move to Dotclear 2.27

This commit is contained in:
Jean-Christian Paul Denis 2023-07-01 10:41:54 +02:00
parent a8e840eca7
commit 04b2b3c1f8
Signed by: JcDenis
GPG Key ID: 1B5B8C5B90B6C951
6 changed files with 42 additions and 76 deletions

View File

@ -14,32 +14,29 @@ declare(strict_types=1);
namespace Dotclear\Plugin\Uninstaller; namespace Dotclear\Plugin\Uninstaller;
use adminModulesList;
use dcCore; use dcCore;
use dcModuleDefine; use dcModuleDefine;
use dcNsProcess; use Dotclear\Core\Process;
use dcPage; use Dotclear\Core\Backend\ModulesList;
use dcUtils; use Dotclear\Core\Backend\Page;
use Exception; use Exception;
class Backend extends dcNsProcess class Backend extends Process
{ {
public static function init(): bool public static function init(): bool
{ {
static::$init = defined('DC_CONTEXT_ADMIN'); return self::status(My::checkContext(My::BACKEND));
return static::$init;
} }
public static function process(): bool public static function process(): bool
{ {
if (!static::$init) { if (!self::status()) {
return false; return false;
} }
dcCore::app()->addBehaviors([ dcCore::app()->addBehaviors([
// add "unsinstall" button to modules list // add "unsinstall" button to modules list
'adminModulesListGetActionsV2' => function (adminModulesList $list, dcModuleDefine $define): string { 'adminModulesListGetActionsV2' => function (ModulesList $list, dcModuleDefine $define): string {
// do not unsintall current theme // do not unsintall current theme
if ($define->get('type') == 'theme' && $define->getId() == dcCore::app()->blog?->settings->get('system')->get('theme')) { if ($define->get('type') == 'theme' && $define->getId() == dcCore::app()->blog?->settings->get('system')->get('theme')) {
return ''; return '';
@ -48,7 +45,7 @@ class Backend extends dcNsProcess
return !count(Uninstaller::instance()->loadModules([$define])->getUserActions($define->getId())) ? '' : return !count(Uninstaller::instance()->loadModules([$define])->getUserActions($define->getId())) ? '' :
sprintf( sprintf(
' <a href="%s" class="button delete uninstall_module_button">' . __('Uninstall') . '</a>', ' <a href="%s" class="button delete uninstall_module_button">' . __('Uninstall') . '</a>',
dcCore::app()->adminurl?->get('admin.plugin.' . My::id(), ['type' => $define->get('type'), 'id' => $define->getId()]) My::manageUrl(['type' => $define->get('type'), 'id' => $define->getId()])
); );
}, },
// perform direct action on theme deletion // perform direct action on theme deletion
@ -92,7 +89,7 @@ class Backend extends dcNsProcess
if ($define->get('state') != dcModuleDefine::STATE_ENABLED) { if ($define->get('state') != dcModuleDefine::STATE_ENABLED) {
if (!in_array($define->get('type'), ['plugin', 'theme']) if (!in_array($define->get('type'), ['plugin', 'theme'])
|| $define->get('type') == 'plugin' && 1 < count(dcCore::app()->plugins->getDefines(['id' => $define->getId()])) || $define->get('type') == 'plugin' && 1 < count(dcCore::app()->plugins->getDefines(['id' => $define->getId()]))
|| $define->get('type') == 'theme' && 1 < count(dcCore::app()->themes->getDefines(['id' => $define->getId()])) || $define->get('type') == 'theme' && 1 < count(dcCore::app()->themes->getDefines(['id' => $define->getId()]))
) { ) {
return; return;
} }
@ -112,7 +109,7 @@ class Backend extends dcNsProcess
// if direct actions are made, do not execute dotclear delete action. // if direct actions are made, do not execute dotclear delete action.
if (!empty($done)) { if (!empty($done)) {
array_unshift($done, __('Plugin has been successfully uninstalled.')); array_unshift($done, __('Plugin has been successfully uninstalled.'));
dcPage::addSuccessNotice(implode('<br />', $done)); Page::addSuccessNotice(implode('<br />', $done));
if ($define->get('type') == 'theme') { if ($define->get('type') == 'theme') {
dcCore::app()->adminurl?->redirect('admin.blog.theme', [], '#themes'); dcCore::app()->adminurl?->redirect('admin.blog.theme', [], '#themes');
} else { } else {
@ -131,6 +128,6 @@ class Backend extends dcNsProcess
*/ */
protected static function modulesToolsHeader(): string protected static function modulesToolsHeader(): string
{ {
return dcUtils::jsModuleLoad(My::id() . '/js/backend.js'); return My::jsLoad('backend.js');
} }
} }

View File

@ -15,24 +15,19 @@ declare(strict_types=1);
namespace Dotclear\Plugin\Uninstaller; namespace Dotclear\Plugin\Uninstaller;
use dcCore; use dcCore;
use dcNsProcess; use Dotclear\Core\Process;
use Exception; use Exception;
class Install extends dcNsProcess class Install extends Process
{ {
public static function init(): bool public static function init(): bool
{ {
if (defined('DC_CONTEXT_ADMIN')) { return self::status(My::checkContext(My::INSTALL));
$version = dcCore::app()->plugins->moduleInfo(My::id(), 'version');
static::$init = is_string($version) ? dcCore::app()->newVersion(My::id(), $version) : true;
}
return static::$init;
} }
public static function process(): bool public static function process(): bool
{ {
if (!static::$init) { if (!self::status()) {
return false; return false;
} }

View File

@ -16,9 +16,9 @@ namespace Dotclear\Plugin\Uninstaller;
use dcCore; use dcCore;
use dcModuleDefine; use dcModuleDefine;
use dcNsProcess;
use dcPage;
use dcThemes; use dcThemes;
use Dotclear\Core\Process;
use Dotclear\Core\Backend\Page;
use Dotclear\Helper\Html\Form\{ use Dotclear\Helper\Html\Form\{
Checkbox, Checkbox,
Div, Div,
@ -32,19 +32,16 @@ use Dotclear\Helper\Html\Form\{
}; };
use Exception; use Exception;
class Manage extends dcNsProcess class Manage extends Process
{ {
public static function init(): bool public static function init(): bool
{ {
static::$init = defined('DC_CONTEXT_ADMIN') return self::status(My::checkContext(My::MANAGE));
&& dcCore::app()->auth?->isSuperAdmin();
return static::$init;
} }
public static function process(): bool public static function process(): bool
{ {
if (!static::$init) { if (!self::status()) {
return false; return false;
} }
@ -96,9 +93,9 @@ class Manage extends dcNsProcess
// list success actions // list success actions
if (!empty($done)) { if (!empty($done)) {
array_unshift($done, __('Uninstall action successfuly excecuted')); array_unshift($done, __('Uninstall action successfuly excecuted'));
dcPage::addSuccessNotice(implode('<br />', $done)); Page::addSuccessNotice(implode('<br />', $done));
} else { } else {
dcPage::addWarningNotice(__('No uninstall action done')); Page::addWarningNotice(__('No uninstall action done'));
} }
self::doRedirect(); self::doRedirect();
} catch (Exception $e) { } catch (Exception $e) {
@ -110,7 +107,7 @@ class Manage extends dcNsProcess
public static function render(): void public static function render(): void
{ {
if (!static::$init) { if (!self::status()) {
return; return;
} }
@ -124,21 +121,21 @@ class Manage extends dcNsProcess
$fields[] = (new Text('', $uninstaller->render($define->getId()))); $fields[] = (new Text('', $uninstaller->render($define->getId())));
} }
dcPage::openModule( Page::openModule(
My::name(), My::name(),
dcPage::jsJson('uninstaller', ['confirm_uninstall' => __('Are you sure you perform these ations?')]) . Page::jsJson('uninstaller', ['confirm_uninstall' => __('Are you sure you perform these ations?')]) .
dcPage::jsModuleLoad(My::id() . '/js/manage.js') . My::jsLoad('manage.js') .
# --BEHAVIOR-- UninstallerHeader # --BEHAVIOR-- UninstallerHeader
dcCore::app()->callBehavior('UninstallerHeader') dcCore::app()->callBehavior('UninstallerHeader')
); );
echo echo
dcPage::breadcrumb([ Page::breadcrumb([
__('System') => '', __('System') => '',
My::name() => '', My::name() => '',
]) . ]) .
dcPage::notices(); Page::notices();
// user actions form fields // user actions form fields
foreach ($uninstaller->getUserActions($define->getId()) as $cleaner => $stack) { foreach ($uninstaller->getUserActions($define->getId()) as $cleaner => $stack) {
@ -166,7 +163,7 @@ class Manage extends dcNsProcess
(new Form('uninstall-form'))->method('post')->action(dcCore::app()->adminurl?->get('admin.plugin.' . My::id()))->fields($fields), (new Form('uninstall-form'))->method('post')->action(dcCore::app()->adminurl?->get('admin.plugin.' . My::id()))->fields($fields),
])->render(); ])->render();
dcPage::closeModule(); Page::closeModule();
} }
private static function getType(): string private static function getType(): string

View File

@ -15,35 +15,15 @@ declare(strict_types=1);
namespace Dotclear\Plugin\Uninstaller; namespace Dotclear\Plugin\Uninstaller;
use dcCore; use dcCore;
use Dotclear\Module\MyPlugin;
/** class My extends MyPlugin
* This module definitions.
*/
class My
{ {
/** protected static function checkCustomContext(int $context): ?bool
* This module id.
*/
public static function id(): string
{ {
return basename(dirname(__DIR__)); // check super admin except install that follows MyPlugin check
} return $context === My::INSTALL ? null :
defined('DC_CONTEXT_ADMIN')
/** && dcCore::app()->auth->isSuperAdmin();
* This module name.
*/
public static function name(): string
{
$name = dcCore::app()->plugins->moduleInfo(self::id(), 'name');
return __(is_string($name) ? $name : self::id());
}
/**
* This module path.
*/
public static function path(): string
{
return dirname(__DIR__);
} }
} }

View File

@ -15,21 +15,18 @@ declare(strict_types=1);
namespace Dotclear\Plugin\Uninstaller; namespace Dotclear\Plugin\Uninstaller;
use dcCore; use dcCore;
use dcNsProcess; use Dotclear\Core\Process;
class Prepend extends dcNsProcess class Prepend extends Process
{ {
public static function init(): bool public static function init(): bool
{ {
static::$init = defined('DC_CONTEXT_ADMIN') return self::status(My::checkContext(My::BACKEND));
&& dcCore::app()->auth?->isSuperAdmin();
return static::$init;
} }
public static function process(): bool public static function process(): bool
{ {
if (!static::$init) { if (!self::status()) {
return false; return false;
} }

View File

@ -15,7 +15,7 @@ declare(strict_types=1);
namespace Dotclear\Plugin\Uninstaller; namespace Dotclear\Plugin\Uninstaller;
use dcModuleDefine; use dcModuleDefine;
use dcNsProcess; use Dotclear\Core\Process;
use Dotclear\Helper\Text; use Dotclear\Helper\Text;
use Exception; use Exception;
@ -95,7 +95,7 @@ class Uninstaller
continue; continue;
} }
$class = $module->get('namespace') . '\\' . self::UNINSTALL_CLASS_NAME; $class = $module->get('namespace') . '\\' . self::UNINSTALL_CLASS_NAME;
if ($module->getId() != My::id() && is_a($class, dcNsProcess::class, true)) { if ($module->getId() != My::id() && is_a($class, Process::class, true)) {
$this->modules[$module->getId()] = $this->module = $module; $this->modules[$module->getId()] = $this->module = $module;
// check class prerequiretics // check class prerequiretics
if ($class::init()) { if ($class::init()) {