[core] config->save() is implicit in set_XXX(), no need to call it from outside of there

This commit is contained in:
Shish 2024-06-19 14:34:22 +01:00 committed by Shish
parent e3e25c1228
commit 63c6f9d2ac
3 changed files with 26 additions and 34 deletions

View file

@ -11,13 +11,6 @@ namespace Shimmie2;
*/
interface Config
{
/**
* Save the list of name:value pairs to wherever they came from,
* so that the next time a page is loaded it will use the new
* configuration.
*/
public function save(string $name = null): void;
//@{ /*--------------------------------- SET ------------------------------------------------------*/
/**
* Set a configuration option to a new value, regardless of what the value is at the moment.
@ -144,6 +137,13 @@ abstract class BaseConfig implements Config
/** @var array<string, mixed> */
public array $values = [];
/**
* Save the list of name:value pairs to wherever they came from,
* so that the next time a page is loaded it will use the new
* configuration.
*/
abstract protected function save(string $name): void;
public function set_int(string $name, ?int $value): void
{
$this->values[$name] = is_null($value) ? null : $value;
@ -341,16 +341,10 @@ class DatabaseConfig extends BaseConfig
return $values;
}
public function save(string $name = null): void
protected function save(string $name): void
{
global $cache;
if (is_null($name)) {
reset($this->values); // rewind the array to the first element
foreach ($this->values as $name => $value) {
$this->save($name);
}
} else {
$query = "DELETE FROM {$this->table_name} WHERE name = :name";
$args = ["name" => $name];
$cols = ["name","value"];
@ -369,7 +363,7 @@ class DatabaseConfig extends BaseConfig
"INSERT INTO {$this->table_name} (".join(",", $cols).") VALUES (".join(",", $params).")",
$args
);
}
// rather than deleting and having some other request(s) do a thundering
// herd of race-conditioned updates, just save the updated version once here
$cache->set($this->cache_name, $this->values);

View file

@ -73,7 +73,6 @@ class Featured extends Extension
global $config;
if ($event->image->id == $config->get_int("featured_id")) {
$config->set_int("featured_id", 0);
$config->save();
}
}

View file

@ -406,7 +406,6 @@ class Setup extends Extension
}
}
}
$config->save();
log_warning("setup", "Configuration updated");
}