check config

This commit is contained in:
Jean-Christian Denis 2023-03-19 10:47:24 +01:00
parent 7054d96d9e
commit 6c0ffc1190
Signed by: JcDenis
GPG key ID: 1B5B8C5B90B6C951
3 changed files with 94 additions and 11 deletions

View file

@ -25,7 +25,8 @@ use Dotclear\Helper\Html\Form\{
Label, Label,
Legend, Legend,
Note, Note,
Para Para,
Text
}; };
class Config extends dcNsProcess class Config extends dcNsProcess
@ -85,6 +86,22 @@ class Config extends dcNsProcess
# -- Get settings -- # -- Get settings --
$s = new Settings(); $s = new Settings();
# -- Check config --
$img = '<img alt="%1$s" title="%1$s" src="images/%2$s" /> ';
$img_on = sprintf($img, __('writable'), 'check-on.png');
$img_off = sprintf($img, __('not writable'), 'check-off.png');
$check_repo = Utils::is_writable(Utils::getRepositoryDir($s->pack_repository), '_.zip') ? $img_on : $img_off;
$check_first = !empty($s->pack_filename) && Utils::is_writable(Utils::getRepositoryDir($repo), $s->pack_filename) ? $img_on : $img_off;
$check_second = !empty($s->secondpack_filename) && Utils::is_writable(Utils::getRepositoryDir($repo), $s->secondpack_filename) ? $img_on : $img_off;
$is_configured = Utils::is_configured(
Utils::getRepositoryDir($s->pack_repository),
$s->pack_filename,
$s->secondpack_filename
);
$check_conf = $is_configured ? $img_on . sprintf(__('%s is well configured.'), My::name()) : $img_off . sprintf(__('%s is not well configured.'), My::name());
# -- Display form -- # -- Display form --
echo echo
(new Div())->items([ (new Div())->items([
@ -98,7 +115,7 @@ class Config extends dcNsProcess
(new Fieldset())->class('fieldset')->legend((new Legend(__('Root'))))->fields([ (new Fieldset())->class('fieldset')->legend((new Legend(__('Root'))))->fields([
// pack_repository // pack_repository
(new Para())->items([ (new Para())->items([
(new Label(__('Path to repository:')))->for('pack_repository'), (new Label($check_repo . __('Path to repository:')))->for('pack_repository'),
(new Input('pack_repository'))->class('maximal')->size(65)->maxlenght(255)->value($s->pack_repository), (new Input('pack_repository'))->class('maximal')->size(65)->maxlenght(255)->value($s->pack_repository),
]), ]),
(new Note())->class('form-note')->text( (new Note())->class('form-note')->text(
@ -112,13 +129,13 @@ class Config extends dcNsProcess
(new Fieldset())->class('fieldset')->legend((new Legend(__('Files'))))->fields([ (new Fieldset())->class('fieldset')->legend((new Legend(__('Files'))))->fields([
// pack_filename // pack_filename
(new Para())->items([ (new Para())->items([
(new Label(__('Name of exported package:')))->for('pack_filename'), (new Label($check_first . __('Name of exported package:')))->for('pack_filename'),
(new Input('pack_filename'))->class('maximal')->size(65)->maxlenght(255)->value($s->pack_filename), (new Input('pack_filename'))->class('maximal')->size(65)->maxlenght(255)->value($s->pack_filename),
]), ]),
(new Note())->text(sprintf(__('Preconization: %s'), '%type%-%id%'))->class('form-note'), (new Note())->text(sprintf(__('Preconization: %s'), '%type%-%id%'))->class('form-note'),
// secondpack_filename // secondpack_filename
(new Para())->items([ (new Para())->items([
(new Label(__('Name of second exported package:')))->for('secondpack_filename'), (new Label($check_second . __('Name of second exported package:')))->for('secondpack_filename'),
(new Input('secondpack_filename'))->class('maximal')->size(65)->maxlenght(255)->value($s->secondpack_filename), (new Input('secondpack_filename'))->class('maximal')->size(65)->maxlenght(255)->value($s->secondpack_filename),
]), ]),
(new Note())->text(sprintf(__('Preconization: %s'), '%type%-%id%-%version%'))->class('form-note'), (new Note())->text(sprintf(__('Preconization: %s'), '%type%-%id%-%version%'))->class('form-note'),
@ -145,7 +162,11 @@ class Config extends dcNsProcess
(new Checkbox('pack_fixnewline', $s->pack_fixnewline))->value(1), (new Checkbox('pack_fixnewline', $s->pack_fixnewline))->value(1),
(new Label(__('Fix newline style from files content'), Label::OUTSIDE_LABEL_AFTER))->for('pack_fixnewline')->class('classic'), (new Label(__('Fix newline style from files content'), Label::OUTSIDE_LABEL_AFTER))->for('pack_fixnewline')->class('classic'),
]), ]),
]),
(new Fieldset())->class('fieldset')->legend((new Legend(__('Capability'))))->fields([
(new Text('p', $img_on . sprintf(__('Use "%s" class to zip modules.'), Utils::getZipCapability()))),
(new Text('p', $img_on . sprintf(__('Use "%s" class to unzip modules.'), Utils::getUnzipCapability()))),
(new Text('p', $check_conf)),
]), ]),
])->render(); ])->render();
} }

