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;
use adminModulesList;
use dcCore;
use dcModuleDefine;
use dcNsProcess;
use dcPage;
use dcUtils;
use Dotclear\Core\Process;
use Dotclear\Core\Backend\ModulesList;
use Dotclear\Core\Backend\Page;
use Exception;
class Backend extends dcNsProcess
class Backend extends Process
{
public static function init(): bool
{
static::$init = defined('DC_CONTEXT_ADMIN');
return static::$init;
return self::status(My::checkContext(My::BACKEND));
}
public static function process(): bool
{
if (!static::$init) {
if (!self::status()) {
return false;
}
dcCore::app()->addBehaviors([
// 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
if ($define->get('type') == 'theme' && $define->getId() == dcCore::app()->blog?->settings->get('system')->get('theme')) {
return '';
@ -48,7 +45,7 @@ class Backend extends dcNsProcess
return !count(Uninstaller::instance()->loadModules([$define])->getUserActions($define->getId())) ? '' :
sprintf(
' <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
@ -92,7 +89,7 @@ class Backend extends dcNsProcess
if ($define->get('state') != dcModuleDefine::STATE_ENABLED) {
if (!in_array($define->get('type'), ['plugin', 'theme'])
|| $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;
}
@ -112,7 +109,7 @@ class Backend extends dcNsProcess
// if direct actions are made, do not execute dotclear delete action.
if (!empty($done)) {
array_unshift($done, __('Plugin has been successfully uninstalled.'));
dcPage::addSuccessNotice(implode('<br />', $done));
Page::addSuccessNotice(implode('<br />', $done));
if ($define->get('type') == 'theme') {
dcCore::app()->adminurl?->redirect('admin.blog.theme', [], '#themes');
} else {
@ -131,6 +128,6 @@ class Backend extends dcNsProcess
*/
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;
use dcCore;
use dcNsProcess;
use Dotclear\Core\Process;
use Exception;
class Install extends dcNsProcess
class Install extends Process
{
public static function init(): bool
{
if (defined('DC_CONTEXT_ADMIN')) {
$version = dcCore::app()->plugins->moduleInfo(My::id(), 'version');
static::$init = is_string($version) ? dcCore::app()->newVersion(My::id(), $version) : true;
}
return static::$init;
return self::status(My::checkContext(My::INSTALL));
}
public static function process(): bool
{
if (!static::$init) {
if (!self::status()) {
return false;
}

View File

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

View File

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

View File

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

View File

@ -15,7 +15,7 @@ declare(strict_types=1);
namespace Dotclear\Plugin\Uninstaller;
use dcModuleDefine;
use dcNsProcess;
use Dotclear\Core\Process;
use Dotclear\Helper\Text;
use Exception;
@ -95,7 +95,7 @@ class Uninstaller
continue;
}
$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;
// check class prerequiretics
if ($class::init()) {