Compare commits

..

3 Commits
v0.1 ... master

7 changed files with 96 additions and 27 deletions

View File

@ -1,3 +1,10 @@
HideStoreUpdates 0.2 - 2023.11.14
===========================================================
* Require Dotclear 2.28
* Require PHP 8.1+
* Clean old modules versions
* Add Fr translation
HideStoreUpdates 0.1 - 2023.11.13
===========================================================
* Require Dotclear 2.28

View File

@ -1,7 +1,7 @@
# README
[![Release](https://img.shields.io/badge/release-0.1-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/HideStoreUpdates/releases)
![Date](https://img.shields.io/badge/date-2023.11.13-c44d58.svg)
[![Release](https://img.shields.io/badge/release-0.2-a2cbe9.svg)](https://git.dotclear.watch/JcDenis/HideStoreUpdates/releases)
![Date](https://img.shields.io/badge/date-2023.11.14-c44d58.svg)
[![Dotclear](https://img.shields.io/badge/dotclear-v2.28-137bbb.svg)](https://fr.dotclear.org/download)
[![Dotaddict](https://img.shields.io/badge/dotaddict-official-9ac123.svg)](https://plugins.dotaddict.org/dc2/details/HideStoreUpdates)
[![License](https://img.shields.io/badge/license-GPL--2.0-ececec.svg)](https://git.dotclear.watch/JcDenis/HideStoreUpdates/src/branch/master/LICENSE)

View File

@ -18,7 +18,7 @@ $this->registerModule(
'Hide store updates',
'Hide some updates from store',
'Jean-Christian Denis and Contributors',
'0.1',
'0.2',
[
'requires' => [['core', '2.28']],
'permissions' => 'My',

View File

@ -2,10 +2,10 @@
<modules xmlns:da="http://dotaddict.org/da/">
<module id="HideStoreUpdates">
<name>Hide store updates</name>
<version>0.1</version>
<version>0.2</version>
<author>Jean-Christian Denis</author>
<desc>Hide some updates from store</desc>
<file>https://git.dotclear.watch/JcDenis/HideStoreUpdates/releases/download/v0.1/plugin-HideStoreUpdates.zip</file>
<file>https://git.dotclear.watch/JcDenis/HideStoreUpdates/releases/download/v0.2/plugin-HideStoreUpdates.zip</file>
<da:dcmin>2.28</da:dcmin>
<da:details>https://git.dotclear.watch/JcDenis/HideStoreUpdates/src/branch/master/README.md</da:details>
<da:support>https://git.dotclear.watch/JcDenis/HideStoreUpdates/issues</da:support>

View File

@ -0,0 +1,15 @@
<?php
// Language: Français
// Module: HideStoreUpdates - 0.1
// Date: 2023-11-14 21:04:22
// Author: , contact@jcdenis.fr
// Translated with Translater - 2023.11.04
#
# DOT NOT MODIFY THIS FILE !
#
use Dotclear\Helper\L10n;
L10n::$locales['Module %s successfully hidden.'] = 'Module %s caché avec succès';

22
locales/fr/main.po 100644
View File

@ -0,0 +1,22 @@
# Language: Français
# Module: HideStoreUpdates - 0.1
# Date: 2023-11-14 21:04:22
# Author: , contact@jcdenis.fr
# Translated with translater 2023.11.04
msgid ""
msgstr ""
"Content-Type: text/plain; charset=UTF-8\n"
"Project-Id-Version: HideStoreUpdates 0.1\n"
"POT-Creation-Date: \n"
"PO-Revision-Date: 2023-11-14T21:04:22+00:00\n"
"Last-Translator: Jean-Christian Denis\n"
"Language-Team: \n"
"MIME-Version: 1.0\n"
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
#: src/BackendBehaviors.php:88
msgid "Module %s successfully hidden."
msgstr "Module %s caché avec succès"

View File

@ -24,6 +24,14 @@ class BackendBehaviors
{
private static bool $cleared = false;
/**
* Add "Hide" button on modules list.
*
* @param ModulesList $list The modules list
* @param ModuleDefine $define The current module
*
* @return string The button or empty string
*/
public static function adminModulesListGetActionsV2(ModulesList $list, ModuleDefine $define): string
{
return in_array($list->getList(), [
@ -33,7 +41,11 @@ class BackendBehaviors
}
/**
* Hide selected module on modules list.
*
* @param ModulesList $list Th emodules list
* @param array<int, ModuleDefine> $defines The modules
* @param string $type The modules type (plugins or themes)
*/
public static function adminModulesListDoActions(ModulesList $list, array $defines, string $type): void
{
@ -44,33 +56,61 @@ class BackendBehaviors
}
$type = str_starts_with($type, 'theme') ? 'themes' : 'plugins';
$to_add = key($_POST[My::id()]);
$update = key($_POST[My::id()]);
$tmp = explode(' ', $update);
$module = $tmp[0];
$logs = self::getLogs($type);
if (!$logs->isEmpty()) {
$ids = [];
while ($logs->fetch()) {
if ($to_add == $logs->f('log_msg')) {
// Allready hidden!
if ($update == $logs->f('log_msg')) {
// Same module version allready hidden
return;
}
if (str_starts_with($logs->f('log_msg'), $module)) {
// Same module but older version
$ids[] = $logs->f('log_id');
}
}
if (!empty($ids)) {
// Delete older versions
App::log()->deLogs($ids);
}
}
if (!empty($to_add)) {
if (!empty($update)) {
// Add module version
$cur = App::log()->openLogCursor();
$cur->setField('log_table', My::id() . '_' . $type);
$cur->setField('log_msg', $to_add);
$cur->setField('log_msg', $update);
App::log()->addLog($cur);
Notices::AddSuccessNotice(__('Module successfully hidden.'));
Notices::AddSuccessNotice(sprintf(__('Module %s successfully hidden.'), $update));
}
}
/**
* Hide modules from store update list.
*
* @param string $type The modules type (plugins or themes)
* @param ArrayObject<int, ModuleDefine> $defines The modules
*/
public static function afterCheckStoreUpdate(string $type, ArrayObject $defines): void
{
self::clearLogs($type);
if (!self::$cleared && !empty($_GET['nocache'])) {
// Clear (once) modules versions on manual check
$logs = self::getLogs($type);
if (!$logs->isEmpty()) {
$ids = [];
while ($logs->fetch()) {
$ids[] = (int) $logs->f('log_id');
}
App::log()->delLogs($ids);
self::$cleared = true;
return;
}
}
$logs = self::getLogs($type);
if ($logs->isEmpty()) {
@ -89,21 +129,6 @@ class BackendBehaviors
}
}
private static function clearLogs(string $type): void
{
if (!self::$cleared && !empty($_GET['nocache'])) {
$logs = self::getLogs($type);
if (!$logs->isEmpty()) {
$ids = [];
while ($logs->fetch()) {
$ids[] = (int) $logs->f('log_id');
}
App::log()->delLogs($ids);
}
self::$cleared = true;
}
}
private static function getLogs(string $type): MetaRecord
{
return App::log()->getLogs([