From d8eaa8c368ea60848b5b4ade8f9fa40d5f00c33c Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Sat, 3 Dec 2022 16:30:57 +0100 Subject: [PATCH] fix tables names --- _init.php | 20 ++++++++++++++++++++ _install.php | 24 +++++++++++++----------- _public.php | 4 ++-- inc/class.periodical.php | 17 ++++++++--------- 4 files changed, 43 insertions(+), 22 deletions(-) create mode 100644 _init.php diff --git a/_init.php b/_init.php new file mode 100644 index 0000000..ed86aff --- /dev/null +++ b/_init.php @@ -0,0 +1,20 @@ +plugins->moduleInfo('periodical', 'version'); -$old_version = dcCore::app()->getVersion('periodical'); - -if (version_compare($old_version, $new_version, '>=')) { - return null; -} - try { + # Grab info + $mod_id = basename(__DIR__); + $dc_min = dcCore::app()->plugins->moduleInfo($mod_id, 'requires')[0][1]; + $new_version = dcCore::app()->plugins->moduleInfo($mod_id, 'version'); + + # Check installed version + if (version_compare(dcCore::app()->getVersion($mod_id), $new_version, '>=')) { + return null; + } + # Check Dotclear version if (!method_exists('dcUtils', 'versionsCompare') || dcUtils::versionsCompare(DC_VERSION, $dc_min, '<', false) ) { throw new Exception(sprintf( '%s requires Dotclear %s', - 'periodical', + $mod_id, $dc_min )); } @@ -38,7 +40,7 @@ try { $t = new dbStruct(dcCore::app()->con, dcCore::app()->prefix); # Table principale des sondages - $t->periodical + $t->{initPeriodical::PERIOD_TABLE_NAME} ->periodical_id('bigint', 0, false) ->blog_id('varchar', 32, false) ->periodical_type('varchar', 32, false, "'post'") @@ -64,7 +66,7 @@ try { $s->put('periodical_pub_order', 'post_dt asc', 'string', 'Order of publication', false, true); # Version - dcCore::app()->setVersion('periodical', $new_version); + dcCore::app()->setVersion($mod_id, $new_version); return true; } catch (Exception $e) { diff --git a/_public.php b/_public.php index 2db10e2..b583172 100644 --- a/_public.php +++ b/_public.php @@ -58,7 +58,7 @@ class publicPeriodical if (!preg_match('/^(post_dt|post_creadt|post_id) (asc|desc)$/', $posts_order)) { $posts_order = 'post_dt asc'; } - $cur_period = dcCore::app()->con->openCursor(dcCore::app()->prefix . 'periodical'); + $cur_period = dcCore::app()->con->openCursor(dcCore::app()->prefix . initPeriodical::PERIOD_TABLE_NAME); while ($periods->fetch()) { # Check if period is ongoing @@ -100,7 +100,7 @@ class publicPeriodical $posts = dcCore::app()->auth->sudo([$per, 'getPosts'], $posts_params); if (!$posts->isEmpty()) { - $cur_post = dcCore::app()->con->openCursor(dcCore::app()->prefix . 'post'); + $cur_post = dcCore::app()->con->openCursor(dcCore::app()->prefix . dcBlog::POST_TABLE_NAME); while ($posts->fetch()) { # Publish post with right date diff --git a/inc/class.periodical.php b/inc/class.periodical.php index 2474078..8d54dbf 100644 --- a/inc/class.periodical.php +++ b/inc/class.periodical.php @@ -24,9 +24,8 @@ class periodical public function __construct() { - $this->con = dcCore::app()->con; - - $this->table = dcCore::app()->con->escape(dcCore::app()->prefix . 'periodical'); + $this->con = dcCore::app()->con; + $this->table = dcCore::app()->con->escape(dcCore::app()->prefix . initPeriodical::PERIOD_TABLE_NAME); $this->blog = dcCore::app()->con->escape(dcCore::app()->blog->id); } @@ -180,7 +179,7 @@ class periodical } $this->con->execute( - 'DELETE FROM ' . dcCore::app()->prefix . 'meta ' . + 'DELETE FROM ' . dcCore::app()->prefix . dcMeta::META_TABLE_NAME . ' ' . "WHERE meta_type = 'periodical' " . 'AND post_id ' . $this->con->in($ids) ); @@ -211,7 +210,7 @@ class periodical $params['columns'][] = 'T.periodical_pub_int'; $params['columns'][] = 'T.periodical_pub_nb'; - $params['join'] .= 'LEFT JOIN ' . dcCore::app()->prefix . 'meta R ON P.post_id = R.post_id '; + $params['join'] .= 'LEFT JOIN ' . dcCore::app()->prefix . dcMeta::META_TABLE_NAME . ' R ON P.post_id = R.post_id '; $params['join'] .= 'LEFT JOIN ' . $this->table . ' T ON CAST(T.periodical_id as char) = CAST(R.meta_id as char) '; $params['sql'] .= "AND R.meta_type = 'periodical' "; @@ -255,8 +254,8 @@ class periodical return; } - $cur = $this->con->openCursor(dcCore::app()->prefix . 'meta'); - $this->con->writeLock(dcCore::app()->prefix . 'meta'); + $cur = $this->con->openCursor(dcCore::app()->prefix . dcMeta::META_TABLE_NAME); + $this->con->writeLock(dcCore::app()->prefix . dcMeta::META_TABLE_NAME); try { $cur->post_id = $post_id; @@ -277,7 +276,7 @@ class periodical $post_id = (int) $post_id; $this->con->execute( - 'DELETE FROM ' . dcCore::app()->prefix . 'meta ' . + 'DELETE FROM ' . dcCore::app()->prefix . dcMeta::META_TABLE_NAME . ' ' . "WHERE meta_type = 'periodical' " . "AND post_id = '" . $post_id . "' " ); @@ -310,7 +309,7 @@ class periodical } $this->con->execute( - 'DELETE FROM ' . dcCore::app()->prefix . 'meta ' . + 'DELETE FROM ' . dcCore::app()->prefix . dcMeta::META_TABLE_NAME . ' ' . "WHERE meta_type = 'periodical' " . 'AND post_id ' . $this->con->in($ids) );