use latest Database namespace
This commit is contained in:
parent
78f131f038
commit
6af93533c4
3 changed files with 36 additions and 34 deletions
|
@ -16,7 +16,7 @@ namespace Dotclear\Plugin\enhancePostContent;
|
||||||
|
|
||||||
use ArrayObject;
|
use ArrayObject;
|
||||||
use dcCore;
|
use dcCore;
|
||||||
use dcRecord;
|
use Dotclear\Database\MetaRecord;
|
||||||
use Dotclear\Plugin\widgets\WidgetsElement;
|
use Dotclear\Plugin\widgets\WidgetsElement;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
||||||
|
@ -30,8 +30,8 @@ abstract class EpcFilter
|
||||||
/** @var string $id The filter id */
|
/** @var string $id The filter id */
|
||||||
protected string $id = 'undefined';
|
protected string $id = 'undefined';
|
||||||
|
|
||||||
/** @var dcRecord $records The filter record if any */
|
/** @var MetaRecord $records The filter record if any */
|
||||||
private ?dcRecord $records = null;
|
private ?MetaRecord $records = null;
|
||||||
|
|
||||||
/** @var int $priority The filter priority (property) */
|
/** @var int $priority The filter priority (property) */
|
||||||
public readonly int $priority;
|
public readonly int $priority;
|
||||||
|
@ -155,15 +155,15 @@ abstract class EpcFilter
|
||||||
* Fitler records are usefull to store and retrieve
|
* Fitler records are usefull to store and retrieve
|
||||||
* list of keyword / replacement etc...
|
* list of keyword / replacement etc...
|
||||||
*
|
*
|
||||||
* @return dcRecord The filter record instance
|
* @return MetaRecord The filter record instance
|
||||||
*/
|
*/
|
||||||
final public function records(): dcRecord
|
final public function records(): MetaRecord
|
||||||
{
|
{
|
||||||
if ($this->records === null && $this->has_list) {
|
if ($this->records === null && $this->has_list) {
|
||||||
$this->records = EpcRecord::getRecords(['epc_filter' => $this->id()]);
|
$this->records = EpcRecord::getRecords(['epc_filter' => $this->id()]);
|
||||||
}
|
}
|
||||||
|
|
||||||
return $this->records ?? dcRecord::newFromArray([]);
|
return $this->records ?? MetaRecord::newFromArray([]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -14,9 +14,11 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Dotclear\Plugin\enhancePostContent;
|
namespace Dotclear\Plugin\enhancePostContent;
|
||||||
|
|
||||||
use cursor;
|
|
||||||
use dcCore;
|
use dcCore;
|
||||||
use dcRecord;
|
use Dotclear\Database\{
|
||||||
|
Cursor,
|
||||||
|
MetaRecord
|
||||||
|
};
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -30,9 +32,9 @@ class EpcRecord
|
||||||
* @param array $params The query params
|
* @param array $params The query params
|
||||||
* @param bool $count_only Count only
|
* @param bool $count_only Count only
|
||||||
*
|
*
|
||||||
* @return dcRecord The records instance
|
* @return MetaRecord The records instance
|
||||||
*/
|
*/
|
||||||
public static function getRecords(array $params, bool $count_only = false): dcRecord
|
public static function getRecords(array $params, bool $count_only = false): MetaRecord
|
||||||
{
|
{
|
||||||
if ($count_only) {
|
if ($count_only) {
|
||||||
$strReq = 'SELECT count(E.epc_id) ';
|
$strReq = 'SELECT count(E.epc_id) ';
|
||||||
|
@ -107,17 +109,17 @@ class EpcRecord
|
||||||
$strReq .= dcCore::app()->con->limit($params['limit']);
|
$strReq .= dcCore::app()->con->limit($params['limit']);
|
||||||
}
|
}
|
||||||
|
|
||||||
return new dcRecord(dcCore::app()->con->select($strReq));
|
return new MetaRecord(dcCore::app()->con->select($strReq));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add record.
|
* Add record.
|
||||||
*
|
*
|
||||||
* @param cursor $cur The cursor
|
* @param Cursor $cur The Cursor
|
||||||
*
|
*
|
||||||
* @return int The record ID
|
* @return int The record ID
|
||||||
*/
|
*/
|
||||||
public static function addRecord(cursor $cur): int
|
public static function addRecord(Cursor $cur): int
|
||||||
{
|
{
|
||||||
dcCore::app()->con->writeLock(dcCore::app()->prefix . My::TABLE_NAME);
|
dcCore::app()->con->writeLock(dcCore::app()->prefix . My::TABLE_NAME);
|
||||||
|
|
||||||
|
@ -137,7 +139,7 @@ class EpcRecord
|
||||||
}
|
}
|
||||||
dcCore::app()->blog?->triggerBlog();
|
dcCore::app()->blog?->triggerBlog();
|
||||||
|
|
||||||
# --BEHAVIOR-- enhancePostContentAfterAddRecord : cursor
|
# --BEHAVIOR-- enhancePostContentAfterAddRecord : Cursor
|
||||||
dcCore::app()->callBehavior('enhancePostContentAfterAddRecord', $cur);
|
dcCore::app()->callBehavior('enhancePostContentAfterAddRecord', $cur);
|
||||||
|
|
||||||
return (int) $cur->getField('epc_id');
|
return (int) $cur->getField('epc_id');
|
||||||
|
@ -147,9 +149,9 @@ class EpcRecord
|
||||||
* Update a record.
|
* Update a record.
|
||||||
*
|
*
|
||||||
* @param int $id The record ID
|
* @param int $id The record ID
|
||||||
* @param cursor $cur The cursor
|
* @param Cursor $cur The Cursor
|
||||||
*/
|
*/
|
||||||
public static function updRecord(int $id, cursor $cur): void
|
public static function updRecord(int $id, Cursor $cur): void
|
||||||
{
|
{
|
||||||
if (empty($id)) {
|
if (empty($id)) {
|
||||||
throw new Exception(__('No such record ID'));
|
throw new Exception(__('No such record ID'));
|
||||||
|
@ -160,7 +162,7 @@ class EpcRecord
|
||||||
$cur->update('WHERE epc_id = ' . $id . " AND blog_id = '" . dcCore::app()->con->escapeStr((string) dcCore::app()->blog?->id) . "' ");
|
$cur->update('WHERE epc_id = ' . $id . " AND blog_id = '" . dcCore::app()->con->escapeStr((string) dcCore::app()->blog?->id) . "' ");
|
||||||
dcCore::app()->blog?->triggerBlog();
|
dcCore::app()->blog?->triggerBlog();
|
||||||
|
|
||||||
# --BEHAVIOR-- enhancePostContentAfterUpdRecord : cursor, int
|
# --BEHAVIOR-- enhancePostContentAfterUpdRecord : Cursor, int
|
||||||
dcCore::app()->callBehavior('enhancePostContentAfterUpdRecord', $cur, $id);
|
dcCore::app()->callBehavior('enhancePostContentAfterUpdRecord', $cur, $id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -218,21 +220,21 @@ class EpcRecord
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Open filter cursor.
|
* Open filter Cursor.
|
||||||
*
|
*
|
||||||
* @return cursor The cursor
|
* @return Cursor The Cursor
|
||||||
*/
|
*/
|
||||||
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::TABLE_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Clean up a cursor.
|
* Clean up a Cursor.
|
||||||
*
|
*
|
||||||
* @param cursor $cur The cursor
|
* @param Cursor $cur The Cursor
|
||||||
*/
|
*/
|
||||||
private static function getCursor(cursor $cur): void
|
private static function getCursor(Cursor $cur): void
|
||||||
{
|
{
|
||||||
if ($cur->getField('epc_key') == '') {
|
if ($cur->getField('epc_key') == '') {
|
||||||
throw new Exception(__('No record key'));
|
throw new Exception(__('No record key'));
|
||||||
|
|
|
@ -14,10 +14,10 @@ declare(strict_types=1);
|
||||||
|
|
||||||
namespace Dotclear\Plugin\enhancePostContent;
|
namespace Dotclear\Plugin\enhancePostContent;
|
||||||
|
|
||||||
use dbStruct;
|
|
||||||
use dcCore;
|
use dcCore;
|
||||||
use dcNamespace;
|
use dcNamespace;
|
||||||
use dcNsProcess;
|
use dcNsProcess;
|
||||||
|
use Dotclear\Database\Structure;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
|
||||||
class Install extends dcNsProcess
|
class Install extends dcNsProcess
|
||||||
|
@ -39,15 +39,15 @@ class Install extends dcNsProcess
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Database
|
// Database
|
||||||
$s = new dbStruct(dcCore::app()->con, dcCore::app()->prefix);
|
$s = new Structure(dcCore::app()->con, dcCore::app()->prefix);
|
||||||
$s->{My::TABLE_NAME}
|
$s->__get(My::TABLE_NAME)
|
||||||
->epc_id('bigint', 0, false)
|
->field('epc_id', 'bigint', 0, false)
|
||||||
->blog_id('varchar', 32, false)
|
->field('blog_id', 'varchar', 32, false)
|
||||||
->epc_type('varchar', 32, false, "'epc'")
|
->field('epc_type', 'varchar', 32, false, "'epc'")
|
||||||
->epc_filter('varchar', 64, false)
|
->field('epc_filter', 'varchar', 64, false)
|
||||||
->epc_key('varchar', 255, false)
|
->field('epc_key', 'varchar', 255, false)
|
||||||
->epc_value('text', 0, false)
|
->field('epc_value', 'text', 0, false)
|
||||||
->epc_upddt('timestamp', 0, false, 'now()')
|
->field('epc_upddt', 'timestamp', 0, false, 'now()')
|
||||||
|
|
||||||
->primary('pk_epc', 'epc_id')
|
->primary('pk_epc', 'epc_id')
|
||||||
->index('idx_epc_blog_id', 'btree', 'blog_id')
|
->index('idx_epc_blog_id', 'btree', 'blog_id')
|
||||||
|
@ -55,7 +55,7 @@ class Install extends dcNsProcess
|
||||||
->index('idx_epc_filter', 'btree', 'epc_filter')
|
->index('idx_epc_filter', 'btree', 'epc_filter')
|
||||||
->index('idx_epc_key', 'btree', 'epc_key');
|
->index('idx_epc_key', 'btree', 'epc_key');
|
||||||
|
|
||||||
(new dbStruct(dcCore::app()->con, dcCore::app()->prefix))->synchronize($s);
|
(new Structure(dcCore::app()->con, dcCore::app()->prefix))->synchronize($s);
|
||||||
$s = null;
|
$s = null;
|
||||||
|
|
||||||
// Uppgrade
|
// Uppgrade
|
||||||
|
|
Loading…
Reference in a new issue