add install process to update settings
This commit is contained in:
parent
78ac10c266
commit
d6424f9442
3 changed files with 131 additions and 0 deletions
20
_install.php
Normal file
20
_install.php
Normal file
|
@ -0,0 +1,20 @@
|
|||
<?php
|
||||
/**
|
||||
* @brief whiteListCom, a plugin for Dotclear 2
|
||||
*
|
||||
* @package Dotclear
|
||||
* @subpackage Plugin
|
||||
*
|
||||
* @author Jean-Christian Denis
|
||||
*
|
||||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
$install = implode('\\', ['Dotclear', 'Plugin', basename(__DIR__), 'Install']);
|
||||
if ($install::init()) {
|
||||
return $install::process();
|
||||
}
|
||||
|
||||
return null;
|
110
inc/Install.php
Normal file
110
inc/Install.php
Normal file
|
@ -0,0 +1,110 @@
|
|||
<?php
|
||||
/**
|
||||
* @brief pacKman, a plugin for Dotclear 2
|
||||
*
|
||||
* @package Dotclear
|
||||
* @subpackage Plugin
|
||||
*
|
||||
* @author Jean-Christian Denis
|
||||
*
|
||||
* @copyright Jean-Christian Denis
|
||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||
*/
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Dotclear\Plugin\whiteListCom;
|
||||
|
||||
/* dotclear ns */
|
||||
use dcCore;
|
||||
use dcNamespace;
|
||||
|
||||
/* php ns */
|
||||
use Exception;
|
||||
|
||||
class Install
|
||||
{
|
||||
// Module specs
|
||||
private static $mod_conf = [
|
||||
[
|
||||
'unmoderated',
|
||||
'[]',
|
||||
'string',
|
||||
'Whitelist of unmoderated users on comments',
|
||||
],
|
||||
[
|
||||
'reserved',
|
||||
'[]',
|
||||
'string',
|
||||
'Whitelist of reserved names on comments',
|
||||
],
|
||||
];
|
||||
|
||||
// Nothing to change below
|
||||
private static $pid = '';
|
||||
protected static $init = false;
|
||||
|
||||
public static function init(): bool
|
||||
{
|
||||
self::$pid = basename(dirname(__DIR__));
|
||||
self::$init = defined('DC_CONTEXT_ADMIN') && dcCore::app()->newVersion(self::$pid, dcCore::app()->plugins->moduleInfo(self::$pid, 'version'));
|
||||
|
||||
return self::$init;
|
||||
}
|
||||
|
||||
public static function process(): ?bool
|
||||
{
|
||||
if (!self::$init) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
// Upgrade
|
||||
self::growUp();
|
||||
|
||||
// Set module settings
|
||||
foreach (self::$mod_conf as $v) {
|
||||
dcCore::app()->blog->settings->__get(self::$pid)->put(
|
||||
$v[0],
|
||||
$v[1],
|
||||
$v[2],
|
||||
$v[3],
|
||||
false,
|
||||
true
|
||||
);
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (Exception $e) {
|
||||
dcCore::app()->error->add($e->getMessage());
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public static function growUp(): void
|
||||
{
|
||||
$current = dcCore::app()->getVersion(self::$pid);
|
||||
|
||||
// Update settings id, ns
|
||||
if ($current && version_compare($current, '1.0', '<')) {
|
||||
$record = dcCore::app()->con->select(
|
||||
'SELECT * FROM ' . dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME . ' ' .
|
||||
"WHERE setting_ns = 'whiteListCom' "
|
||||
);
|
||||
|
||||
while ($record->fetch()) {
|
||||
if (preg_match('/^whiteListCom(.*?)$/', $record->setting_id, $match)) {
|
||||
$value = @unserialize(@base64_decode($x));
|
||||
$cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME);
|
||||
$cur->setting_id = $match[1];
|
||||
$cur->setting_ns = self::$pid;
|
||||
$cur->setting_value = is_array($value) ? json_encode($value) : '[]';
|
||||
$cur->update(
|
||||
"WHERE setting_id = '" . $record->setting_id . "' and setting_ns = 'whiteListCom' " .
|
||||
'AND blog_id ' . (null === $record->blog_id ? 'IS NULL ' : ("= '" . dcCore::app()->con->escape($record->blog_id) . "' "))
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -26,6 +26,7 @@ class Prepend
|
|||
'Core',
|
||||
'UnmoderatedWhiteList',
|
||||
'ReservedWhiteList',
|
||||
'Install',
|
||||
'Prepend',
|
||||
];
|
||||
protected static $init = false;
|
||||
|
|
Loading…
Reference in a new issue