From 2217d70dd8ff400519e444d6b9860cb0c76d6ab5 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Sat, 3 Dec 2022 16:57:39 +0100 Subject: [PATCH] fix tables names --- _init.php | 20 ++++++++++++++++++++ _install.php | 23 ++++++++++++----------- inc/class.postwidgettext.php | 2 +- inc/lib.pwt.admin.php | 10 +++++----- inc/patch.0.5.php | 8 ++++---- 5 files changed, 42 insertions(+), 21 deletions(-) create mode 100644 _init.php diff --git a/_init.php b/_init.php new file mode 100644 index 0000000..719156f --- /dev/null +++ b/_init.php @@ -0,0 +1,20 @@ +plugins->moduleInfo('postWidgetText', 'version'); -$old_version = dcCore::app()->getVersion('postWidgetText'); - -if (version_compare($old_version, $new_version, '>=')) { - return; -} - try { + # Grab info + $mod_id = basename(__DIR__); + + # check installed version + if (version_compare(dcCore::app()->getVersion($mod_id), $new_version, '>=')) { + return; + } + # Table is the same for plugins # pollsFactory, postTask, postWidgetText $s = new dbStruct(dcCore::app()->con, dcCore::app()->prefix); - $s->post_option + $s->{initPostWidgetText::PWT_TABLE_NAME} ->option_id('bigint', 0, false) ->post_id('bigint', 0, false) ->option_creadt('timestamp', 0, false, 'now()') @@ -64,14 +65,14 @@ try { ); # Transfert records from old table to the new one - if (dcCore::app()->getVersion('postWidgetText') !== null - && version_compare(dcCore::app()->getVersion('postWidgetText'), '0.5', '<') + if (dcCore::app()->getVersion($mod_id) !== null + && version_compare(dcCore::app()->getVersion($mod_id), '0.5', '<') ) { require_once __DIR__ . '/inc/patch.0.5.php'; } # Set module version - dcCore::app()->setVersion('postWidgetText', $new_version); + dcCore::app()->setVersion($mod_id, $new_version); return true; } catch (Exception $e) { diff --git a/inc/class.postwidgettext.php b/inc/class.postwidgettext.php index b6f3d7e..0abacb6 100644 --- a/inc/class.postwidgettext.php +++ b/inc/class.postwidgettext.php @@ -28,7 +28,7 @@ class postWidgetText public function __construct() { $this->con = dcCore::app()->con; - $this->table = dcCore::app()->prefix . 'post_option'; + $this->table = dcCore::app()->prefix . initPostWidgetText::PWT_TABLE_NAME; $this->blog = dcCore::app()->con->escape(dcCore::app()->blog->id); } diff --git a/inc/lib.pwt.admin.php b/inc/lib.pwt.admin.php index 5fc7331..cad41ff 100644 --- a/inc/lib.pwt.admin.php +++ b/inc/lib.pwt.admin.php @@ -186,8 +186,8 @@ class adminPostWidgetText 'postwidgettext', 'SELECT option_type, option_content, ' . 'option_content_xhtml, W.post_id ' . - 'FROM ' . dcCore::app()->prefix . 'post_option W ' . - 'LEFT JOIN ' . dcCore::app()->prefix . 'post P ' . + 'FROM ' . dcCore::app()->prefix . initPostWidgetText::PWT_TABLE_NAME . ' W ' . + 'LEFT JOIN ' . dcCore::app()->prefix . dcBlog::POST_TABLE_NAME . ' P ' . 'ON P.post_id = W.post_id ' . "WHERE P.blog_id = '" . $blog_id . "' " . "AND W.option_type = 'postwidgettext' " @@ -200,8 +200,8 @@ class adminPostWidgetText 'postwidgettext', 'SELECT option_type, option_content, ' . 'option_content_xhtml, W.post_id ' . - 'FROM ' . dcCore::app()->prefix . 'post_option W ' . - 'LEFT JOIN ' . dcCore::app()->prefix . 'post P ' . + 'FROM ' . dcCore::app()->prefix . initPostWidgetText::PWT_TABLE_NAME . ' W ' . + 'LEFT JOIN ' . dcCore::app()->prefix . dcBlog::POST_TABLE_NAME . ' P ' . 'ON P.post_id = W.post_id ' . "WHERE W.option_type = 'postwidgettext' " ); @@ -210,7 +210,7 @@ class adminPostWidgetText public static function importInit($bk, dcCore $core) { $bk->cur_postwidgettext = dcCore::app()->con->openCursor( - dcCore::app()->prefix . 'post_option' + dcCore::app()->prefix . initPostWidgetText::PWT_TABLE_NAME ); $bk->postwidgettext = new postWidgetText(); } diff --git a/inc/patch.0.5.php b/inc/patch.0.5.php index e8954ac..d50e219 100644 --- a/inc/patch.0.5.php +++ b/inc/patch.0.5.php @@ -12,16 +12,16 @@ */ $records = dcCore::app()->con->select( 'SELECT W.*, P.post_lang, P.post_format FROM ' . dcCore::app()->prefix . 'post_wtext W ' . - 'LEFT JOIN ' . dcCore::app()->prefix . 'post P ON P.post_id=W.post_id ' + 'LEFT JOIN ' . dcCore::app()->prefix . dcBlog::POST_TABLE_NAME . ' P ON P.post_id=W.post_id ' ); if (!$records->isEmpty()) { - $cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . 'post_option'); + $cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . initPostWidgetText::PWT_TABLE_NAME); while ($records->fetch()) { - dcCore::app()->con->writeLock(dcCore::app()->prefix . 'post_option'); + dcCore::app()->con->writeLock(dcCore::app()->prefix . initPostWidgetText::PWT_TABLE_NAME); try { $id = dcCore::app()->con->select( - 'SELECT MAX(option_id) FROM ' . dcCore::app()->prefix . 'post_option' + 'SELECT MAX(option_id) FROM ' . dcCore::app()->prefix . initPostWidgetText::PWT_TABLE_NAME )->f(0) + 1; $cur->clean();