From 43fb134887c7ab70e75b048380b3fefc3876ad34 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Thu, 1 Dec 2022 00:42:12 +0100 Subject: [PATCH] fix table name --- _init.php | 20 ++++++++++++++++++++ _install.php | 4 ++-- _uninstall.php | 22 ++++++++++++++++++++++ inc/lib.epc.records.php | 2 +- inc/lib.epc.update.php | 14 +++++++------- 5 files changed, 52 insertions(+), 10 deletions(-) create mode 100644 _init.php diff --git a/_init.php b/_init.php new file mode 100644 index 0000000..808a042 --- /dev/null +++ b/_init.php @@ -0,0 +1,20 @@ +plugins->moduleInfo($mod_id, 'requires')[0][1]; $new_version = dcCore::app()->plugins->moduleInfo($mod_id, 'version'); $old_version = dcCore::app()->getVersion($mod_id); @@ -36,7 +36,7 @@ try { # Database $s = new dbStruct(dcCore::app()->con, dcCore::app()->prefix); - $s->epc + $s->{initEnhancePostContent::EPC_TABLE_NAME} ->epc_id('bigint', 0, false) ->blog_id('varchar', 32, false) ->epc_type('varchar', 32, false, "'epc'") diff --git a/_uninstall.php b/_uninstall.php index 02e39ec..287d161 100644 --- a/_uninstall.php +++ b/_uninstall.php @@ -25,6 +25,17 @@ $this->addUserAction( __('delete all settings') ); +$this->addUserAction( + /* type */ + 'tables', + /* action */ + 'delete', + /* ns */ + initEnhancePostContent::EPC_TABLE_NAME, + /* desc */ + __('delete table') +); + $this->addUserAction( /* type */ 'plugins', @@ -58,6 +69,17 @@ $this->addDirectAction( sprintf(__('delete all %s settings'), 'enhancePostContent') ); +$this->addDirectAction( + /* type */ + 'tables', + /* action */ + 'delete', + /* ns */ + initEnhancePostContent::EPC_TABLE_NAME, + /* desc */ + sprintf(__('delete %s table'), 'enhancePostContent') +); + $this->addDirectAction( /* type */ 'plugins', diff --git a/inc/lib.epc.records.php b/inc/lib.epc.records.php index c69e069..249ec48 100644 --- a/inc/lib.epc.records.php +++ b/inc/lib.epc.records.php @@ -19,7 +19,7 @@ class epcRecords public function __construct() { $this->con = dcCore::app()->con; - $this->table = dcCore::app()->prefix . 'epc'; + $this->table = dcCore::app()->prefix . initEnhancePostContent::EPC_TABLE_NAME; $this->blog = dcCore::app()->con->escape(dcCore::app()->blog->id); } diff --git a/inc/lib.epc.update.php b/inc/lib.epc.update.php index 0560071..4ac8601 100644 --- a/inc/lib.epc.update.php +++ b/inc/lib.epc.update.php @@ -16,17 +16,17 @@ if (!isset($old_version)) { # Move old filters lists from settings to database if ($old_version && version_compare('0.6.6', $old_version, '>=')) { - $f = dcCore::app()->con->select('SELECT * FROM ' . dcCore::app()->prefix . "setting 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()) { if (preg_match('#enhancePostContent_(.*?)List#', $f->setting_id, $m)) { $curlist = @unserialize($f->setting_value); if (is_array($curlist)) { foreach ($curlist as $k => $v) { - $cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . 'epc'); - dcCore::app()->con->writeLock(dcCore::app()->prefix . 'epc'); + $cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . initEnhancePostContent::EPC_TABLE_NAME); + dcCore::app()->con->writeLock(dcCore::app()->prefix . initEnhancePostContent::EPC_TABLE_NAME); - $cur->epc_id = dcCore::app()->con->select('SELECT MAX(epc_id) FROM ' . dcCore::app()->prefix . 'epc' . ' ')->f(0) + 1; + $cur->epc_id = dcCore::app()->con->select('SELECT MAX(epc_id) FROM ' . dcCore::app()->prefix . initEnhancePostContent::EPC_TABLE_NAME . ' ')->f(0) + 1; $cur->blog_id = $f->blog_id; $cur->epc_filter = strtolower($m[1]); $cur->epc_key = $k; @@ -36,15 +36,15 @@ if ($old_version && version_compare('0.6.6', $old_version, '>=')) { dcCore::app()->con->unlock(); } } - dcCore::app()->con->execute('DELETE FROM ' . dcCore::app()->prefix . "setting 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 } elseif ($old_version && version_compare('2021.10.05', $old_version, '>=')) { - $rs = dcCore::app()->con->select('SELECT epc_id, epc_filter FROM ' . dcCore::app()->prefix . 'epc'); + $rs = dcCore::app()->con->select('SELECT epc_id, epc_filter FROM ' . dcCore::app()->prefix . initEnhancePostContent::EPC_TABLE_NAME); while ($rs->fetch()) { - $cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . 'epc'); + $cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . initEnhancePostContent::EPC_TABLE_NAME); $cur->epc_filter = strtolower($rs->epc_filter);