From 93ff90472913d73a8e69a327da44c29efde45de6 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Sun, 30 Jul 2023 21:42:46 +0200 Subject: [PATCH] release 1.2 --- CHANGELOG.md | 5 +++++ README.md | 5 +++-- _define.php | 4 ++-- dcstore.xml | 6 +++--- src/Backend.php | 51 +++++++++++++++++++------------------------------ 5 files changed, 33 insertions(+), 38 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3af8ad3..16279a0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +1.2 - 2023.07.30 +- require Dotclear 2.26 +- require PHP 7.4+ +- update to Dotclear 2.27-dev + 1.1.1 - 2023..04.23 - require Dotclear 2.26 - use latest dotclear namespace diff --git a/README.md b/README.md index e56e843..192505a 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [![Release](https://img.shields.io/github/v/release/JcDenis/tinyPacker)](https://github.com/JcDenis/tinyPacker/releases) [![Date](https://img.shields.io/github/release-date/JcDenis/tinyPacker)](https://github.com/JcDenis/tinyPacker/releases) [![Issues](https://img.shields.io/github/issues/JcDenis/tinyPacker)](https://github.com/JcDenis/tinyPacker/issues) -[![Dotclear](https://img.shields.io/badge/dotclear-v2.26-blue.svg)](https://fr.dotclear.org/download) +[![Dotclear](https://img.shields.io/badge/dotclear-v2.27-blue.svg)](https://fr.dotclear.org/download) [![Dotaddict](https://img.shields.io/badge/dotaddict-official-green.svg)](https://plugins.dotaddict.org/dc2/details/tinyPacker) [![License](https://img.shields.io/github/license/JcDenis/tinyPacker)](https://github.com/JcDenis/tinyPacker/blob/master/LICENSE) @@ -20,8 +20,9 @@ direct from Dotclear blog manager. _tinyPacker_ requires: * Super administrator permissions - * Dotclear 2.26 * A writable public directory. + * Dotclear 2.27 + * PHP 7.4+ ## USAGE diff --git a/_define.php b/_define.php index 81bc234..37bb861 100644 --- a/_define.php +++ b/_define.php @@ -18,9 +18,9 @@ $this->registerModule( 'Tiny packer', 'Quick pack theme or plugin into public dir', 'Jean-Christian Denis', - '1.1.1', + '1.2', [ - 'requires' => [['core', '2.26']], + 'requires' => [['core', '2.27']], 'permissions' => null, 'type' => 'plugin', 'support' => 'https://github.com/JcDenis/' . basename(__DIR__), diff --git a/dcstore.xml b/dcstore.xml index 0c1540e..3f26c37 100644 --- a/dcstore.xml +++ b/dcstore.xml @@ -2,11 +2,11 @@ Tiny packer - 1.1.1 + 1.2 Jean-Christian Denis Quick pack theme or plugin into public dir - https://github.com/JcDenis/tinyPacker/releases/download/v1.1.1/plugin-tinyPacker.zip - 2.26 + https://github.com/JcDenis/tinyPacker/releases/download/v1.2/plugin-tinyPacker.zip + 2.27 https://plugins.dotaddict.org/dc2/details/tinyPacker https://github.com/JcDenis/tinyPacker diff --git a/src/Backend.php b/src/Backend.php index 898df5b..60b4929 100644 --- a/src/Backend.php +++ b/src/Backend.php @@ -14,23 +14,24 @@ declare(strict_types=1); namespace Dotclear\Plugin\tinyPacker; -use adminModulesList; use dcCore; -use dcNsProcess; -use dcPage; +use Dotclear\Core\Process; +use Dotclear\Core\Backend\ModulesList; +use Dotclear\Core\Backend\Notices; use Dotclear\Helper\File\Files; use Dotclear\Helper\File\Path; use Dotclear\Helper\File\Zip\Zip; +use Dotclear\Helper\Html\Form\Submit; use Dotclear\Helper\Html\Html; use Dotclear\Helper\Network\Http; use Exception; /** - * tinyPacker admin class + * tinyPacker admin class. * * Add action and button to modules lists. */ -class Backend extends dcNsProcess +class Backend extends Process { /** @var string Public packages folder */ public const TINYPACKER_DIR = 'packages'; @@ -52,36 +53,23 @@ class Backend extends dcNsProcess public static function init(): bool { - static::$init = defined('DC_CONTEXT_ADMIN') - && !is_null(dcCore::app()->auth) - && dcCore::app()->auth->isSuperAdmin(); - - return static::$init; + return self::status(defined('DC_CONTEXT_ADMIN') && dcCore::app()->auth->isSuperAdmin()); } public static function process(): bool { - if (!static::$init) { + if (!self::status()) { return false; } dcCore::app()->addBehaviors([ - 'adminModulesListGetActions' => function (adminModulesList $list, string $id, array $_): string { + 'adminModulesListGetActions' => function (ModulesList $list, string $id, array $_): string { return in_array($list->getList(), [ 'plugin-activate', 'theme-activate', - ]) ? sprintf( - '', - self::id(), - Html::escapeHTML($id) - ) : ''; + ]) ? (new Submit([self::id() . '[' . Html::escapeHTML($id) . ']']))->value(__('Pack'))->render() : ''; }, - 'adminModulesListDoActions' => function (adminModulesList $list, array $modules, string $type): void { - # nullsafe - if (is_null(dcCore::app()->blog)) { - return; - } - + 'adminModulesListDoActions' => function (ModulesList $list, array $modules, string $type): void { # Pack action if (empty($_POST[self::id()]) || !is_array($_POST[self::id()])) { @@ -104,22 +92,22 @@ class Backend extends dcNsProcess $modules = array_keys($_POST[self::id()]); $id = $modules[0]; - if (!$list->modules->moduleExists($id)) { + $module = $list->modules->getDefine($id); + if (!$module->isDefined()) { throw new Exception(__('No such module.')); } - $module = $list->modules->getModules($id); # Packages names $files = [ $type . '-' . $id . '.zip', - $type . '-' . $id . '-' . $module['version'] . '.zip', + $type . '-' . $id . '-' . $module->get('version') . '.zip', ]; # Create zip foreach ($files as $file) { @set_time_limit(300); - - $zip = new Zip($dir . '/' . $file); + $fp = fopen($dir . DIRECTORY_SEPARATOR . $file, 'wb'); + $zip = new Zip($fp); foreach (self::TINYPACKER_EXCLUDE as $e) { $zip->addExclusion(sprintf( @@ -128,12 +116,13 @@ class Backend extends dcNsProcess )); } - $zip->addDirectory((string) Path::real($module['root']), $id, true); + $zip->addDirectory((string) Path::real($module->get('root')), $id, true); + $zip->write(); $zip->close(); - unset($zip); + unset($zip, $fp); } - dcPage::addSuccessNotice( + Notices::addSuccessNotice( __('Task successfully executed.') ); Http::redirect($list->getURL());