fix tables names

This commit is contained in:
Jean-Christian Paul Denis 2022-11-30 22:35:28 +01:00
parent 3acb671855
commit 5b163c70a9
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
4 changed files with 42 additions and 23 deletions

21
_init.php Normal file
View File

@ -0,0 +1,21 @@
<?php
/**
* @brief zoneclearFeedServer, a plugin for Dotclear 2
*
* @package Dotclear
* @subpackage Plugin
*
* @author Jean-Christian Denis, BG, Pierre Van Glabeke
*
* @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 initActivityReport
{
public const ACTIVITY_TABLE_NAME = 'activity';
public const SETTING_TABLE_NAME = 'activity_setting';
}

View File

@ -23,7 +23,7 @@ if (version_compare($old_version, $new_version, '>=')) {
try {
$s = new dbStruct(dcCore::app()->con, dcCore::app()->prefix);
$s->activity
$s->{initActivityReport::ACTIVITY_TABLE_NAME}
->activity_id('bigint', 0, false)
->activity_type('varchar', 32, false, "'activityReport'")
->blog_id('varchar', 32, true)
@ -41,7 +41,7 @@ try {
->index('idx_activity_blog_status', 'btree', 'activity_blog_status')
->index('idx_activity_super_status', 'btree', 'activity_super_status');
$s->activity_setting
$s->{initActivityReport::SETTING_TABLE_NAME}
->setting_id('varchar', 64, false)
->blog_id('varchar', 32, true)
->setting_type('varchar', 32, false)

View File

@ -20,7 +20,7 @@ $this->addUserAction(
/* action */
'delete',
/* ns */
'activity',
initActivityReport::ACTIVITY_TABLE_NAME,
/* description */
sprintf(__('delete %s table'), '"activity"')
);
@ -31,7 +31,7 @@ $this->addUserAction(
/* action */
'delete',
/* ns */
'activity_setting',
initActivityReport::SETTING_TABLE_NAME,
/* description */
sprintf(__('delete %s table'), '"activity_setting"')
);

View File