View file

@ -213,6 +213,7 @@ class Core
$file = str_replace( $file = str_replace(
[ [
'\\',
'%type%', '%type%',
'%id%', '%id%',
'%version%', '%version%',
@ -220,6 +221,7 @@ class Core
'%time%', '%time%',
], ],
[ [
'/',
$info['type'], $info['type'],
$info['id'], $info['id'],
$info['version'], $info['version'],
@ -233,12 +235,12 @@ class Core
$parts[$i] = files::tidyFileName($part); $parts[$i] = files::tidyFileName($part);
} }
return implode('/', $parts) . '.zip'; return implode(DIRECTORY_SEPARATOR, $parts) . '.zip';
} }
private static function getOverwrite(bool $overwrite, string $root, string$file): ?string private static function getOverwrite(bool $overwrite, string $root, string$file): ?string
{ {
$path = $root . '/' . $file; $path = $root . DIRECTORY_SEPARATOR . $file;
if (file_exists($path) && !$overwrite) { if (file_exists($path) && !$overwrite) {
// don't break loop // don't break loop
//throw new Exception('File already exists'); //throw new Exception('File already exists');
@ -250,7 +252,7 @@ class Core
private static function getCache(): string private static function getCache(): string
{ {
$c = DC_TPL_CACHE . '/packman'; $c = DC_TPL_CACHE . DIRECTORY_SEPARATOR . 'packman';
if (!file_exists($c)) { if (!file_exists($c)) {
@files::makeDir($c); @files::makeDir($c);
} }

View file

@ -16,6 +16,8 @@ namespace Dotclear\Plugin\pacKman;
/* dotclear ns */ /* dotclear ns */
use dcCore; use dcCore;
use Dotclear\Helper\File\Zip\Unzip;
use Dotclear\Helper\File\Zip\Zip;
/* clearbricks ns */ /* clearbricks ns */
use dt; use dt;
@ -58,13 +60,13 @@ class Utils
); );
} }
if (!is_writable(dirname($repo . '/' . $file_a))) { if (!is_writable(dirname($repo . DIRECTORY_SEPARATOR . $file_a))) {
dcCore::app()->error->add( dcCore::app()->error->add(
__('Path to first export package is not writable.') __('Path to first export package is not writable.')
); );
} }
if (!empty($file_b) && !is_writable(dirname($repo . '/' . $file_b))) { if (!empty($file_b) && !is_writable(dirname($repo . DIRECTORY_SEPARATOR . $file_b))) {
dcCore::app()->error->add( dcCore::app()->error->add(
__('Path to second export package is not writable.') __('Path to second export package is not writable.')
); );
@ -75,7 +77,65 @@ class Utils
public static function is_writable(string $path, string $file): bool public static function is_writable(string $path, string $file): bool
{ {
return !(empty($path) || empty($file) || !is_writable(dirname($path . '/' . $file))); return !(empty($path) || empty($file) || !is_writable(dirname($path . DIRECTORY_SEPARATOR . $file)));
}
public static function getUnzipCapability()
{
switch (Unzip::USE_DEFAULT) {
case Unzip::USE_PHARDATA:
if (class_exists('PharData')) {
return 'PharData';
}
if (class_exists('ZipArchive')) {
return 'ZipArchive';
}
break;
case Unzip::USE_ZIPARCHIVE:
if (class_exists('ZipArchive')) {
return 'ZipArchive';
}
if (class_exists('PharData')) {
return 'PharData';
}
break;
case self::USE_LEGACY:
break;
}
return 'Legacy';
}
public static function getZipCapability()
{
switch (Zip::USE_DEFAULT) {
case Zip::USE_PHARDATA:
if (class_exists('PharData')) {
return 'PharData';
}
if (class_exists('ZipArchive')) {
return 'ZipArchive';
}
break;
case Zip::USE_ZIPARCHIVE:
if (class_exists('ZipArchive')) {
return 'ZipArchive';
}
if (class_exists('PharData')) {
return 'PharData';
}
break;
case self::USE_LEGACY:
break;
}
return 'Legacy';
} }
public static function getRepositoryDir(?string $dir): string public static function getRepositoryDir(?string $dir): string