user shorter settings names, fix #8

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

View File

@ -16,59 +16,60 @@ namespace Dotclear\Plugin\pacKman;
/* dotclear ns */ /* dotclear ns */
use dcCore; use dcCore;
use dcNamespace;
/* php ns */ /* php ns */
use Exception; use Exception;
class Install class Install
{ {
# -- Module specs -- // Module specs
private static $mod_conf = [ private static $mod_conf = [
[ [
'packman_menu_plugins', 'menu_plugins',
'Add link to pacKman in plugins page', 'Add link to pacKman in plugins page',
false, false,
'boolean', 'boolean',
], ],
[ [
'packman_pack_nocomment', 'pack_nocomment',
'Remove comments from files', 'Remove comments from files',
false, false,
'boolean', 'boolean',
], ],
[ [
'packman_pack_overwrite', 'pack_overwrite',
'Overwrite existing package', 'Overwrite existing package',
false, false,
'boolean', 'boolean',
], ],
[ [
'packman_pack_filename', 'pack_filename',
'Name of package', 'Name of package',
'%type%-%id%', '%type%-%id%',
'string', 'string',
], ],
[ [
'packman_secondpack_filename', 'secondpack_filename',
'Name of second package', 'Name of second package',
'%type%-%id%-%version%', '%type%-%id%-%version%',
'string', 'string',
], ],
[ [
'packman_pack_repository', 'pack_repository',
'Path to package repository', 'Path to package repository',
'', '',
'string', 'string',
], ],
[ [
'packman_pack_excludefiles', 'pack_excludefiles',
'Extra files to exclude from package', 'Extra files to exclude from package',
'*.zip,*.tar,*.tar.gz,.directory,.hg', '*.zip,*.tar,*.tar.gz,.directory,.hg',
'string', 'string',
], ],
]; ];
# -- Nothing to change below -- // Nothing to change below
private static $init = false; private static $init = false;
public static function init(): bool public static function init(): bool
@ -85,7 +86,10 @@ class Install
} }
try { try {
# Set module settings // Upgrade
self::growUp();
// Set module settings
dcCore::app()->blog->settings->addNamespace(Core::id()); dcCore::app()->blog->settings->addNamespace(Core::id());
foreach (self::$mod_conf as $v) { foreach (self::$mod_conf as $v) {
dcCore::app()->blog->settings->__get(Core::id())->put( dcCore::app()->blog->settings->__get(Core::id())->put(
@ -105,4 +109,29 @@ class Install
return false; 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 # Rights
$is_writable = Utils::is_writable( $is_writable = Utils::is_writable(
$s->get('packman_pack_repository'), $s->get('pack_repository'),
$s->get('packman_pack_filename') $s->get('pack_filename')
); );
$is_editable = !empty($type) $is_editable = !empty($type)
&& !empty($_POST['modules']) && !empty($_POST['modules'])
@ -91,8 +91,8 @@ class Manage
$modules = Core::getPackages(self::$themes_path); $modules = Core::getPackages(self::$themes_path);
} else { } else {
$modules = array_merge( $modules = array_merge(
Core::getPackages(dirname($s->get('packman_pack_repository') . '/' . $s->get('packman_pack_filename'))), Core::getPackages(dirname($s->get('pack_repository') . '/' . $s->get('pack_filename'))),
Core::getPackages(dirname($s->get('packman_pack_repository') . '/' . $s->get('packman_secondpack_filename'))) Core::getPackages(dirname($s->get('pack_repository') . '/' . $s->get('secondpack_filename')))
); );
} }
@ -133,15 +133,15 @@ class Manage
$module['id'] = $id; $module['id'] = $id;
$module['type'] = $type == 'themes' ? 'theme' : 'plugin'; $module['type'] = $type == 'themes' ? 'theme' : 'plugin';
$root = (string) $s->get('packman_pack_repository'); $root = (string) $s->get('pack_repository');
$files = [ $files = [
(string) $s->get('packman_pack_filename'), (string) $s->get('pack_filename'),
(string) $s->get('packman_secondpack_filename'), (string) $s->get('secondpack_filename'),
]; ];
$nocomment = (bool) $s->get('packman_pack_nocomment'); $nocomment = (bool) $s->get('pack_nocomment');
$fixnewline = (bool) $s->get('packman_pack_fixnewline'); $fixnewline = (bool) $s->get('pack_fixnewline');
$overwrite = (bool) $s->get('packman_pack_overwrite'); $overwrite = (bool) $s->get('pack_overwrite');
$exclude = explode(',', (string) $s->get('packman_pack_excludefiles')); $exclude = explode(',', (string) $s->get('pack_excludefiles'));
# --BEHAVIOR-- packmanBeforeCreatePackage # --BEHAVIOR-- packmanBeforeCreatePackage
dcCore::app()->callBehavior('packmanBeforeCreatePackage', $module); dcCore::app()->callBehavior('packmanBeforeCreatePackage', $module);
@ -211,7 +211,7 @@ class Manage
# Copy # Copy
} elseif (strpos($action, 'copy_to_') !== false) { } elseif (strpos($action, 'copy_to_') !== false) {
$dest = (string) $s->get('packman_pack_repository'); $dest = (string) $s->get('pack_repository');
if ($action == 'copy_to_plugins') { if ($action == 'copy_to_plugins') {
$dest = self::$plugins_path; $dest = self::$plugins_path;
} elseif ($action == 'copy_to_themes') { } elseif ($action == 'copy_to_themes') {
@ -237,7 +237,7 @@ class Manage
# Move # Move
} elseif (strpos($action, 'move_to_') !== false) { } elseif (strpos($action, 'move_to_') !== false) {
$dest = (string) $s->get('packman_pack_repository'); $dest = (string) $s->get('pack_repository');
if ($action == 'move_to_plugins') { if ($action == 'move_to_plugins') {
$dest = self::$plugins_path; $dest = self::$plugins_path;
} elseif ($action == 'move_to_themes') { } elseif ($action == 'move_to_themes') {
@ -277,9 +277,9 @@ class Manage
$s = dcCore::app()->blog->settings->get(Core::id()); $s = dcCore::app()->blog->settings->get(Core::id());
$is_configured = Utils::is_configured( $is_configured = Utils::is_configured(
$s->get('packman_pack_repository'), $s->get('pack_repository'),
$s->get('packman_pack_filename'), $s->get('pack_filename'),
$s->get('packman_secondpack_filename') $s->get('secondpack_filename')
); );
# Display # Display
@ -307,8 +307,8 @@ class Manage
'</div>'; '</div>';
} else { } else {
$repo_path_modules = array_merge( $repo_path_modules = array_merge(
Core::getPackages(dirname($s->get('packman_pack_repository') . '/' . $s->get('packman_pack_filename'))), Core::getPackages(dirname($s->get('pack_repository') . '/' . $s->get('pack_filename'))),
Core::getPackages(dirname($s->get('packman_pack_repository') . '/' . $s->get('packman_secondpack_filename'))) Core::getPackages(dirname($s->get('pack_repository') . '/' . $s->get('secondpack_filename')))
); );
$plugins_path_modules = Core::getPackages(self::$plugins_path); $plugins_path_modules = Core::getPackages(self::$plugins_path);
$themes_path_modules = Core::getPackages(self::$themes_path); $themes_path_modules = Core::getPackages(self::$themes_path);