fix table name

This commit is contained in:
Jean-Christian Denis 2022-12-01 00:42:12 +01:00
parent 93c2607544
commit 43fb134887
Signed by: JcDenis
GPG key ID: 1B5B8C5B90B6C951
5 changed files with 52 additions and 10 deletions

20
_init.php Normal file
View file

@ -0,0 +1,20 @@
<?php
/**
* @brief enhancePostContent, 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 initEnhancePostContent
{
public const EPC_TABLE_NAME = 'epc';
}

View file

@ -14,8 +14,8 @@ if (!defined('DC_CONTEXT_ADMIN')) {
return null; return null;
} }
$dc_min = '2.24';
$mod_id = 'enhancePostContent'; $mod_id = 'enhancePostContent';
$dc_min = dcCore::app()->plugins->moduleInfo($mod_id, 'requires')[0][1];
$new_version = dcCore::app()->plugins->moduleInfo($mod_id, 'version'); $new_version = dcCore::app()->plugins->moduleInfo($mod_id, 'version');
$old_version = dcCore::app()->getVersion($mod_id); $old_version = dcCore::app()->getVersion($mod_id);
@ -36,7 +36,7 @@ try {
# Database # Database
$s = new dbStruct(dcCore::app()->con, dcCore::app()->prefix); $s = new dbStruct(dcCore::app()->con, dcCore::app()->prefix);
$s->epc $s->{initEnhancePostContent::EPC_TABLE_NAME}
->epc_id('bigint', 0, false) ->epc_id('bigint', 0, false)
->blog_id('varchar', 32, false) ->blog_id('varchar', 32, false)
->epc_type('varchar', 32, false, "'epc'") ->epc_type('varchar', 32, false, "'epc'")

View file

@ -25,6 +25,17 @@ $this->addUserAction(
__('delete all settings') __('delete all settings')
); );
$this->addUserAction(
/* type */
'tables',
/* action */
'delete',
/* ns */
initEnhancePostContent::EPC_TABLE_NAME,
/* desc */
__('delete table')
);
$this->addUserAction( $this->addUserAction(
/* type */ /* type */
'plugins', 'plugins',
@ -58,6 +69,17 @@ $this->addDirectAction(
sprintf(__('delete all %s settings'), 'enhancePostContent') sprintf(__('delete all %s settings'), 'enhancePostContent')
); );
$this->addDirectAction(
/* type */
'tables',
/* action */
'delete',
/* ns */
initEnhancePostContent::EPC_TABLE_NAME,
/* desc */
sprintf(__('delete %s table'), 'enhancePostContent')
);
$this->addDirectAction( $this->addDirectAction(
/* type */ /* type */
'plugins', 'plugins',

View file

@ -19,7 +19,7 @@ class epcRecords
public function __construct() public function __construct()
{ {
$this->con = dcCore::app()->con; $this->con = dcCore::app()->con;
$this->table = dcCore::app()->prefix . 'epc'; $this->table = dcCore::app()->prefix . initEnhancePostContent::EPC_TABLE_NAME;
$this->blog = dcCore::app()->con->escape(dcCore::app()->blog->id); $this->blog = dcCore::app()->con->escape(dcCore::app()->blog->id);
} }

View file

@ -16,17 +16,17 @@ if (!isset($old_version)) {
# Move old filters lists from settings to database # Move old filters lists from settings to database
if ($old_version && version_compare('0.6.6', $old_version, '>=')) { if ($old_version && version_compare('0.6.6', $old_version, '>=')) {
$f = dcCore::app()->con->select('SELECT * FROM ' . dcCore::app()->prefix . "setting WHERE setting_ns='enhancePostContent' AND blog_id IS NOT NULL "); $f = dcCore::app()->con->select('SELECT * FROM ' . dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME . " WHERE setting_ns='enhancePostContent' AND blog_id IS NOT NULL ");
while ($f->fetch()) { while ($f->fetch()) {
if (preg_match('#enhancePostContent_(.*?)List#', $f->setting_id, $m)) { if (preg_match('#enhancePostContent_(.*?)List#', $f->setting_id, $m)) {
$curlist = @unserialize($f->setting_value); $curlist = @unserialize($f->setting_value);
if (is_array($curlist)) { if (is_array($curlist)) {
foreach ($curlist as $k => $v) { foreach ($curlist as $k => $v) {
$cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . 'epc'); $cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . initEnhancePostContent::EPC_TABLE_NAME);
dcCore::app()->con->writeLock(dcCore::app()->prefix . 'epc'); dcCore::app()->con->writeLock(dcCore::app()->prefix . initEnhancePostContent::EPC_TABLE_NAME);
$cur->epc_id = dcCore::app()->con->select('SELECT MAX(epc_id) FROM ' . dcCore::app()->prefix . 'epc' . ' ')->f(0) + 1; $cur->epc_id = dcCore::app()->con->select('SELECT MAX(epc_id) FROM ' . dcCore::app()->prefix . initEnhancePostContent::EPC_TABLE_NAME . ' ')->f(0) + 1;
$cur->blog_id = $f->blog_id; $cur->blog_id = $f->blog_id;
$cur->epc_filter = strtolower($m[1]); $cur->epc_filter = strtolower($m[1]);
$cur->epc_key = $k; $cur->epc_key = $k;
@ -36,15 +36,15 @@ if ($old_version && version_compare('0.6.6', $old_version, '>=')) {
dcCore::app()->con->unlock(); dcCore::app()->con->unlock();
} }
} }
dcCore::app()->con->execute('DELETE FROM ' . dcCore::app()->prefix . "setting WHERE setting_id='" . $f->setting_id . "' AND setting_ns='enhancePostContent' AND blog_id='" . $f->blog_id . "' "); dcCore::app()->con->execute('DELETE FROM ' . dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME . " WHERE setting_id='" . $f->setting_id . "' AND setting_ns='enhancePostContent' AND blog_id='" . $f->blog_id . "' ");
} }
} }
# Move old filter name to filter id # Move old filter name to filter id
} elseif ($old_version && version_compare('2021.10.05', $old_version, '>=')) { } elseif ($old_version && version_compare('2021.10.05', $old_version, '>=')) {
$rs = dcCore::app()->con->select('SELECT epc_id, epc_filter FROM ' . dcCore::app()->prefix . 'epc'); $rs = dcCore::app()->con->select('SELECT epc_id, epc_filter FROM ' . dcCore::app()->prefix . initEnhancePostContent::EPC_TABLE_NAME);
while ($rs->fetch()) { while ($rs->fetch()) {
$cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . 'epc'); $cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . initEnhancePostContent::EPC_TABLE_NAME);
$cur->epc_filter = strtolower($rs->epc_filter); $cur->epc_filter = strtolower($rs->epc_filter);