diff --git a/_install.php b/_install.php new file mode 100644 index 0000000..8ac3be3 --- /dev/null +++ b/_install.php @@ -0,0 +1,20 @@ +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) . "' ")) + ); + } + } + } + } +} diff --git a/inc/Prepend.php b/inc/Prepend.php index 399beda..38683a6 100644 --- a/inc/Prepend.php +++ b/inc/Prepend.php @@ -26,6 +26,7 @@ class Prepend 'Core', 'UnmoderatedWhiteList', 'ReservedWhiteList', + 'Install', 'Prepend', ]; protected static $init = false;