use database statement
This commit is contained in:
parent
0fd637fab0
commit
d633c811a5
@ -16,6 +16,10 @@ namespace Dotclear\Plugin\Uninstaller\Cleaner;
|
|||||||
|
|
||||||
use dcCore;
|
use dcCore;
|
||||||
use dcNamespace;
|
use dcNamespace;
|
||||||
|
use Dotclear\Database\Statement\{
|
||||||
|
DeleteStatement,
|
||||||
|
SelectStatement
|
||||||
|
};
|
||||||
use Dotclear\Plugin\Uninstaller\{
|
use Dotclear\Plugin\Uninstaller\{
|
||||||
AbstractCleaner,
|
AbstractCleaner,
|
||||||
ActionDescriptor
|
ActionDescriptor
|
||||||
@ -88,24 +92,25 @@ class Settings extends AbstractCleaner
|
|||||||
|
|
||||||
public function values(): array
|
public function values(): array
|
||||||
{
|
{
|
||||||
$res = dcCore::app()->con->select(
|
$sql = new SelectStatement();
|
||||||
'SELECT setting_ns ' .
|
$sql->from(dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME)
|
||||||
'FROM ' . dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME . ' ' .
|
->columns(['setting_ns'])
|
||||||
'WHERE blog_id IS NULL ' .
|
->where($sql->orGroup(['blog_id IS NULL', 'blog_id IS NOT NULL']))
|
||||||
'OR blog_id IS NOT NULL ' .
|
->group('setting_ns');
|
||||||
'GROUP BY setting_ns'
|
|
||||||
);
|
|
||||||
|
|
||||||
|
$res = $sql->select();
|
||||||
$rs = [];
|
$rs = [];
|
||||||
$i = 0;
|
$i = 0;
|
||||||
while ($res->fetch()) {
|
while ($res->fetch()) {
|
||||||
|
$sql = new SelectStatement();
|
||||||
|
$sql->from(dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME)
|
||||||
|
->fields([$sql->count('*')])
|
||||||
|
->where($sql->orGroup(['blog_id IS NULL', 'blog_id IS NOT NULL']))
|
||||||
|
->and('setting_ns = ' . $sql->quote($res->f('setting_ns')))
|
||||||
|
->group('setting_ns');
|
||||||
|
|
||||||
$rs[$i]['key'] = $res->f('setting_ns');
|
$rs[$i]['key'] = $res->f('setting_ns');
|
||||||
$rs[$i]['value'] = dcCore::app()->con->select(
|
$rs[$i]['value'] = $sql->select()->f(0);
|
||||||
'SELECT count(*) FROM ' . dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME . ' ' .
|
|
||||||
"WHERE setting_ns = '" . $res->f('setting_ns') . "' " .
|
|
||||||
'AND (blog_id IS NULL OR blog_id IS NOT NULL) ' .
|
|
||||||
'GROUP BY setting_ns '
|
|
||||||
)->f(0);
|
|
||||||
$i++;
|
$i++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,30 +119,29 @@ class Settings extends AbstractCleaner
|
|||||||
|
|
||||||
public function execute(string $action, string $ns): bool
|
public function execute(string $action, string $ns): bool
|
||||||
{
|
{
|
||||||
|
$sql = new DeleteStatement();
|
||||||
|
|
||||||
if ($action == 'delete_global') {
|
if ($action == 'delete_global') {
|
||||||
dcCore::app()->con->execute(
|
$sql->from(dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME)
|
||||||
'DELETE FROM ' . dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME . ' ' .
|
->where('blog_id IS NULL')
|
||||||
'WHERE blog_id IS NULL ' .
|
->and('setting_ns = ' . $sql->quote((string) $ns))
|
||||||
"AND setting_ns = '" . dcCore::app()->con->escapeStr((string) $ns) . "' "
|
->delete();
|
||||||
);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if ($action == 'delete_local') {
|
if ($action == 'delete_local') {
|
||||||
dcCore::app()->con->execute(
|
$sql->from(dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME)
|
||||||
'DELETE FROM ' . dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME . ' ' .
|
->where('blog_id = ' . $sql->quote((string) dcCore::app()->blog?->id))
|
||||||
"WHERE blog_id = '" . dcCore::app()->con->escapeStr((string) dcCore::app()->blog?->id) . "' " .
|
->and('setting_ns = ' . $sql->quote((string) $ns))
|
||||||
"AND setting_ns = '" . dcCore::app()->con->escapeStr((string) $ns) . "' "
|
->delete();
|
||||||
);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
if ($action == 'delete_all') {
|
if ($action == 'delete_all') {
|
||||||
dcCore::app()->con->execute(
|
$sql->from(dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME)
|
||||||
'DELETE FROM ' . dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME . ' ' .
|
->where('setting_ns = ' . $sql->quote((string) $ns))
|
||||||
"WHERE setting_ns = '" . dcCore::app()->con->escapeStr((string) $ns) . "' " .
|
->and($sql->orGroup(['blog_id IS NULL', 'blog_id IS NOT NULL']))
|
||||||
"AND (blog_id IS NULL OR blog_id != '') "
|
->delete();
|
||||||
);
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@ -146,17 +150,17 @@ class Settings extends AbstractCleaner
|
|||||||
foreach (explode(';', $ns) as $pair) {
|
foreach (explode(';', $ns) as $pair) {
|
||||||
$exp = explode(':', $pair);
|
$exp = explode(':', $pair);
|
||||||
if (count($exp) == 2) {
|
if (count($exp) == 2) {
|
||||||
$or[] = "setting_ns = '" . dcCore::app()->con->escapeStr((string) $exp[0]) . "' AND setting_id = '" . dcCore::app()->con->escapeStr((string) $exp[1]) . "'";
|
$or[] = $sql->andGroup(['setting_ns = ' . $sq->quote((string) $exp[0]), 'setting_id = ' . $sql->quote((string) $exp[1])]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (empty($or)) {
|
if (empty($or)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
dcCore::app()->con->execute(
|
|
||||||
'DELETE FROM ' . dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME . ' ' .
|
$sql->from(dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME)
|
||||||
"WHERE (" . implode(' OR ', $or) . ") " .
|
->where($sql->orGroup($or))
|
||||||
"AND (blog_id IS NULL OR blog_id != '') "
|
->and($sql->orGroup(['blog_id IS NULL', 'blog_id IS NOT NULL']))
|
||||||
);
|
->delete();
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user