fix tables names

master
Jean-Christian Paul Denis 2022-12-03 16:30:57 +01:00
parent 13bf194e61
commit d8eaa8c368
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
4 changed files with 43 additions and 22 deletions

20
_init.php 100644
View File

@ -0,0 +1,20 @@
<?php
/**
* @brief periodical, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis and Contributors
*
* @copyright Jean-Christian Denis
* @copyright GPL-2.0 https://www.gnu.org/licenses/gpl-2.0.html
*/
if (!defined('DC_RC_PATH')) {
return null;
}
class initPeriodical
{
public const PERIOD_TABLE_NAME = 'periodical';
}

View File

@ -14,22 +14,24 @@ if (!defined('DC_CONTEXT_ADMIN')) {
return null;
}
$dc_min = '2.24';
$new_version = dcCore::app()->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) {

View File

@ -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

View File

@ -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)
);