mirror of
https://github.com/friendica/friendica
synced 2025-05-25 23:04:14 +02:00
Revert node.config.php into Config table
This commit is contained in:
parent
6db89adc04
commit
513ef03421
27 changed files with 425 additions and 829 deletions
91
src/Core/Config/Model/DatabaseConfig.php
Normal file
91
src/Core/Config/Model/DatabaseConfig.php
Normal file
|
@ -0,0 +1,91 @@
|
|||
<?php
|
||||
|
||||
namespace Friendica\Core\Config\Model;
|
||||
|
||||
use Friendica\Core\Config\Capability\IManageConfigValues;
|
||||
use Friendica\Core\Config\Capability\ISetConfigValuesTransactionally;
|
||||
use Friendica\Core\Config\Util\SerializeUtil;
|
||||
use Friendica\Core\Config\ValueObject\Cache;
|
||||
use Friendica\Database\Database;
|
||||
|
||||
/**
|
||||
* Complete system configuration model, bound with the database
|
||||
*/
|
||||
class DatabaseConfig implements IManageConfigValues
|
||||
{
|
||||
/** @var Database */
|
||||
protected $database;
|
||||
/** @var Cache */
|
||||
protected $cache;
|
||||
|
||||
public function __construct(Database $database, Cache $cache)
|
||||
{
|
||||
$this->database = $database;
|
||||
$this->cache = $cache;
|
||||
|
||||
$this->reload();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public function reload()
|
||||
{
|
||||
$config = $this->database->selectToArray('config');
|
||||
|
||||
foreach ($config as $entry) {
|
||||
$this->cache->set($entry['cat'], $entry['k'], SerializeUtil::maybeUnserialize($entry['v']), Cache::SOURCE_DATA);
|
||||
}
|
||||
}
|
||||
|
||||
public function setAndSave(Cache $setCache, Cache $delCache): bool
|
||||
{
|
||||
$this->database->transaction();
|
||||
|
||||
foreach ($setCache->getAll() as $category => $data) {
|
||||
foreach ($data as $key => $value) {
|
||||
$this->cache->set($category, $key, $value, Cache::SOURCE_DATA);
|
||||
$this->database->insert('config', ['cat' => $category, 'k' => $key, 'v' => serialize($value)], Database::INSERT_UPDATE);
|
||||
}
|
||||
}
|
||||
|
||||
foreach ($delCache->getAll() as $category => $keys) {
|
||||
foreach ($keys as $key => $value) {
|
||||
$this->cache->delete($category, $key);
|
||||
$this->database->delete('config', ['cat' => $category, 'k' => $key]);
|
||||
}
|
||||
}
|
||||
|
||||
return $this->database->commit();
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public function get(string $cat, string $key = null, $default_value = null)
|
||||
{
|
||||
return $this->cache->get($cat, $key) ?? $default_value;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public function set(string $cat, string $key, $value): bool
|
||||
{
|
||||
$this->cache->set($cat, $key, $value, Cache::SOURCE_DATA);
|
||||
return $this->database->insert('config', ['cat' => $cat, 'k' => $key, 'v' => serialize($value)], Database::INSERT_UPDATE);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public function beginTransaction(): ISetConfigValuesTransactionally
|
||||
{
|
||||
return new ConfigTransaction($this);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public function delete(string $cat, string $key): bool
|
||||
{
|
||||
$this->cache->delete($cat, $key);
|
||||
return $this->database->delete('config', ['cat' => $cat, 'k' => $key]);
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public function getCache(): Cache
|
||||
{
|
||||
return $this->cache;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue