Uninstaller/src/Cleaner/Versions.php

104 lines
2.5 KiB
PHP
Raw Normal View History

2023-04-15 15:38:25 +00:00
<?php
/**
* @brief Uninstaller, 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
*/
declare(strict_types=1);
namespace Dotclear\Plugin\Uninstaller\Cleaner;
use dcCore;
use Dotclear\Database\Statement\SelectStatement;
2023-04-15 15:38:25 +00:00
use Dotclear\Plugin\Uninstaller\{
AbstractCleaner,
ActionDescriptor,
ValueDescriptor
2023-04-15 15:38:25 +00:00
};
class Versions extends AbstractCleaner
{
protected function properties(): array
{
return [
'id' => 'versions',
'name' => __('Versions'),
'desc' => __('Versions registered in table "version" of Dotclear'),
];
}
protected function actions(): array
{
return [
new ActionDescriptor([
'id' => 'delete',
'select' => __('delete selected versions numbers'),
2023-04-15 15:38:25 +00:00
'query' => __('delete "%s" version number'),
'success' => __('"%s" version number deleted'),
'error' => __('Failed to delete "%s" version number'),
]),
];
}
public function distributed(): array
{
return [
'antispam',
'blogroll',
'blowupConfig',
'core',
'dcCKEditor',
'dcLegacyEditor',
'pages',
'pings',
'simpleMenu',
'tags',
'widgets',
];
}
public function values(): array
{
$sql = new SelectStatement();
$rs = $sql
->from(dcCore::app()->prefix . dcCore::VERSION_TABLE_NAME)
->columns(['module', 'version'])
->select();
2023-04-15 15:38:25 +00:00
if (is_null($rs) || $rs->isEmpty()) {
return [];
2023-04-15 15:38:25 +00:00
}
$res = [];
while ($rs->fetch()) {
$res[] = new ValueDescriptor(
$rs->f('module'),
$rs->f('version'),
1
);
}
return $res;
2023-04-15 15:38:25 +00:00
}
public function execute(string $action, string $ns): bool
{
if ($action == 'delete') {
dcCore::app()->con->execute(
'DELETE FROM ' . dcCore::app()->prefix . dcCore::VERSION_TABLE_NAME . ' ' .
"WHERE module = '" . dcCore::app()->con->escapeStr((string) $ns) . "' "
);
return true;
}
return false;
}
}