use plugin ID as table name and meta ID

master
Jean-Christian Paul Denis 2023-08-15 13:43:30 +02:00
parent c83e31fbb2
commit 8684011f3e
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
7 changed files with 17 additions and 22 deletions

View File

@ -16,5 +16,6 @@ if (!defined('DC_RC_PATH')) {
class initPeriodical class initPeriodical
{ {
// now use My::id()
public const PERIOD_TABLE_NAME = 'periodical'; public const PERIOD_TABLE_NAME = 'periodical';
} }

View File

@ -60,7 +60,7 @@ class Frontend extends Process
if (!preg_match('/^(post_dt|post_creadt|post_id) (asc|desc)$/', $posts_order)) { if (!preg_match('/^(post_dt|post_creadt|post_id) (asc|desc)$/', $posts_order)) {
$posts_order = 'post_dt asc'; $posts_order = 'post_dt asc';
} }
$cur_period = dcCore::app()->con->openCursor(dcCore::app()->prefix . My::TABLE_NAME); $cur_period = dcCore::app()->con->openCursor(dcCore::app()->prefix . My::id());
while ($periods->fetch()) { while ($periods->fetch()) {
// Check if period is ongoing // Check if period is ongoing

View File

@ -36,7 +36,7 @@ class Install extends Process
$t = new Structure(dcCore::app()->con, dcCore::app()->prefix); $t = new Structure(dcCore::app()->con, dcCore::app()->prefix);
// create database table // create database table
$t->__get(My::TABLE_NAME) $t->__get(My::id())
->field('periodical_id', 'bigint', 0, false) ->field('periodical_id', 'bigint', 0, false)
->field('blog_id', 'varchar', 32, false) ->field('blog_id', 'varchar', 32, false)
->field('periodical_type', 'varchar', 32, false, "'post'") ->field('periodical_type', 'varchar', 32, false, "'post'")

View File

@ -104,8 +104,8 @@ class ManagePeriod extends Process
Utils::updPeriod($vars->period_id, $cur); Utils::updPeriod($vars->period_id, $cur);
self::redirect($vars->redir, $vars->period_id, '#period', __('Period successfully updated.')); self::redirect($vars->redir, $vars->period_id, '#period', __('Period successfully updated.'));
// Create period
} else { } else {
// Create period
$period_id = Utils::addPeriod($cur); $period_id = Utils::addPeriod($cur);
self::redirect($vars->redir, $period_id, '#period', __('Period successfully created.')); self::redirect($vars->redir, $period_id, '#period', __('Period successfully created.'));

View File

@ -22,12 +22,6 @@ use Dotclear\Module\MyPlugin;
*/ */
class My extends MyPlugin class My extends MyPlugin
{ {
/** @var string This module table name */
public const TABLE_NAME = 'periodical';
/** @var string This module meta type */
public const META_TYPE = 'periodical';
public static function checkCustomContext(int $context): ?bool public static function checkCustomContext(int $context): ?bool
{ {
return in_array($context, [My::MANAGE, My::MENU]) ? return in_array($context, [My::MANAGE, My::MENU]) ?

View File

@ -40,7 +40,7 @@ class Uninstall extends Process
->addUserAction( ->addUserAction(
'tables', 'tables',
'delete', 'delete',
My::TABLE_NAME My::id()
) )
->addUserAction( ->addUserAction(
'plugins', 'plugins',
@ -60,7 +60,7 @@ class Uninstall extends Process
->addDirectAction( ->addDirectAction(
'tables', 'tables',
'delete', 'delete',
My::TABLE_NAME My::id()
) )
->addDirectAction( ->addDirectAction(
'plugins', 'plugins',

View File

@ -48,7 +48,7 @@ class Utils
*/ */
public static function openCursor(): Cursor public static function openCursor(): Cursor
{ {
return dcCore::app()->con->openCursor(dcCore::app()->prefix . My::TABLE_NAME); return dcCore::app()->con->openCursor(dcCore::app()->prefix . My::id());
} }
/** /**
@ -82,7 +82,7 @@ class Utils
]); ]);
} }
$sql->from($sql->as(dcCore::app()->prefix . My::TABLE_NAME, 'T'), false, true); $sql->from($sql->as(dcCore::app()->prefix . My::id(), 'T'), false, true);
if (!empty($params['join'])) { if (!empty($params['join'])) {
$sql->join($params['join']); $sql->join($params['join']);
@ -150,12 +150,12 @@ class Utils
*/ */
public static function addPeriod(Cursor $cur): int public static function addPeriod(Cursor $cur): int
{ {
dcCore::app()->con->writeLock(dcCore::app()->prefix . My::TABLE_NAME); dcCore::app()->con->writeLock(dcCore::app()->prefix . My::id());
try { try {
// get next id // get next id
$sql = new SelectStatement(); $sql = new SelectStatement();
$rs = $sql->from(dcCore::app()->prefix . My::TABLE_NAME) $rs = $sql->from(dcCore::app()->prefix . My::id())
->column($sql->max('periodical_id')) ->column($sql->max('periodical_id'))
->select(); ->select();
@ -207,7 +207,7 @@ class Utils
} }
$sql = new DeleteStatement(); $sql = new DeleteStatement();
$sql->from(dcCore::app()->prefix . My::TABLE_NAME) $sql->from(dcCore::app()->prefix . My::id())
->where('blog_id = ' . $sql->quote((string) dcCore::app()->blog?->id)) ->where('blog_id = ' . $sql->quote((string) dcCore::app()->blog?->id))
->and('periodical_id = ' . $period_id) ->and('periodical_id = ' . $period_id)
->delete(); ->delete();
@ -236,7 +236,7 @@ class Utils
$sql = new DeleteStatement(); $sql = new DeleteStatement();
$sql->from(dcCore::app()->prefix . dcMeta::META_TABLE_NAME) $sql->from(dcCore::app()->prefix . dcMeta::META_TABLE_NAME)
->where('meta_type = ' . $sql->quote(My::META_TYPE)) ->where('meta_type = ' . $sql->quote(My::id()))
->and('post_id ' . $sql->in($ids)) ->and('post_id ' . $sql->in($ids))
->delete(); ->delete();
} }
@ -282,11 +282,11 @@ class Utils
->join( ->join(
(new JoinStatement()) (new JoinStatement())
->left() ->left()
->from($sql->as(dcCore::app()->prefix . My::TABLE_NAME, 'T')) ->from($sql->as(dcCore::app()->prefix . My::id(), 'T'))
->on('CAST(T.periodical_id as char) = CAST(R.meta_id as char)') ->on('CAST(T.periodical_id as char) = CAST(R.meta_id as char)')
->statement() ->statement()
) )
->and('R.meta_type = ' . $sql->quote(My::META_TYPE)) ->and('R.meta_type = ' . $sql->quote(My::id()))
->and("T.periodical_type = 'post' ") ->and("T.periodical_type = 'post' ")
; ;
@ -343,7 +343,7 @@ class Utils
try { try {
$cur->setField('post_id', $post_id); $cur->setField('post_id', $post_id);
$cur->setField('meta_id', $period_id); $cur->setField('meta_id', $period_id);
$cur->setField('meta_type', My::META_TYPE); $cur->setField('meta_type', My::id());
$cur->insert(); $cur->insert();
dcCore::app()->con->unlock(); dcCore::app()->con->unlock();
} catch (Exception $e) { } catch (Exception $e) {
@ -362,7 +362,7 @@ class Utils
{ {
$sql = new DeleteStatement(); $sql = new DeleteStatement();
$sql->from(dcCore::app()->prefix . dcMeta::META_TABLE_NAME) $sql->from(dcCore::app()->prefix . dcMeta::META_TABLE_NAME)
->where('meta_type = ' . $sql->quote(My::META_TYPE)) ->where('meta_type = ' . $sql->quote(My::id()))
->and('post_id = ' . $post_id) ->and('post_id = ' . $post_id)
->delete(); ->delete();
} }
@ -395,7 +395,7 @@ class Utils
$sql = new DeleteStatement(); $sql = new DeleteStatement();
$sql->from(dcCore::app()->prefix . dcMeta::META_TABLE_NAME) $sql->from(dcCore::app()->prefix . dcMeta::META_TABLE_NAME)
->where('meta_type = ' . $sql->quote(My::META_TYPE)) ->where('meta_type = ' . $sql->quote(My::id()))
->and('post_id ' . $sql->in($ids)) ->and('post_id ' . $sql->in($ids))
->delete(); ->delete();
} }