mirror of
https://github.com/Piwigo/Piwigo.git
synced 2026-03-28 17:42:57 +01:00
fixes #2488 improve handling of derivative config
Refactors how derivative and disabled_derivatives config values are loaded from the database, supporting both parameters and using a new safe_unserialize function. Updates ImageStdParams to use the global config and ensures proper serialization/deserialization of disabled type maps, with improved save logic to avoid unnecessary writes.
This commit is contained in:
21
i.php
21
i.php
@@ -365,6 +365,15 @@ function send_derivative($expires)
|
||||
fclose($fp);
|
||||
}
|
||||
|
||||
function safe_unserialize($value)
|
||||
{
|
||||
if (is_string($value))
|
||||
{
|
||||
return unserialize($value);
|
||||
}
|
||||
return $value;
|
||||
}
|
||||
|
||||
$page=array();
|
||||
$begin = $step = microtime(true);
|
||||
$timing=array();
|
||||
@@ -388,7 +397,17 @@ catch (Exception $e)
|
||||
}
|
||||
pwg_db_check_charset();
|
||||
|
||||
list($conf['derivatives']) = pwg_db_fetch_row(pwg_query('SELECT value FROM '.$prefixeTable.'config WHERE param=\'derivatives\''));
|
||||
$query = '
|
||||
SELECT param, value
|
||||
FROM '.$prefixeTable.'config
|
||||
WHERE param IN (\'derivatives\', \'disabled_derivatives\')
|
||||
;';
|
||||
|
||||
$result = pwg_query($query);
|
||||
while ($row = pwg_db_fetch_assoc($result))
|
||||
{
|
||||
$conf[ $row['param'] ] = $row['value'];
|
||||
}
|
||||
ImageStdParams::load_from_db();
|
||||
|
||||
|
||||
|
||||
@@ -103,11 +103,13 @@ final class ImageStdParams
|
||||
*/
|
||||
static function get_disabled_type_map()
|
||||
{
|
||||
global $conf;
|
||||
|
||||
if (count(self::$disabled_type_map))
|
||||
{
|
||||
return self::$disabled_type_map;
|
||||
}
|
||||
return conf_get_param('disabled_derivatives', array());
|
||||
return $conf['disabled_derivatives'] ?? array();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -178,9 +180,16 @@ final class ImageStdParams
|
||||
{
|
||||
self::$watermark = new WatermarkParams();
|
||||
self::$type_map = self::get_enabled_default_sizes();
|
||||
self::$disabled_type_map = self::get_disabled_default_sizes();
|
||||
self::save();
|
||||
self::save(false);
|
||||
}
|
||||
|
||||
self::$disabled_type_map = safe_unserialize(self::get_disabled_type_map());
|
||||
if (empty(self::$disabled_type_map))
|
||||
{
|
||||
self::$disabled_type_map = self::get_disabled_default_sizes();
|
||||
self::save_disabled();
|
||||
}
|
||||
|
||||
self::build_maps();
|
||||
}
|
||||
|
||||
@@ -200,14 +209,14 @@ final class ImageStdParams
|
||||
static function set_and_save($map)
|
||||
{
|
||||
self::$type_map = $map;
|
||||
self::save();
|
||||
self::save(false);
|
||||
self::build_maps();
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the configuration in database.
|
||||
*/
|
||||
static function save()
|
||||
static function save($save_disabled = true)
|
||||
{
|
||||
$ser = serialize( array(
|
||||
'd' => self::$type_map,
|
||||
@@ -217,8 +226,11 @@ final class ImageStdParams
|
||||
) );
|
||||
conf_update_param('derivatives', addslashes($ser) );
|
||||
|
||||
if ($save_disabled)
|
||||
{
|
||||
self::save_disabled();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Saves the disabled configuration in database.
|
||||
|
||||
Reference in New Issue
Block a user