@ -21,7 +21,6 @@ class activityReport
private $ns = 'activityReport';
private $_global = 0;
private $blog = null;
private $table = '';
private $groups = [];
private $settings = [];
private $lock_blog = null;
@ -30,7 +29,6 @@ class activityReport
public function __construct($ns = 'activityReport')
{
$this->con = dcCore::app()->con;
$this->table = dcCore::app()->prefix . 'activity';
$this->blog = dcCore::app()->con->escape(dcCore::app()->blog->id);
$this->ns = dcCore::app()->con->escape($ns);
@ -104,7 +102,7 @@ class activityReport
$rs = $this->con->select(
'SELECT setting_id, setting_value, blog_id ' .
'FROM ' . $this->table . '_setting ' .
'FROM ' . dcCore::app()->prefix . initActivityReport::SETTING_TABLE_NAME . ' ' .
"WHERE setting_type='" . $this->ns . "' " .
"AND (blog_id='" . $this->blog . "' OR blog_id IS NULL) " .
'ORDER BY setting_id DESC '
@ -137,8 +135,8 @@ class activityReport
$c = $this->delSetting($n);
$cur = $this->con->openCursor($this->table . '_setting');
$this->con->writeLock($this->table . '_setting');
$cur = $this->con->openCursor(dcCore::app()->prefix . initActivityReport::SETTING_TABLE_NAME);
$this->con->writeLock(dcCore::app()->prefix . initActivityReport::SETTING_TABLE_NAME);
$cur->blog_id = $this->_global ? null : $this->blog;
$cur->setting_id = $this->con->escape($n);
@ -156,7 +154,7 @@ class activityReport
private function delSetting($n)
{
return $this->con->execute(
'DELETE FROM ' . $this->table . '_setting ' .
'DELETE FROM ' . dcCore::app()->prefix . initActivityReport::SETTING_TABLE_NAME . ' ' .
'WHERE blog_id' . ($this->_global ? ' IS NULL' : "='" . $this->blog . "'") . ' ' .
"AND setting_id='" . $this->con->escape($n) . "' " .
"AND setting_type='" . $this->ns . "' "
@ -192,8 +190,8 @@ class activityReport
'E.activity_blog_status, E.activity_super_status ';
}
$r .= 'FROM ' . $this->table . ' E ' .
'LEFT JOIN ' . dcCore::app()->prefix . 'blog B on E.blog_id=B.blog_id ';
$r .= 'FROM ' . dcCore::app()->prefix . initActivityReport::ACTIVITY_TABLE_NAME . ' E ' .
'LEFT JOIN ' . dcCore::app()->prefix . dcBlog::BLOG_TABLE_NAME . ' B on E.blog_id=B.blog_id ';
if (!empty($p['from'])) {
$r .= $p['from'] . ' ';
@ -278,8 +276,8 @@ class activityReport
public function addLog($group, $action, $logs)
{
try {
$cur = $this->con->openCursor($this->table);
$this->con->writeLock($this->table);
$cur = $this->con->openCursor(dcCore::app()->prefix . initActivityReport::ACTIVITY_TABLE_NAME);
$this->con->writeLock(dcCore::app()->prefix . initActivityReport::ACTIVITY_TABLE_NAME);
$cur->activity_id = $this->getNextId();
$cur->activity_type = $this->ns;
@ -430,7 +428,7 @@ class activityReport
// Get blogs and logs count
$rs = $this->con->select(
'SELECT blog_id ' .
'FROM ' . $this->table . ' ' .
'FROM ' . dcCore::app()->prefix . initActivityReport::ACTIVITY_TABLE_NAME . ' ' .
"WHERE activity_type='" . $this->ns . "' " .
'GROUP BY blog_id '
);
@ -445,7 +443,7 @@ class activityReport
$obs_global = dt::str('%Y-%m-%d %H:%M:%S', $ts - (int) $this->settings[1]['obsolete']);
$this->con->execute(
'DELETE FROM ' . $this->table . ' ' .
'DELETE FROM ' . dcCore::app()->prefix . initActivityReport::ACTIVITY_TABLE_NAME . ' ' .
"WHERE activity_type='" . $this->ns . "' " .
"AND (activity_dt < TIMESTAMP '" . $obs_blog . "' " .
"OR activity_dt < TIMESTAMP '" . $obs_global . "') " .
@ -454,8 +452,8 @@ class activityReport
if ($this->con->changes()) {
try {
$cur = $this->con->openCursor($this->table);
$this->con->writeLock($this->table);
$cur = $this->con->openCursor(dcCore::app()->prefix . initActivityReport::ACTIVITY_TABLE_NAME);
$this->con->writeLock(dcCore::app()->prefix . initActivityReport::ACTIVITY_TABLE_NAME);
$cur->activity_id = $this->getNextId();
$cur->activity_type = $this->ns;
@ -478,7 +476,7 @@ class activityReport
private function cleanLogs()
{
$this->con->execute(
'DELETE FROM ' . $this->table . ' ' .
'DELETE FROM ' . dcCore::app()->prefix . initActivityReport::ACTIVITY_TABLE_NAME . ' ' .
"WHERE activity_type='" . $this->ns . "' " .
'AND activity_blog_status = 1 ' .
'AND activity_super_status = 1 '
@ -492,14 +490,14 @@ class activityReport
}
return $this->con->execute(
'DELETE FROM ' . $this->table . ' ' .
'DELETE FROM ' . dcCore::app()->prefix . initActivityReport::ACTIVITY_TABLE_NAME . ' ' .
"WHERE activity_type='" . $this->ns . "' "
);
}
private function updateStatus($from_date_ts, $to_date_ts)
{
$r = 'UPDATE ' . $this->table . ' ';
$r = 'UPDATE ' . dcCore::app()->prefix . initActivityReport::ACTIVITY_TABLE_NAME . ' ';
if ($this->_global) {
$r .= 'SET activity_super_status = 1 WHERE blog_id IS NOT NULL ';
@ -516,7 +514,7 @@ class activityReport
public function getNextId()
{
return $this->con->select(
'SELECT MAX(activity_id) FROM ' . $this->table
'SELECT MAX(activity_id) FROM ' . dcCore::app()->prefix . initActivityReport::ACTIVITY_TABLE_NAME
)->f(0) + 1;
}
@ -747,7 +745,7 @@ class activityReport
$pwd = $pwd['hex'];
$strReq = 'SELECT user_id, user_pwd ' .
'FROM ' . dcCore::app()->prefix . 'user ' .
'FROM ' . dcCore::app()->prefix . dcAuth::USER_TABLE_NAME . ' ' .
"WHERE user_id = '" . dcCore::app()->con->escape($user_id) . "' ";
$rs = dcCore::app()->con->select($strReq);