user shorter settings names, fix #8

This commit is contained in:
Jean-Christian Denis 2022-12-19 12:04:34 +01:00
parent 539fd61998
commit 8dcc092f4b
Signed by: JcDenis
GPG key ID: 1B5B8C5B90B6C951
3 changed files with 88 additions and 59 deletions

View file

@ -52,29 +52,29 @@ class Config
# -- Set settings --
try {
$packman_pack_nocomment = !empty($_POST['packman_pack_nocomment']);
$packman_pack_fixnewline = !empty($_POST['packman_pack_fixnewline']);
$packman_pack_overwrite = !empty($_POST['packman_pack_overwrite']);
$packman_pack_filename = (string) $_POST['packman_pack_filename'];
$packman_secondpack_filename = (string) $_POST['packman_secondpack_filename'];
$packman_pack_repository = (string) path::real($_POST['packman_pack_repository'], false);
$packman_pack_excludefiles = (string) $_POST['packman_pack_excludefiles'];
$pack_nocomment = !empty($_POST['pack_nocomment']);
$pack_fixnewline = !empty($_POST['pack_fixnewline']);
$pack_overwrite = !empty($_POST['pack_overwrite']);
$pack_filename = (string) $_POST['pack_filename'];
$secondpack_filename = (string) $_POST['secondpack_filename'];
$pack_repository = (string) path::real($_POST['pack_repository'], false);
$pack_excludefiles = (string) $_POST['pack_excludefiles'];
$check = Utils::is_configured(
$packman_pack_repository,
$packman_pack_filename,
$packman_secondpack_filename
$pack_repository,
$pack_filename,
$secondpack_filename
);
if ($check) {
$s = dcCore::app()->blog->settings->__get(Core::id());
$s->put('packman_pack_nocomment', $packman_pack_nocomment);
$s->put('packman_pack_fixnewline', $packman_pack_fixnewline);
$s->put('packman_pack_overwrite', $packman_pack_overwrite);
$s->put('packman_pack_filename', $packman_pack_filename);
$s->put('packman_secondpack_filename', $packman_secondpack_filename);
$s->put('packman_pack_repository', $packman_pack_repository);
$s->put('packman_pack_excludefiles', $packman_pack_excludefiles);
$s->put('pack_nocomment', $pack_nocomment);
$s->put('pack_fixnewline', $pack_fixnewline);
$s->put('pack_overwrite', $pack_overwrite);
$s->put('pack_filename', $pack_filename);
$s->put('secondpack_filename', $secondpack_filename);
$s->put('pack_repository', $pack_repository);
$s->put('pack_excludefiles', $pack_excludefiles);
dcPage::addSuccessNotice(
__('Configuration has been successfully updated.')
@ -103,8 +103,8 @@ class Config
<div class="fieldset">
<h4>' . __('Root') . '</h4>
<p><label for="packman_pack_repository">' . __('Path to repository:') . ' ' .
form::field('packman_pack_repository', 65, 255, (string) $s->get('packman_pack_repository'), 'maximal') .
<p><label for="pack_repository">' . __('Path to repository:') . ' ' .
form::field('pack_repository', 65, 255, (string) $s->get('pack_repository'), 'maximal') .
'</label></p>' .
'<p class="form-note">' . sprintf(
__('Preconization: %s'),
@ -116,18 +116,18 @@ class Config
<div class="fieldset">
<h4>' . __('Files') . '</h4>
<p><label for="packman_pack_filename">' . __('Name of exported package:') . ' ' .
form::field('packman_pack_filename', 65, 255, (string) $s->get('packman_pack_filename'), 'maximal') .
<p><label for="pack_filename">' . __('Name of exported package:') . ' ' .
form::field('pack_filename', 65, 255, (string) $s->get('pack_filename'), 'maximal') .
'</label></p>
<p class="form-note">' . sprintf(__('Preconization: %s'), '%type%-%id%') . '</p>
<p><label for="packman_secondpack_filename">' . __('Name of second exported package:') . ' ' .
form::field('packman_secondpack_filename', 65, 255, (string) $s->get('packman_secondpack_filename'), 'maximal') .
<p><label for="secondpack_filename">' . __('Name of second exported package:') . ' ' .
form::field('secondpack_filename', 65, 255, (string) $s->get('secondpack_filename'), 'maximal') .
'</label></p>
<p class="form-note">' . sprintf(__('Preconization: %s'), '%type%-%id%-%version%') . '</p>
<p><label class="classic" for="packman_pack_overwrite">' .
form::checkbox('packman_pack_overwrite', 1, (bool) $s->get('packman_pack_overwrite')) . ' ' .
<p><label class="classic" for="pack_overwrite">' .
form::checkbox('pack_overwrite', 1, (bool) $s->get('pack_overwrite')) . ' ' .
__('Overwrite existing package') . '</label></p>
</div>
@ -135,17 +135,17 @@ class Config
<div class="fieldset">
<h4>' . __('Content') . '</h4>
<p><label for="packman_pack_excludefiles">' . __('Extra files to exclude from package:') . ' ' .
form::field('packman_pack_excludefiles', 65, 255, (string) $s->get('packman_pack_excludefiles'), 'maximal') .
<p><label for="pack_excludefiles">' . __('Extra files to exclude from package:') . ' ' .
form::field('pack_excludefiles', 65, 255, (string) $s->get('pack_excludefiles'), 'maximal') .
'</label></p>
<p class="form-note">' . sprintf(__('Preconization: %s'), '*.zip,*.tar,*.tar.gz') . '</p>
<p><label class="classic" for="packman_pack_nocomment">' .
form::checkbox('packman_pack_nocomment', 1, (bool) $s->get('packman_pack_nocomment')) . ' ' .
<p><label class="classic" for="pack_nocomment">' .
form::checkbox('pack_nocomment', 1, (bool) $s->get('pack_nocomment')) . ' ' .
__('Remove comments from files') . '</label></p>
<p><label class="classic" for="packman_pack_fixnewline">' .
form::checkbox('packman_pack_fixnewline', 1, (bool) $s->get('packman_pack_fixnewline')) . ' ' .
<p><label class="classic" for="pack_fixnewline">' .
form::checkbox('pack_fixnewline', 1, (bool) $s->get('pack_fixnewline')) . ' ' .
__('Fix newline style from files content') . '</label></p>
</div>';

View file

@ -16,59 +16,60 @@ namespace Dotclear\Plugin\pacKman;
/* dotclear ns */
use dcCore;
use dcNamespace;
/* php ns */
use Exception;
class Install
{
# -- Module specs --
// Module specs
private static $mod_conf = [
[
'packman_menu_plugins',
'menu_plugins',
'Add link to pacKman in plugins page',
false,
'boolean',
],
[
'packman_pack_nocomment',
'pack_nocomment',
'Remove comments from files',
false,
'boolean',
],
[
'packman_pack_overwrite',
'pack_overwrite',
'Overwrite existing package',
false,
'boolean',
],
[
'packman_pack_filename',
'pack_filename',
'Name of package',
'%type%-%id%',
'string',
],
[
'packman_secondpack_filename',
'secondpack_filename',
'Name of second package',
'%type%-%id%-%version%',
'string',
],
[
'packman_pack_repository',
'pack_repository',
'Path to package repository',
'',
'string',
],
[
'packman_pack_excludefiles',
'pack_excludefiles',
'Extra files to exclude from package',
'*.zip,*.tar,*.tar.gz,.directory,.hg',
'string',
],
];
# -- Nothing to change below --
// Nothing to change below
private static $init = false;
public static function init(): bool
@ -85,7 +86,10 @@ class Install
}
try {
# Set module settings
// Upgrade
self::growUp();
// Set module settings
dcCore::app()->blog->settings->addNamespace(Core::id());
foreach (self::$mod_conf as $v) {
dcCore::app()->blog->settings->__get(Core::id())->put(
@ -105,4 +109,29 @@ class Install
return false;
}
}
public static function growUp()
{
$current = dcCore::app()->getVersion(Core::id());
// Update settings id, ns
if ($current && version_compare($current, '2022.12.19.1', '<=')) {
$record = dcCore::app()->con->select(
'SELECT * FROM ' . dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME . ' ' .
"WHERE setting_ns = 'pacKman' "
);
while ($record->fetch()) {
if (preg_match('/^packman_(.*?)$/', $record->setting_id, $match)) {
$cur = dcCore::app()->con->openCursor(dcCore::app()->prefix . dcNamespace::NS_TABLE_NAME);
$cur->setting_id = $match[1];
$cur->setting_ns = Core::id();
$cur->update(
"WHERE setting_id = '" . $record->setting_id . "' and setting_ns = 'pacKman' " .
'AND blog_id ' . (null === $record->blog_id ? 'IS NULL ' : ("= '" . dcCore::app()->con->escape($record->blog_id) . "' "))
);
}
}
}
}
}

View file

@ -73,8 +73,8 @@ class Manage
# Rights
$is_writable = Utils::is_writable(
$s->get('packman_pack_repository'),
$s->get('packman_pack_filename')
$s->get('pack_repository'),
$s->get('pack_filename')
);
$is_editable = !empty($type)
&& !empty($_POST['modules'])
@ -91,8 +91,8 @@ class Manage
$modules = Core::getPackages(self::$themes_path);
} else {
$modules = array_merge(
Core::getPackages(dirname($s->get('packman_pack_repository') . '/' . $s->get('packman_pack_filename'))),
Core::getPackages(dirname($s->get('packman_pack_repository') . '/' . $s->get('packman_secondpack_filename')))
Core::getPackages(dirname($s->get('pack_repository') . '/' . $s->get('pack_filename'))),
Core::getPackages(dirname($s->get('pack_repository') . '/' . $s->get('secondpack_filename')))
);
}
@ -133,15 +133,15 @@ class Manage
$module['id'] = $id;
$module['type'] = $type == 'themes' ? 'theme' : 'plugin';
$root = (string) $s->get('packman_pack_repository');
$root = (string) $s->get('pack_repository');
$files = [
(string) $s->get('packman_pack_filename'),
(string) $s->get('packman_secondpack_filename'),
(string) $s->get('pack_filename'),
(string) $s->get('secondpack_filename'),
];
$nocomment = (bool) $s->get('packman_pack_nocomment');
$fixnewline = (bool) $s->get('packman_pack_fixnewline');
$overwrite = (bool) $s->get('packman_pack_overwrite');
$exclude = explode(',', (string) $s->get('packman_pack_excludefiles'));
$nocomment = (bool) $s->get('pack_nocomment');
$fixnewline = (bool) $s->get('pack_fixnewline');
$overwrite = (bool) $s->get('pack_overwrite');
$exclude = explode(',', (string) $s->get('pack_excludefiles'));
# --BEHAVIOR-- packmanBeforeCreatePackage
dcCore::app()->callBehavior('packmanBeforeCreatePackage', $module);
@ -211,7 +211,7 @@ class Manage
# Copy
} elseif (strpos($action, 'copy_to_') !== false) {
$dest = (string) $s->get('packman_pack_repository');
$dest = (string) $s->get('pack_repository');
if ($action == 'copy_to_plugins') {
$dest = self::$plugins_path;
} elseif ($action == 'copy_to_themes') {
@ -237,7 +237,7 @@ class Manage
# Move
} elseif (strpos($action, 'move_to_') !== false) {
$dest = (string) $s->get('packman_pack_repository');
$dest = (string) $s->get('pack_repository');
if ($action == 'move_to_plugins') {
$dest = self::$plugins_path;
} elseif ($action == 'move_to_themes') {
@ -277,9 +277,9 @@ class Manage
$s = dcCore::app()->blog->settings->get(Core::id());
$is_configured = Utils::is_configured(
$s->get('packman_pack_repository'),
$s->get('packman_pack_filename'),
$s->get('packman_secondpack_filename')
$s->get('pack_repository'),
$s->get('pack_filename'),
$s->get('secondpack_filename')
);
# Display
@ -307,8 +307,8 @@ class Manage
'</div>';
} else {
$repo_path_modules = array_merge(
Core::getPackages(dirname($s->get('packman_pack_repository') . '/' . $s->get('packman_pack_filename'))),
Core::getPackages(dirname($s->get('packman_pack_repository') . '/' . $s->get('packman_secondpack_filename')))
Core::getPackages(dirname($s->get('pack_repository') . '/' . $s->get('pack_filename'))),
Core::getPackages(dirname($s->get('pack_repository') . '/' . $s->get('secondpack_filename')))
);
$plugins_path_modules = Core::getPackages(self::$plugins_path);
$themes_path_modules = Core::getPackages(self::$themes_path);