improve/inc/Install.php

94 lines
2.2 KiB
PHP
Raw Normal View History

2021-11-05 21:52:46 +00:00
<?php
/**
* @brief improve, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
declare(strict_types=1);
2022-12-21 14:41:27 +00:00
namespace Dotclear\Plugin\improve;
2021-11-05 21:52:46 +00:00
/* dotclear */
use dcCore;
/* php */
use Exception;
2021-11-05 21:52:46 +00:00
/**
* Improve install class
*
* Set default settings and version
* and manage changes on updates.
*/
2022-12-21 14:41:27 +00:00
class Install
{
/** @var array Improve default settings */
private static $default_settings = [[
2021-11-05 21:52:46 +00:00
'disabled',
'List of hidden action modules',
'tab;newline;endoffile',
'string',
]];
2021-11-05 21:52:46 +00:00
2022-12-21 14:41:27 +00:00
// Nothing to change below
private static $init = false;
public static function init(): bool
{
self::$init = defined('DC_CONTEXT_ADMIN') && dcCore::app()->newVersion(Core::id(), dcCore::app()->plugins->moduleInfo(Core::id(), 'version'));
return self::$init;
}
public static function process(): ?bool
{
2022-12-21 14:41:27 +00:00
if (!self::$init) {
return false;
}
2021-11-05 21:52:46 +00:00
2022-12-21 14:41:27 +00:00
try {
self::update_0_8_0();
self::putSettings();
2022-12-21 14:51:43 +00:00
2022-12-21 14:41:27 +00:00
return true;
} catch (Exception $e) {
dcCore::app()->error->add($e->getMessage());
2021-11-05 21:52:46 +00:00
2022-12-21 14:41:27 +00:00
return false;
}
2021-11-05 21:52:46 +00:00
}
private static function putSettings(): void
{
foreach (self::$default_settings as $v) {
2022-12-21 14:41:27 +00:00
dcCore::app()->blog->settings->get(Core::id())->put(
$v[0],
$v[2],
$v[3],
$v[1],
false,
true
);
}
}
/** Update improve < 0.8 : action modules settings name */
private static function update_0_8_0(): void
{
2022-12-21 14:41:27 +00:00
if (version_compare(dcCore::app()->getVersion(Core::id()) ?? '0', '0.8', '<')) {
foreach (dcCore::app()->blog->settings->get(Core::id())->dumpGlobalSettings() as $id => $values) {
$newId = str_replace('ImproveAction', '', $id);
if ($id != $newId) {
2022-12-21 14:41:27 +00:00
dcCore::app()->blog->settings->get(Core::id())->rename($id, strtolower($newId));
}
}
}
}
}