use plugin ID as table name and meta ID
parent
c83e31fbb2
commit
8684011f3e
|
@ -16,5 +16,6 @@ if (!defined('DC_RC_PATH')) {
|
|||
|
||||
class initPeriodical
|
||||
{
|
||||
// now use My::id()
|
||||
public const PERIOD_TABLE_NAME = 'periodical';
|
||||
}
|
||||
|
|
|
@ -60,7 +60,7 @@ class Frontend extends Process
|
|||
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 . My::TABLE_NAME);
|
||||
$cur_period = dcCore::app()->con->openCursor(dcCore::app()->prefix . My::id());
|
||||
|
||||
while ($periods->fetch()) {
|
||||
// Check if period is ongoing
|
||||
|
|
|
@ -36,7 +36,7 @@ class Install extends Process
|
|||
$t = new Structure(dcCore::app()->con, dcCore::app()->prefix);
|
||||
|
||||
// create database table
|
||||
$t->__get(My::TABLE_NAME)
|
||||
$t->__get(My::id())
|
||||
->field('periodical_id', 'bigint', 0, false)
|
||||
->field('blog_id', 'varchar', 32, false)
|
||||
->field('periodical_type', 'varchar', 32, false, "'post'")
|
||||
|
|
|
@ -104,8 +104,8 @@ class ManagePeriod extends Process
|
|||
Utils::updPeriod($vars->period_id, $cur);
|
||||
|
||||
self::redirect($vars->redir, $vars->period_id, '#period', __('Period successfully updated.'));
|
||||
// Create period
|
||||
} else {
|
||||
// Create period
|
||||
$period_id = Utils::addPeriod($cur);
|
||||
|
||||
self::redirect($vars->redir, $period_id, '#period', __('Period successfully created.'));
|
||||
|
|
|
@ -22,12 +22,6 @@ use Dotclear\Module\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
|
||||
{
|
||||
return in_array($context, [My::MANAGE, My::MENU]) ?
|
||||
|
|
|
@ -40,7 +40,7 @@ class Uninstall extends Process
|
|||
->addUserAction(
|
||||
'tables',
|
||||
'delete',
|
||||
My::TABLE_NAME
|
||||
My::id()
|
||||
)
|
||||
->addUserAction(
|
||||
'plugins',
|
||||
|
@ -60,7 +60,7 @@ class Uninstall extends Process
|
|||
->addDirectAction(
|
||||
'tables',
|
||||
'delete',
|
||||
My::TABLE_NAME
|
||||
My::id()
|
||||
)
|
||||
->addDirectAction(
|
||||
'plugins',
|
||||
|
|
|
@ -48,7 +48,7 @@ class Utils
|
|||
*/
|
||||
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'])) {
|
||||
$sql->join($params['join']);
|
||||
|
@ -150,12 +150,12 @@ class Utils
|
|||
*/
|
||||
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 {
|
||||
// get next id
|
||||
$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'))
|
||||
->select();
|
||||
|
||||
|
@ -207,7 +207,7 @@ class Utils
|
|||
}
|
||||
|
||||
$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))
|
||||
->and('periodical_id = ' . $period_id)
|
||||
->delete();
|
||||
|
@ -236,7 +236,7 @@ class Utils
|
|||
|
||||
$sql = new DeleteStatement();
|
||||
$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))
|
||||
->delete();
|
||||
}
|
||||
|
@ -282,11 +282,11 @@ class Utils
|
|||
->join(
|
||||
(new JoinStatement())
|
||||
->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)')
|
||||
->statement()
|
||||
)
|
||||
->and('R.meta_type = ' . $sql->quote(My::META_TYPE))
|
||||
->and('R.meta_type = ' . $sql->quote(My::id()))
|
||||
->and("T.periodical_type = 'post' ")
|
||||
;
|
||||
|
||||
|
@ -343,7 +343,7 @@ class Utils
|
|||
try {
|
||||
$cur->setField('post_id', $post_id);
|
||||
$cur->setField('meta_id', $period_id);
|
||||
$cur->setField('meta_type', My::META_TYPE);
|
||||
$cur->setField('meta_type', My::id());
|
||||
$cur->insert();
|
||||
dcCore::app()->con->unlock();
|
||||
} catch (Exception $e) {
|
||||
|
@ -362,7 +362,7 @@ class Utils
|
|||
{
|
||||
$sql = new DeleteStatement();
|
||||
$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)
|
||||
->delete();
|
||||
}
|
||||
|
@ -395,7 +395,7 @@ class Utils
|
|||
|
||||
$sql = new DeleteStatement();
|
||||
$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))
|
||||
->delete();
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue