add Cleaner for preferences (workspaces)

This commit is contained in:
Jean-Christian Paul Denis 2023-04-23 17:58:35 +02:00
parent a01d41d535
commit 36c99b2a34
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
3 changed files with 283 additions and 24 deletions

View File

@ -1,15 +1,15 @@
# Language: Français # Language: Français
# Module: Uninstaller - 0.2 # Module: Uninstaller - 0.4
# Date: 2023-04-16 09:40:12 # Date: 2023-04-23 15:51:03
# Author: , contact@jcdenis.fr # Author: , contact@jcdenis.fr
# Translated with translater 2023.03.19 # Translated with translater 2023.03.19
msgid "" msgid ""
msgstr "" msgstr ""
"Content-Type: text/plain; charset=UTF-8\n" "Content-Type: text/plain; charset=UTF-8\n"
"Project-Id-Version: Uninstaller 0.2\n" "Project-Id-Version: Uninstaller 0.4\n"
"POT-Creation-Date: \n" "POT-Creation-Date: \n"
"PO-Revision-Date: 2023-04-16T09:40:12+00:00\n" "PO-Revision-Date: 2023-04-23T15:51:03+00:00\n"
"Last-Translator: Jean-Christian Denis\n" "Last-Translator: Jean-Christian Denis\n"
"Language-Team: \n" "Language-Team: \n"
"MIME-Version: 1.0\n" "MIME-Version: 1.0\n"
@ -100,6 +100,74 @@ msgstr "fichiers et répertoires du plugin \"%s\" effacés"
msgid "Failed to delete \"%s\" plugin files and directories" msgid "Failed to delete \"%s\" plugin files and directories"
msgstr "Impossible d'effacer les fichiers et répertoires du plugin \"%s\"" msgstr "Impossible d'effacer les fichiers et répertoires du plugin \"%s\""
#: src/Cleaner/Preferences.php:40
msgid "Preferences"
msgstr "Préférences"
#: src/Cleaner/Preferences.php:41
msgid "Users preferences workspaces"
msgstr "Préférences utilisateurs (workspaces)"
#: src/Cleaner/Preferences.php:50
msgid "delete selected global preferences workspaces"
msgstr "effacer les préférences globales"
#: src/Cleaner/Preferences.php:51
msgid "delete \"%s\" global preferences workspace"
msgstr "effacer les préférences globales \"%s\""
#: src/Cleaner/Preferences.php:52
msgid "\"%s\" global preferences workspace deleted"
msgstr "préférences globales \"%s\" effacées"
#: src/Cleaner/Preferences.php:53
msgid "Failed to delete \"%s\" global preferences workspace"
msgstr "Impossible d'effacer les préférences globales \"%s\""
#: src/Cleaner/Preferences.php:57
msgid "delete selected users preferences workspaces"
msgstr "effacer les préférences utilisateurs sélectionnées"
#: src/Cleaner/Preferences.php:58
msgid "delete \"%s\" users preferences workspace"
msgstr "effacer les préférences utilisateurs \"%s\""
#: src/Cleaner/Preferences.php:59
msgid "\"%s\" users preferences workspace deleted"
msgstr "préférences utilistateurs \"%s\" effacées"
#: src/Cleaner/Preferences.php:60
msgid "Failed to delete \"%s\" users preferences workspace"
msgstr "Impossible d'effacer les préférences utilisateurs \"%s\""
#: src/Cleaner/Preferences.php:64
msgid "delete selected preferences workspaces"
msgstr "effacer les préférences selectionnées"
#: src/Cleaner/Preferences.php:65
msgid "delete \"%s\" preferences workspace"
msgstr "effacer les préférences \"%s\""
#: src/Cleaner/Preferences.php:66
msgid "\"%s\" preferences workspace deleted"
msgstr "préférences \"%s\" effacées"
#: src/Cleaner/Preferences.php:67
msgid "Failed to delete \"%s\" preferences workspace"
msgstr "Impossible d'effacer les préférences \"%s\""
#: src/Cleaner/Preferences.php:72
msgid "delete related preferences"
msgstr "effacer les préférences associées"
#: src/Cleaner/Preferences.php:73
msgid "related preferences deleted"
msgstr "préférences associées effacées"
#: src/Cleaner/Preferences.php:74
msgid "Failed to delete related preferences"
msgstr "Impossible d'effacer les préférences associées"
#: src/Cleaner/Settings.php:41 #: src/Cleaner/Settings.php:41
msgid "Namespaces registered in dcSettings" msgid "Namespaces registered in dcSettings"
msgstr "Espaces de nom (namespaces) enregistrés dans dcSettings" msgstr "Espaces de nom (namespaces) enregistrés dans dcSettings"
@ -164,39 +232,39 @@ msgstr "paramètres relatifs effacer"
msgid "Failed to delete related settings" msgid "Failed to delete related settings"
msgstr "Impossible d'effacer les paramètres relatifs" msgstr "Impossible d'effacer les paramètres relatifs"
#: src/Cleaner/Tables.php:36 #: src/Cleaner/Tables.php:37
msgid "All database tables of Dotclear" msgid "All database tables of Dotclear"
msgstr "Toutes les tables Dotclear de la base de données" msgstr "Toutes les tables Dotclear de la base de données"
#: src/Cleaner/Tables.php:45 #: src/Cleaner/Tables.php:46
msgid "delete selected tables" msgid "delete selected tables"
msgstr "effacer les tables sélectionnées" msgstr "effacer les tables sélectionnées"
#: src/Cleaner/Tables.php:46 #: src/Cleaner/Tables.php:47
msgid "delete \"%s\" table" msgid "delete \"%s\" table"
msgstr "Supprimer la table \"%s\"" msgstr "Supprimer la table \"%s\""
#: src/Cleaner/Tables.php:47 #: src/Cleaner/Tables.php:48
msgid "\"%s\" table deleted" msgid "\"%s\" table deleted"
msgstr "table \"%s\" supprimée" msgstr "table \"%s\" supprimée"
#: src/Cleaner/Tables.php:48 #: src/Cleaner/Tables.php:49
msgid "Failed to delete \"%s\" table" msgid "Failed to delete \"%s\" table"
msgstr "Impossible de supprimer la table \"%s\"" msgstr "Impossible de supprimer la table \"%s\""
#: src/Cleaner/Tables.php:52 #: src/Cleaner/Tables.php:53
msgid "empty selected tables" msgid "empty selected tables"
msgstr "vider les tables selectionnées" msgstr "vider les tables selectionnées"
#: src/Cleaner/Tables.php:53 #: src/Cleaner/Tables.php:54
msgid "empty \"%s\" table" msgid "empty \"%s\" table"
msgstr "vider la table \"%s\"" msgstr "vider la table \"%s\""
#: src/Cleaner/Tables.php:54 #: src/Cleaner/Tables.php:55
msgid "\"%s\" table emptied" msgid "\"%s\" table emptied"
msgstr "table \"%s\" vidée" msgstr "table \"%s\" vidée"
#: src/Cleaner/Tables.php:55 #: src/Cleaner/Tables.php:56
msgid "Failed to empty \"%s\" table" msgid "Failed to empty \"%s\" table"
msgstr "Impossible de vider la table \"%s\"" msgstr "Impossible de vider la table \"%s\""
@ -260,47 +328,47 @@ msgstr "numéro de version de \"%s\" supprimé"
msgid "Failed to delete \"%s\" version number" msgid "Failed to delete \"%s\" version number"
msgstr "Impossible de supprimer le numéro de version de \"%s\"" msgstr "Impossible de supprimer le numéro de version de \"%s\""
#: src/Cleaners.php:84 #: src/Cleaners.php:87
msgid "Unknown cleaner \"%s\"" msgid "Unknown cleaner \"%s\""
msgstr "Nettoyeur \"%s\" inconnu" msgstr "Nettoyeur \"%s\" inconnu"
#: src/Cleaners.php:87 #: src/Cleaners.php:90
msgid "Unsintaller can't remove itself" msgid "Unsintaller can't remove itself"
msgstr "Le désinstalleur ne peut pas se supprimer lui-même" msgstr "Le désinstalleur ne peut pas se supprimer lui-même"
#: src/Manage.php:64 #: src/Manage.php:65
msgid "Unknown module id to uninstall" msgid "Unknown module id to uninstall"
msgstr "Module a désinstaller inconnu" msgstr "Module a désinstaller inconnu"
#: src/Manage.php:71 #: src/Manage.php:73
msgid "There are no uninstall actions for this module" msgid "There are no uninstall actions for this module"
msgstr "Il n'y a aucune action pour ce module" msgstr "Il n'y a aucune action pour ce module"
#: src/Manage.php:93 #: src/Manage.php:98
msgid "Uninstall action successfuly excecuted" msgid "Uninstall action successfuly excecuted"
msgstr "Actions de désinstallation exécutées avec succès" msgstr "Actions de désinstallation exécutées avec succès"
#: src/Manage.php:96 #: src/Manage.php:101
msgid "No uninstall action done" msgid "No uninstall action done"
msgstr "Aucune action de désinstallation exécutée" msgstr "Aucune action de désinstallation exécutée"
#: src/Manage.php:125 #: src/Manage.php:129
msgid "Are you sure you perform these ations?" msgid "Are you sure you perform these ations?"
msgstr "Êtes-vous sûre de vouloir effectuer ces actions ?" msgstr "Êtes-vous sûre de vouloir effectuer ces actions ?"
#: src/Manage.php:154 #: src/Manage.php:158
msgid "Perform selected actions" msgid "Perform selected actions"
msgstr "Effectuer les actions sélectionnées" msgstr "Effectuer les actions sélectionnées"
#: src/Manage.php:160 #: src/Manage.php:164
msgid "Uninstall theme \"%s\"" msgid "Uninstall theme \"%s\""
msgstr "Désinstaller le thème \"%s\"" msgstr "Désinstaller le thème \"%s\""
#: src/Manage.php:160 #: src/Manage.php:164
msgid "Uninstall plugin \"%s\"" msgid "Uninstall plugin \"%s\""
msgstr "Désinstaller le plugin \"%s\"" msgstr "Désinstaller le plugin \"%s\""
#: src/Manage.php:161 #: src/Manage.php:165
msgid "The module \"%s %s\" offers advanced unsintall process:" msgid "The module \"%s %s\" offers advanced unsintall process:"
msgstr "Le module \"%s %s\" propose un processus de désinstallation avancée :" msgstr "Le module \"%s %s\" propose un processus de désinstallation avancée :"

190
src/Cleaner/Preferences.php Normal file
View File

@ -0,0 +1,190 @@
<?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 dcWorkspace;
use Dotclear\Database\Statement\{
DeleteStatement,
SelectStatement
};
use Dotclear\Plugin\Uninstaller\{
AbstractCleaner,
ActionDescriptor
};
/**
* Users preferences cleaner.
*
* Cleaner manages entire users preferences workspace
* except 'delete_related' which can pickup preference ws/id pairs
*/
class Preferences extends AbstractCleaner
{
protected function properties(): array
{
return [
'id' => 'preferences',
'name' => __('Preferences'),
'desc' => __('Users preferences workspaces'),
];
}
protected function actions(): array
{
return [
new ActionDescriptor([
'id' => 'delete_global',
'select' => __('delete selected global preferences workspaces'),
'query' => __('delete "%s" global preferences workspace'),
'success' => __('"%s" global preferences workspace deleted'),
'error' => __('Failed to delete "%s" global preferences workspace'),
]),
new ActionDescriptor([
'id' => 'delete_local',
'select' => __('delete selected users preferences workspaces'),
'query' => __('delete "%s" users preferences workspace'),
'success' => __('"%s" users preferences workspace deleted'),
'error' => __('Failed to delete "%s" users preferences workspace'),
]),
new ActionDescriptor([
'id' => 'delete_all',
'select' => __('delete selected preferences workspaces'),
'query' => __('delete "%s" preferences workspace'),
'success' => __('"%s" preferences workspace deleted'),
'error' => __('Failed to delete "%s" preferences workspace'),
]),
// $ns = 'pref_ws:pref_id;pref_ws:pref_id;...' for global and users preferences
new ActionDescriptor([
'id' => 'delete_related',
'query' => __('delete related preferences'),
'success' => __('related preferences deleted'),
'error' => __('Failed to delete related preferences'),
]),
];
}
public function distributed(): array
{
return [
'accessibility',
'interface',
'maintenance',
'profile',
'dashboard',
'favorites',
'toggles',
];
}
public function values(): array
{
$sql = new SelectStatement();
$sql->from(dcCore::app()->prefix . dcWorkspace::WS_TABLE_NAME)
->columns(['pref_ws'])
->where($sql->orGroup(['user_id IS NULL', 'user_id IS NOT NULL']))
->group('pref_ws');
$res = $sql->select();
if ($res == null || $res->isEmpty()) {
return [];
}
$rs = [];
$i = 0;
while ($res->fetch()) {
$sql = new SelectStatement();
$sql->from(dcCore::app()->prefix . dcWorkspace::WS_TABLE_NAME)
->fields([$sql->count('*')])
->where($sql->orGroup(['user_id IS NULL', 'user_id IS NOT NULL']))
->and('pref_ws = ' . $sql->quote($res->f('pref_ws')))
->group('pref_ws');
$rs[$i]['key'] = $res->f('pref_ws');
$rs[$i]['value'] = (int) $sql->select()?->f(0);
$i++;
}
return $rs;
}
public function execute(string $action, string $ns): bool
{
$sql = new DeleteStatement();
if ($action == 'delete_global' && self::checkNs($ns)) {
$sql->from(dcCore::app()->prefix . dcWorkspace::WS_TABLE_NAME)
->where('user_id IS NULL')
->and('pref_ws = ' . $sql->quote((string) $ns))
->delete();
return true;
}
if ($action == 'delete_local' && self::checkNs($ns)) {
$sql->from(dcCore::app()->prefix . dcWorkspace::WS_TABLE_NAME)
->where('user_id = ' . $sql->quote((string) dcCore::app()->blog?->id))
->and('pref_ws = ' . $sql->quote((string) $ns))
->delete();
return true;
}
if ($action == 'delete_all' && self::checkNs($ns)) {
$sql->from(dcCore::app()->prefix . dcWorkspace::WS_TABLE_NAME)
->where('pref_ws = ' . $sql->quote((string) $ns))
->and($sql->orGroup(['user_id IS NULL', 'user_id IS NOT NULL']))
->delete();
return true;
}
if ($action == 'delete_related') {
// check ns match ws:id;
$reg_ws = substr(dcWorkspace::WS_NAME_SCHEMA, 2, -2);
$reg_id = substr(dcWorkspace::WS_ID_SCHEMA, 2, -2);
if (!preg_match_all('#((' . $reg_ws . '):(' . $reg_id . ');?)#', $ns, $matches)) {
return false;
}
// build ws/id requests
$or = [];
foreach ($matches[2] as $key => $name) {
$or[] = $sql->andGroup(['pref_ws = ' . $sql->quote((string) $name), 'pref_id = ' . $sql->quote((string) $matches[3][$key])]);
}
if (empty($or)) {
return false;
}
$sql->from(dcCore::app()->prefix . dcWorkspace::WS_TABLE_NAME)
->where($sql->orGroup($or))
->and($sql->orGroup(['user_id IS NULL', 'user_id IS NOT NULL']))
->delete();
return true;
}
return false;
}
/**
* Check well formed ns.
*
* @param string The ns to check
*
* @return bool True on well formed
*/
private static function checkNs(string $ns): bool
{
return preg_match(dcWorkspace::WS_NAME_SCHEMA, $ns);
}
}

View File

@ -38,6 +38,7 @@ class Prepend extends dcNsProcess
dcCore::app()->addBehavior('UninstallerCleanersConstruct', function (Cleaners $cleaners): void { dcCore::app()->addBehavior('UninstallerCleanersConstruct', function (Cleaners $cleaners): void {
$cleaners $cleaners
->add(new Cleaner\Settings()) ->add(new Cleaner\Settings())
->add(new Cleaner\Preferences())
->add(new Cleaner\Tables()) ->add(new Cleaner\Tables())
->add(new Cleaner\Versions()) ->add(new Cleaner\Versions())
->add(new Cleaner\Logs()) ->add(new Cleaner\Logs())