add upgrade process
This commit is contained in:
parent
4c04ec2ca1
commit
eb356a5e6e
2 changed files with 107 additions and 32 deletions
|
@ -33,6 +33,7 @@ Clearbricks::lib()->autoload([
|
||||||
'enhancePostContent' => $d . 'class.enhancepostcontent.php',
|
'enhancePostContent' => $d . 'class.enhancepostcontent.php',
|
||||||
'epcFilter' => $d . 'class.epcfilter.php',
|
'epcFilter' => $d . 'class.epcfilter.php',
|
||||||
'epcRecords' => $d . 'class.epcrecords.php',
|
'epcRecords' => $d . 'class.epcrecords.php',
|
||||||
|
'epcUpgrade' => $d . 'class.epcupgrade.php',
|
||||||
'adminEpcList' => $d . 'class.adminepclist.php',
|
'adminEpcList' => $d . 'class.adminepclist.php',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
|
|
|
@ -10,12 +10,83 @@
|
||||||
* @copyright Jean-Christian Denis
|
* @copyright Jean-Christian Denis
|
||||||
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
|
||||||
*/
|
*/
|
||||||
if (!isset($old_version)) {
|
if (!defined('DC_CONTEXT_ADMIN')) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
# Move old filters lists from settings to database
|
class epcUpgrade
|
||||||
if ($old_version && version_compare('0.6.6', $old_version, '>=')) {
|
{
|
||||||
|
public static function preUpgrade()
|
||||||
|
{
|
||||||
|
$current = dcCore::app()->getVersion(basename(dirname('../' . __DIR__)));
|
||||||
|
if ($current && version_compare($current, '2022.12.10', '<')) {
|
||||||
|
self::preUpgrade20221210();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function postUpgrade()
|
||||||
|
{
|
||||||
|
$current = dcCore::app()->getVersion(basename(dirname('../' . __DIR__)));
|
||||||
|
if ($current && version_compare($current, '0.6.6', '<')) {
|
||||||
|
self::postUpgrade00060607();
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($current && version_compare($current, '2021.10.06', '<')) {
|
||||||
|
self::postUpgrade20211006();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function preUpgrade20221210()
|
||||||
|
{
|
||||||
|
// Rename settings
|
||||||
|
$setting_ids = [
|
||||||
|
'enhancePostContent_active' => 'active',
|
||||||
|
'enhancePostContent_list_sortby' => 'list_sortby',
|
||||||
|
'enhancePostContent_list_order' => 'list_order',
|
||||||
|
'enhancePostContent_list_nb' => 'list_nb',
|
||||||
|
'enhancePostContent_allowedtplvalues' => 'allowedtplvalues',
|
||||||
|
'enhancePostContent_allowedpubpages' => 'allowedpubpages',
|
||||||
|
];
|
||||||
|
|
||||||
|
foreach ($setting_ids as $old => $new) {
|
||||||
|
$cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME);
|
||||||
|
$cur->setting_id = $new;
|
||||||
|
$cur->setting_ns = basename(dirname('../' . __DIR__));
|
||||||
|
$cur->update("WHERE setting_id = '" . $old . "' and setting_ns = 'enhancePostContent' ");
|
||||||
|
}
|
||||||
|
|
||||||
|
// use json rather than serialise for settings array
|
||||||
|
$setting_values = [
|
||||||
|
'allowedtplvalues' => json_encode(enhancePostContent::defaultAllowedTplValues()),
|
||||||
|
'allowedpubpages' =>json_encode(enhancePostContent::defaultAllowedPubPages()),
|
||||||
|
];
|
||||||
|
|
||||||
|
$record = dcCore::app()->con->select(
|
||||||
|
'SELECT * FROM ' . dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME . ' ' .
|
||||||
|
"WHERE setting_ns = '" . dcCore::app()->con->escape(basename(dirname('../' . __DIR__))) . "' "
|
||||||
|
);
|
||||||
|
|
||||||
|
while ($record->fetch()) {
|
||||||
|
foreach ($setting_values as $key => $default) {
|
||||||
|
try {
|
||||||
|
$value = @unserialize($record->__get($key));
|
||||||
|
} catch(Exception) {
|
||||||
|
$value = $default;
|
||||||
|
}
|
||||||
|
|
||||||
|
$cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME);
|
||||||
|
$cur->setting_value = json_encode(!is_array($value) ? $default : $value);
|
||||||
|
$cur->update(
|
||||||
|
"WHERE setting_id = '" . $key . "' and setting_ns = '" . dcCore::app()->con->escape($record->setting_ns) . "' " .
|
||||||
|
'AND blog_id ' . (null === $record->blog_id ? 'IS NULL ' : ("= '" . dcCore::app()->con->escape($record->blog_id) . "' "))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static function postUpgrade00060607()
|
||||||
|
{
|
||||||
|
# Move old filters lists from settings to database
|
||||||
$f = dcCore::app()->con->select('SELECT * FROM ' . dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME . " WHERE setting_ns='enhancePostContent' AND blog_id IS NOT NULL ");
|
$f = dcCore::app()->con->select('SELECT * FROM ' . dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME . " WHERE setting_ns='enhancePostContent' AND blog_id IS NOT NULL ");
|
||||||
|
|
||||||
while ($f->fetch()) {
|
while ($f->fetch()) {
|
||||||
|
@ -39,9 +110,11 @@ if ($old_version && version_compare('0.6.6', $old_version, '>=')) {
|
||||||
dcCore::app()->con->execute('DELETE FROM ' . dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME . " WHERE setting_id='" . $f->setting_id . "' AND setting_ns='enhancePostContent' AND blog_id='" . $f->blog_id . "' ");
|
dcCore::app()->con->execute('DELETE FROM ' . dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME . " WHERE setting_id='" . $f->setting_id . "' AND setting_ns='enhancePostContent' AND blog_id='" . $f->blog_id . "' ");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
# Move old filter name to filter id
|
private static function postUpgrade20211006()
|
||||||
} elseif ($old_version && version_compare('2021.10.05', $old_version, '>=')) {
|
{
|
||||||
|
# Move old filter name to filter id
|
||||||
$rs = dcCore::app()->con->select('SELECT epc_id, epc_filter FROM ' . dcCore::app()->prefix . initEnhancePostContent::TABLE_NAME);
|
$rs = dcCore::app()->con->select('SELECT epc_id, epc_filter FROM ' . dcCore::app()->prefix . initEnhancePostContent::TABLE_NAME);
|
||||||
while ($rs->fetch()) {
|
while ($rs->fetch()) {
|
||||||
$cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . initEnhancePostContent::TABLE_NAME);
|
$cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . initEnhancePostContent::TABLE_NAME);
|
||||||
|
@ -51,4 +124,5 @@ if ($old_version && version_compare('0.6.6', $old_version, '>=')) {
|
||||||
$cur->update('WHERE epc_id = ' . $rs->epc_id . ' ');
|
$cur->update('WHERE epc_id = ' . $rs->epc_id . ' ');
|
||||||
dcCore::app()->blog->triggerBlog();
|
dcCore::app()->blog->triggerBlog();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue