use short settings id

This commit is contained in:
Jean-Christian Denis 2022-12-23 00:15:43 +01:00
parent 11a6dd5189
commit 837d83d6c4
Signed by: JcDenis
GPG key ID: 1B5B8C5B90B6C951
2 changed files with 37 additions and 4 deletions

View file

@ -22,7 +22,9 @@ try {
return null; return null;
} }
$translater = new dcTranslater(false); $translater = new dcTranslater(false);
$translater->writeSettings(false); if (!$translater->growUp()) {
$translater->writeSettings(false);
}
return true; return true;
} catch (Exception $e) { } catch (Exception $e) {

View file

@ -122,7 +122,7 @@ class dcTranslater extends dcTranslaterDefaultSettings
public function loadSettings(): void public function loadSettings(): void
{ {
foreach ($this->getDefaultSettings() as $key => $value) { foreach ($this->getDefaultSettings() as $key => $value) {
$this->$key = dcCore::app()->blog->settings->translater->get('translater_' . $key); $this->$key = dcCore::app()->blog->settings->get('translater')->get($key);
try { try {
settype($this->$key, gettype($value)); settype($this->$key, gettype($value));
@ -139,10 +139,41 @@ class dcTranslater extends dcTranslaterDefaultSettings
public function writeSettings($overwrite = true): void public function writeSettings($overwrite = true): void
{ {
foreach ($this->getDefaultSettings() as $key => $value) { foreach ($this->getDefaultSettings() as $key => $value) {
dcCore::app()->blog->settings->translater->drop('translater_' . $key); dcCore::app()->blog->settings->get('translater')->drop($key);
dcCore::app()->blog->settings->translater->put('translater_' . $key, $this->$key, gettype($value), '', true, true); dcCore::app()->blog->settings->get('translater')->put($key, $this->$key, gettype($value), '', true, true);
} }
} }
/**
* Upgrade plugin
*
* @return bool Upgrade done
*/
public function growUp()
{
$current = dcCore::app()->getVersion(basename(dirname(__DIR__)));
// use short settings id
if ($current && version_compare($current, '2022.12.22', '<')) {
$record = dcCore::app()->con->select(
'SELECT * FROM ' . dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME . ' ' .
"WHERE setting_ns = 'translater' "
);
while ($record->fetch()) {
if (preg_match('/^translater_(.*?)$/', $record->setting_id, $match)) {
$cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME);
$cur->setting_id = $this->$key = $match[1];
$cur->update(
"WHERE setting_id = '" . $record->setting_id . "' and setting_ns = 'translater' " .
'AND blog_id ' . (null === $record->blog_id ? 'IS NULL ' : ("= '" . dcCore::app()->con->escape($record->blog_id) . "' "))
);
}
}
return true;
}
return false;
}
//@} //@}
/// @name modules methods /// @name modules methods