From 788cf5b16aaf4a2ee3af35b8cad0a98997ae3c61 Mon Sep 17 00:00:00 2001 From: Jean-Christian Denis Date: Tue, 30 May 2023 00:24:13 +0200 Subject: [PATCH] add option to separate themes and plugins repository --- locales/fr/main.po | 19 +++++++++-- src/Config.php | 6 ++++ src/Manage.php | 78 +++++++++++++++++++++++++++++++++------------- src/Settings.php | 4 +++ src/Utils.php | 25 ++++++++------- 5 files changed, 97 insertions(+), 35 deletions(-) diff --git a/locales/fr/main.po b/locales/fr/main.po index 55ebaf8..cc37977 100644 --- a/locales/fr/main.po +++ b/locales/fr/main.po @@ -1,9 +1,9 @@ msgid "" msgstr "" "Content-Type: text/plain; charset=UTF-8\n" -"Project-Id-Version: pacKman 2023.05.13\n" +"Project-Id-Version: pacKman 2023.05.24\n" "POT-Creation-Date: \n" -"PO-Revision-Date: 2023-05-24T20:51:11+00:00\n" +"PO-Revision-Date: 2023-05-29T22:03:06+00:00\n" "Last-Translator: Jean-Christian Denis\n" "Language-Team: \n" "MIME-Version: 1.0\n" @@ -31,6 +31,12 @@ msgstr "Répertoire public du blog" msgid "Leave it empty to use Dotclear VAR directory" msgstr "Laisser vide pour utiliser le répertoire VAR de Dotclear" +msgid "Seperate themes and plugins" +msgstr "Séparer les thèmes des plugins" + +msgid "This creates one repository sub folder for themes and one for plugins" +msgstr "Ceci créée un sous-dossier pour les thèmes et un pour les plugins" + msgid "Files" msgstr "Fichiers" @@ -79,12 +85,21 @@ msgstr "Paquetage copié avec succès." msgid "Package successfully moved." msgstr "Paquetage déplacé avec succès." +msgid "Module \"%s\" is not well configured." +msgstr "Le module \"%s\" est mal configuré" + msgid "Plugins root" msgstr "Racine des plugins" msgid "Themes root" msgstr "Racine des thèmes" +msgid "Themes packages repository" +msgstr "Dépôt de paquetages de thèmes" + +msgid "Plugins packages repository" +msgstr "Dépôt de paquetages de plugins" + msgid "Packages repository" msgstr "Dépôt de paquetages" diff --git a/src/Config.php b/src/Config.php index a7a7a8b..56c156a 100644 --- a/src/Config.php +++ b/src/Config.php @@ -126,6 +126,12 @@ class Config extends dcNsProcess dcCore::app()->blog->public_path : __("Blog's public directory") ) . ' ' . __('Leave it empty to use Dotclear VAR directory') ), + // pack_overwrite + (new Para())->items([ + (new Checkbox('pack_typedrepo', $s->pack_typedrepo))->value(1), + (new Label(__('Seperate themes and plugins'), Label::OUTSIDE_LABEL_AFTER))->for('pack_typedrepo')->class('classic'), + ]), + (new Note())->class('form-note')->text(__('This creates one repository sub folder for themes and one for plugins')), ]), (new Fieldset())->class('fieldset')->legend((new Legend(__('Files'))))->fields([ // pack_filename diff --git a/src/Manage.php b/src/Manage.php index da20d62..d5cfad2 100644 --- a/src/Manage.php +++ b/src/Manage.php @@ -43,13 +43,14 @@ class Manage extends dcNsProcess return false; } + # Settings + $s = new Settings(); + # Queries $action = $_POST['action'] ?? ''; - $type = isset($_POST['type']) && in_array($_POST['type'], ['plugins', 'themes', 'repository']) ? $_POST['type'] : ''; - - # Settings - $s = new Settings(); - $dir = Utils::getRepositoryDir($s->pack_repository); + $type = isset($_POST['type']) && in_array($_POST['type'], ['plugins', 'themes', 'repository', 'repository-themes', 'repository-plugins']) ? $_POST['type'] : ''; + $repo = $s->pack_typedrepo ? (empty($_REQUEST['repo']) ? $type : (str_contains($_REQUEST['repo'], 'themes') ? 'themes' : 'plugins')) : null; + $dir = Utils::getRepositoryDir($s->pack_repository, $repo); # Modules if (!(dcCore::app()->themes instanceof dcThemes)) { @@ -268,14 +269,30 @@ class Manage extends dcNsProcess } # Settings - $s = new Settings(); - $dir = Utils::getRepositoryDir($s->pack_repository); + $s = new Settings(); + $is_configured = $is_plugins_configured = $is_themes_configured = true; - $is_configured = Utils::isConfigured( - $dir, - $s->pack_filename, - $s->secondpack_filename - ); + if ($s->pack_typedrepo) { + $dir_plugins = Utils::getRepositoryDir($s->pack_repository, 'plugins'); + $is_plugins_configured = Utils::isConfigured( + $dir_plugins, + $s->pack_filename, + $s->secondpack_filename + ); + $dir_themes = Utils::getRepositoryDir($s->pack_repository, 'themes'); + $is_themes_configured = Utils::isConfigured( + $dir_themes, + $s->pack_filename, + $s->secondpack_filename + ); + } else { + $dir = Utils::getRepositoryDir($s->pack_repository); + $is_configured = Utils::isConfigured( + $dir, + $s->pack_filename, + $s->secondpack_filename + ); + } # Display dcPage::openModule( @@ -294,7 +311,7 @@ class Manage extends dcNsProcess ]) . dcPage::notices(); - if (dcCore::app()->error->flag() || !$is_configured) { + if (dcCore::app()->error->flag() || !$is_configured || !$is_plugins_configured || !$is_themes_configured) { echo (new Div()) ->separator(' ') @@ -328,14 +345,33 @@ class Manage extends dcNsProcess __('Themes root') ); - Utils::repository( - array_merge( - Core::getPackages(dirname($dir . DIRECTORY_SEPARATOR . $s->pack_filename)), - Core::getPackages(dirname($dir . DIRECTORY_SEPARATOR . $s->secondpack_filename)) - ), - 'repository', - __('Packages repository') - ); + if ($s->pack_typedrepo) { + Utils::repository( + array_merge( + Core::getPackages(dirname($dir_themes . DIRECTORY_SEPARATOR . $s->pack_filename)), + Core::getPackages(dirname($dir_themes . DIRECTORY_SEPARATOR . $s->secondpack_filename)) + ), + 'repository-themes', + __('Themes packages repository') + ); + Utils::repository( + array_merge( + Core::getPackages(dirname($dir_plugins . DIRECTORY_SEPARATOR . $s->pack_filename)), + Core::getPackages(dirname($dir_plugins . DIRECTORY_SEPARATOR . $s->secondpack_filename)) + ), + 'repository-plugins', + __('Plugins packages repository') + ); + } else { + Utils::repository( + array_merge( + Core::getPackages(dirname($dir . DIRECTORY_SEPARATOR . $s->pack_filename)), + Core::getPackages(dirname($dir . DIRECTORY_SEPARATOR . $s->secondpack_filename)) + ), + 'repository', + __('Packages repository') + ); + } } # --BEHAVIOR-- packmanAdminTabs diff --git a/src/Settings.php b/src/Settings.php index db230d6..5d1808d 100644 --- a/src/Settings.php +++ b/src/Settings.php @@ -36,6 +36,9 @@ class Settings // Path to package repository public readonly string $pack_repository; + // Seperate themes and plugins repository + public readonly bool $pack_typedrepo; + // Extra files to exclude from package public readonly string $pack_excludefiles; @@ -55,6 +58,7 @@ class Settings $this->pack_filename = (string) ($s?->get('pack_filename') ?? '%type%-%id%'); $this->secondpack_filename = (string) ($s?->get('secondpack_filename') ?? '%type%-%id%-%version%'); $this->pack_repository = (string) ($s?->get('pack_repository') ?? ''); + $this->pack_typedrepo = (bool) ($s?->get('pack_typedrepo') ?? false); $this->pack_excludefiles = (string) ($s?->get('pack_excludefiles') ?? '*.zip,*.tar,*.tar.gz,.directory,.hg'); $this->hide_distrib = (bool) ($s?->get('hide_distrib') ?? false); } diff --git a/src/Utils.php b/src/Utils.php index fab5bea..bc2cc3e 100644 --- a/src/Utils.php +++ b/src/Utils.php @@ -50,6 +50,7 @@ class Utils public static function isConfigured(string $repo, string $file_a, string $file_b): bool { + sleep(1); if (!is_writable($repo)) { dcCore::app()->error->add( __('Path to repository is not writable.') @@ -82,15 +83,15 @@ class Utils return !(empty($path) || empty($file) || !is_writable(dirname($path . DIRECTORY_SEPARATOR . $file))); } - public static function getRepositoryDir(?string $dir): string + public static function getRepositoryDir(?string $dir, ?string $typed = null): string { - if (empty($dir)) { - try { - $dir = DC_VAR . DIRECTORY_SEPARATOR . 'packman'; - @Files::makeDir($dir, true); - } catch (Exception $e) { - $dir = ''; - } + $typed = empty($typed) ? '' : DIRECTORY_SEPARATOR . ($typed == 'themes' ? 'themes' : 'plugins'); + $dir = empty($dir) ? DC_VAR . DIRECTORY_SEPARATOR . 'packman' . $typed : $dir . $typed; + + try { + @Files::makeDir($dir, true); + } catch (Exception $e) { + $dir = ''; } return $dir; @@ -182,7 +183,7 @@ class Utils if (empty($modules)) { return null; } - if (!in_array($type, ['plugins', 'themes', 'repository'])) { + if (!in_array($type, ['plugins', 'themes', 'repository', 'repository-themes', 'repository-plugins'])) { return null; } @@ -199,13 +200,13 @@ class Utils $combo_action[sprintf(__('copy to %s directory'), __('themes'))] = 'copy_to_themes'; $combo_action[sprintf(__('move to %s directory'), __('themes'))] = 'move_to_themes'; } - if ($type != 'repository') { + if (!str_contains($type, 'repository')) { $combo_action[sprintf(__('copy to %s directory'), __('repository'))] = 'copy_to_repository'; $combo_action[sprintf(__('move to %s directory'), __('repository'))] = 'move_to_repository'; } $helpers_addon = []; - if ($type == 'repository') { + if (str_contains($type, 'repository')) { $helpers_addon[] = (new Link()) ->class('button') ->href(dcCore::app()->adminurl?->get('admin.plugin.' . My::id(), ['purge' => 1]) . '#packman-repository-' . $type) @@ -214,7 +215,7 @@ class Utils } $versions = []; - if (!empty($_REQUEST['purge']) && $type = 'repository') { + if (!empty($_REQUEST['purge']) && str_contains($type, 'repository')) { foreach ($modules as $module) { if (!isset($versions[$module->getId()]) || version_compare($module->get('version'), $versions[$module->getId()], '>')) { $versions[$module->getId()] = $module->get('version');