fix install and behaviors

This commit is contained in:
Jean-Christian Paul Denis 2021-09-25 17:24:38 +02:00
parent c8b0cba5ec
commit 3a18325a62
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
3 changed files with 21 additions and 28 deletions

View File

@ -44,7 +44,7 @@ class translaterAdminBehaviors
private static function translater($core)
{
if (!(self::$translater instanceof dcTranslater)) {
self::$translater = new dcTranslater($core);
self::$translater = new dcTranslater($core, false);
}
return self::$translater;
}
@ -69,7 +69,7 @@ class translaterAdminBehaviors
return
' <input type="submit" name="translater[' .
html::escapeHTML($id) .
']" value="' . _('Translate') . '" /> ';
']" value="' . __('Translate') . '" /> ';
}
/**

View File

@ -14,19 +14,17 @@
if (!defined('DC_CONTEXT_ADMIN')) {
return null;
}
$id = 'translater';
try {
if (version_compare($core->getVersion($id), $this->moduleInfo($id, 'version'), '>=')) {
if (version_compare($core->getVersion($id), $core->plugins->moduleInfo($id, 'version'), '>=')) {
return null;
}
$t = new dcTranslater($core);
$s = $t->getDefaultSettings();
foreach($s as $v) {
$t->setSetting($v[0], $v[1], false);
$translater = new dcTranslater($core, false);
$settings = $translater->getDefaultSettings();
foreach($settings as $key => $setting) {
$translater->setSetting($key, $setting['value'], false);
}
$core->setVersion($id, $this->moduleInfo($id, 'version'));
$core->setVersion($id, $core->plugins->moduleInfo($id, 'version'));
return true;
} catch (Exception $e) {

View File

@ -57,7 +57,7 @@ class dcTranslater
],
'start_page' => [
'id' => 'translater_start_page',
'value' => 'setting',
'value' => '-',
'type' => 'string',
'label' => 'Page to start on'
],
@ -151,15 +151,18 @@ class dcTranslater
/**
* translater instance
*
* @param dcCore $core dcCore instance
* @param dcCore $core dcCore instance
* @param boolean $core Also load modules
*/
public function __construct($core)
public function __construct(dcCore $core, bool $full = true)
{
$this->core = $core;
$core->blog->settings->addNamespace('translater');
$this->loadModules();
// fill with translated string
if ($full) {
$this->loadModules();
}
self::$allowed_backup_folders = [
__('locales folders of each module') => 'module',
__('plugins folder root') => 'plugin',
@ -167,8 +170,6 @@ class dcTranslater
__('cache folder of Dotclear') => 'cache',
__('locales folder of translater') => 'translater'
];
// fill distrib modules list
self::$default_distrib_modules = [
'plugin' => explode(',', DC_DISTRIB_PLUGINS),
'theme' => explode(',', DC_DISTRIB_THEMES)
@ -215,20 +216,14 @@ class dcTranslater
* @param mixed $overwrite Overwrite settings if exists
* @return boolean Success
*/
public function setSetting(string $id, $value, $overwrite = true)
public function setSetting(string $id, $value, $overwrite = true): bool
{
if (!array_key_exists($id, self::$default_settings)) {
return false;
}
$this->core->blog->settings->translater->drop(self::$default_settings[$id]['id']);
$this->core->blog->settings->translater->put(
self::$default_settings[$id]['id'],
$value,
self::$default_settings[$id]['type'],
self::$default_settings[$id]['label'],
$overwrite,
true
);
$s = self::$default_settings[$id];
$this->core->blog->settings->translater->drop($s['id']);
$this->core->blog->settings->translater->put($s['id'], $value, $s['type'], $s['label'], $overwrite, true);
return true;
}