add option to separate themes and plugins repository

This commit is contained in:
Jean-Christian Denis 2023-05-30 00:24:13 +02:00
parent 0107bbb72f
commit 788cf5b16a
Signed by: JcDenis
GPG key ID: 1B5B8C5B90B6C951
5 changed files with 97 additions and 35 deletions

View file

@ -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"

View file

@ -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

View file

@ -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

View file

@ -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);
}

View file

@ -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');