use Database Statement

This commit is contained in:
Jean-Christian Paul Denis 2023-04-16 10:32:45 +02:00
parent 7bc7383ff9
commit c008a15a8c
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951

View File

@ -16,6 +16,11 @@ namespace Dotclear\Plugin\Uninstaller\Cleaner;
use dbSchema; use dbSchema;
use dcCore; use dcCore;
use Dotclear\Database\Statement\{
DeleteStatement,
DropStatement,
SelectStatement
};
use Dotclear\Plugin\Uninstaller\{ use Dotclear\Plugin\Uninstaller\{
AbstractCleaner, AbstractCleaner,
ActionDescriptor ActionDescriptor
@ -83,14 +88,21 @@ class Tables extends AbstractCleaner
$rs = []; $rs = [];
$i = 0; $i = 0;
foreach ($res as $k => $v) { foreach ($res as $k => $v) {
// get only tables with dotclear prefix
if ('' != dcCore::app()->prefix) { if ('' != dcCore::app()->prefix) {
if (!preg_match('/^' . preg_quote(dcCore::app()->prefix) . '(.*?)$/', $v, $m)) { if (!preg_match('/^' . preg_quote(dcCore::app()->prefix) . '(.*?)$/', $v, $m)) {
continue; continue;
} }
$v = $m[1]; $v = $m[1];
} }
$sql = new SelectStatement();
$sql->from(dcCore::app()->prefix . $res[$k])
->fields([$sql->count('*')]);
$rs[$i]['key'] = $v; $rs[$i]['key'] = $v;
$rs[$i]['value'] = dcCore::app()->con->select('SELECT count(*) FROM ' . $res[$k])->f(0); $rs[$i]['value'] = (int) $sql->select()?->f(0);
;
$i++; $i++;
} }
@ -100,17 +112,17 @@ class Tables extends AbstractCleaner
public function execute(string $action, string $ns): bool public function execute(string $action, string $ns): bool
{ {
if (in_array($action, ['empty', 'delete'])) { if (in_array($action, ['empty', 'delete'])) {
dcCore::app()->con->execute( $sql = new DeleteStatement();
'DELETE FROM ' . dcCore::app()->con->escapeSystem(dcCore::app()->prefix . $ns) $sql->from(dcCore::app()->prefix . $ns)
); ->delete();
} }
if ($action == 'empty') { if ($action == 'empty') {
return true; return true;
} }
if ($action == 'delete') { if ($action == 'delete') {
dcCore::app()->con->execute( $sql = new DropStatement();
'DROP TABLE ' . dcCore::app()->con->escapeSystem(dcCore::app()->prefix . $ns) $sql->from(dcCore::app()->prefix . $ns)
); ->drop();
return true; return true;
} }