use dcModuleDefine rather than properties array
This commit is contained in:
parent
e794fc1e70
commit
1877d40fce
11 changed files with 72 additions and 99 deletions
|
@ -16,6 +16,7 @@ namespace Dotclear\Plugin\improve;
|
|||
|
||||
/* dotclear */
|
||||
use dcCore;
|
||||
use dcModuleDefine;
|
||||
use dcPage;
|
||||
|
||||
/* clearbricks */
|
||||
|
@ -36,8 +37,8 @@ use ArrayObject;
|
|||
*/
|
||||
abstract class Action
|
||||
{
|
||||
/** @var array<string,mixed> Current module */
|
||||
protected $module = [];
|
||||
/** @var dcModuleDefine Current module */
|
||||
protected $module;
|
||||
|
||||
/** @var string Current full path */
|
||||
protected $path_full = '';
|
||||
|
@ -84,6 +85,7 @@ abstract class Action
|
|||
final public function __construct()
|
||||
{
|
||||
$this->class_name = str_replace(Utils::getActionsNS(), '', get_called_class());
|
||||
$this->module = new dcModuleDefine('undefined');
|
||||
|
||||
$settings = dcCore::app()->blog->settings->get(My::id())->get('settings_' . $this->class_name);
|
||||
if (null != $settings) {
|
||||
|
@ -291,9 +293,9 @@ abstract class Action
|
|||
*
|
||||
* @see Improve::sanitizeModule()
|
||||
*
|
||||
* @param array<string> $module Full array of module definitons
|
||||
* @param dcModuleDefine $module Module definitons
|
||||
*/
|
||||
final public function setModule(array $module): bool
|
||||
final public function setModule(dcModuleDefine $module): bool
|
||||
{
|
||||
$this->module = $module;
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ namespace Dotclear\Plugin\improve;
|
|||
/* dotclear */
|
||||
use dcCore;
|
||||
use dcLog;
|
||||
use dcModuleDefine;
|
||||
|
||||
/* clearbricks */
|
||||
use path;
|
||||
|
@ -190,10 +191,9 @@ class Core
|
|||
return $this->disabled;
|
||||
}
|
||||
|
||||
public function fixModule(string $type, string $id, array $properties, array $actions): float
|
||||
public function fixModule(dcModuleDefine $module, array $actions): float
|
||||
{
|
||||
$time_start = microtime(true);
|
||||
$module = Module::clean($type, $id, $properties);
|
||||
|
||||
$workers = [];
|
||||
foreach ($actions as $action) {
|
||||
|
@ -210,10 +210,10 @@ class Core
|
|||
// action: open module
|
||||
$action->openModule();
|
||||
}
|
||||
if (!isset($module['sroot']) || !$module['root_writable'] || !is_writable($module['sroot'])) {
|
||||
if (!$module->get('root_writable') || !is_writable($module->get('root'))) {
|
||||
throw new Exception(__('Module path is not writable'));
|
||||
}
|
||||
$tree = self::getModuleFiles($module['sroot']);
|
||||
$tree = self::getModuleFiles($module->get('root'));
|
||||
foreach ($tree as $file) {
|
||||
if (!file_exists($file[0])) {
|
||||
continue;
|
||||
|
|
|
@ -54,13 +54,6 @@ class Manage extends dcNsProcess
|
|||
&& dcCore::app()->auth->isSuperAdmin()
|
||||
&& My::phpCompliant();
|
||||
|
||||
if (static::$init) {
|
||||
self::$improve = new Core();
|
||||
self::$type = self::getType();
|
||||
self::$module = self::getModule();
|
||||
self::$action = self::getAction();
|
||||
}
|
||||
|
||||
return static::$init;
|
||||
}
|
||||
|
||||
|
@ -125,51 +118,34 @@ class Manage extends dcNsProcess
|
|||
|
||||
private static function comboModules(): array
|
||||
{
|
||||
$allow_distrib = (bool) dcCore::app()->blog->settings->get(My::id())->get('allow_distrib');
|
||||
$official = [
|
||||
'plugin' => explode(',', DC_DISTRIB_PLUGINS),
|
||||
'theme' => explode(',', DC_DISTRIB_THEMES),
|
||||
];
|
||||
|
||||
if (!(dcCore::app()->themes instanceof dcThemes)) {
|
||||
dcCore::app()->themes = new dcThemes();
|
||||
dcCore::app()->themes->loadModules(dcCore::app()->blog->themes_path, null);
|
||||
}
|
||||
|
||||
$combo_modules = [];
|
||||
$modules = self::getModules(self::$type == 'plugin' ? 'plugins' : 'themes');
|
||||
foreach ($modules as $id => $m) {
|
||||
if (!$m['root_writable'] || !$allow_distrib && in_array($id, $official[self::$type])) {
|
||||
foreach (self::$type == 'plugin' ? dcCore::app()->plugins->getDefines() : dcCore::app()->themes->getDefines() as $module) {
|
||||
if (!$module->get('root_writable') || !dcCore::app()->blog->settings->get(My::id())->get('allow_distrib') && $module->get('distributed')) {
|
||||
continue;
|
||||
}
|
||||
$combo_modules[sprintf(__('%s (%s)'), __($m['name']), $id)] = $id;
|
||||
$combo_modules[sprintf(__('%s (%s)'), __($module->get('name')), $module->getId())] = $module->getId();
|
||||
}
|
||||
dcUtils::lexicalKeySort($combo_modules);
|
||||
|
||||
return array_merge([__('Select a module') => '-'], $combo_modules);
|
||||
}
|
||||
|
||||
public static function getModules(string $type, ?string $id = null): ?array
|
||||
{
|
||||
$type = $type == 'themes' ? 'themes' : 'plugins';
|
||||
|
||||
$modules = array_merge(dcCore::app()->{$type}->getDisabledModules(), dcCore::app()->{$type}->getModules());
|
||||
|
||||
if (empty($id)) {
|
||||
return $modules;
|
||||
} elseif (array_key_exists($id, $modules)) {
|
||||
return $modules[$id];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public static function process(): bool
|
||||
{
|
||||
if (!static::$init) {
|
||||
return false;
|
||||
}
|
||||
|
||||
self::$improve = new Core();
|
||||
self::$type = self::getType();
|
||||
self::$module = self::getModule();
|
||||
self::$action = self::getAction();
|
||||
|
||||
$log_id = '';
|
||||
$done = self::setPreferences();
|
||||
|
||||
|
@ -181,9 +157,7 @@ class Manage extends dcNsProcess
|
|||
} else {
|
||||
try {
|
||||
$time = self::$improve->fixModule(
|
||||
self::$type,
|
||||
self::$module,
|
||||
self::getModules(self::$type == 'plugin' ? 'plugins' : 'themes', self::$module),
|
||||
self::$type == 'plugin' ? dcCore::app()->plugins->getDefine(self::$module) : dcCore::app()->themes->getDefine(self::$module),
|
||||
$_POST['actions']
|
||||
);
|
||||
$log_id = self::$improve->writeLogs();
|
||||
|
|
|
@ -184,10 +184,10 @@ class cssheader extends Action
|
|||
$this->bloc_wildcards,
|
||||
[
|
||||
date('Y'),
|
||||
$this->module['id'],
|
||||
$this->module['name'],
|
||||
$this->module['author'],
|
||||
$this->module['type'],
|
||||
$this->module->getId(),
|
||||
$this->module->get('name'),
|
||||
$this->module->get('author'),
|
||||
$this->module->get('type'),
|
||||
dcCore::app()->auth->getInfo('user_cn'),
|
||||
dcCore::app()->auth->getinfo('user_name'),
|
||||
dcCore::app()->auth->getInfo('user_email'),
|
||||
|
|
|
@ -97,7 +97,7 @@ class dcstore extends Action
|
|||
$content = $this->prettyXML($content);
|
||||
|
||||
try {
|
||||
files::putContent($this->module['sroot'] . '/dcstore.xml', $content);
|
||||
files::putContent($this->module->get('root') . DIRECTORY_SEPARATOR . 'dcstore.xml', $content);
|
||||
$this->setSuccess(__('Write dcstore.xml file.'));
|
||||
} catch (Exception $e) {
|
||||
$this->setError(__('Failed to write dcstore.xml file'));
|
||||
|
@ -114,37 +114,34 @@ class dcstore extends Action
|
|||
$rsp = new xmlTag('module');
|
||||
|
||||
# id
|
||||
if (empty($this->module['id'])) {
|
||||
$this->setError(__('unkow module id'));
|
||||
}
|
||||
$rsp->id = $this->module['id'];
|
||||
$rsp->id = $this->module->getId();
|
||||
|
||||
# name
|
||||
if (empty($this->module['oname'])) {
|
||||
if (empty($this->module->get('name'))) {
|
||||
$this->setError(__('unknow module name'));
|
||||
}
|
||||
$rsp->name($this->module['oname']);
|
||||
$rsp->name($this->module->get('name'));
|
||||
|
||||
# version
|
||||
if (empty($this->module['version'])) {
|
||||
if (empty($this->module->get('version'))) {
|
||||
$this->setError(__('unknow module version'));
|
||||
}
|
||||
$rsp->version($this->module['version']);
|
||||
$rsp->version($this->module->get('version'));
|
||||
|
||||
# author
|
||||
if (empty($this->module['author'])) {
|
||||
if (empty($this->module->get('author'))) {
|
||||
$this->setError(__('unknow module author'));
|
||||
}
|
||||
$rsp->author($this->module['author']);
|
||||
$rsp->author($this->module->get('author'));
|
||||
|
||||
# desc
|
||||
if (empty($this->module['desc'])) {
|
||||
if (empty($this->module->get('desc'))) {
|
||||
$this->setError(__('unknow module description'));
|
||||
}
|
||||
$rsp->desc($this->module['desc']);
|
||||
$rsp->desc($this->module->get('desc'));
|
||||
|
||||
# repository
|
||||
if (empty($this->module['repository'])) {
|
||||
if (empty($this->module->get('repository'))) {
|
||||
$this->setError(__('no repository set in _define.php'));
|
||||
}
|
||||
|
||||
|
@ -156,44 +153,44 @@ class dcstore extends Action
|
|||
$rsp->file($file_pattern);
|
||||
|
||||
# da dc_min or requires core
|
||||
if (!empty($this->module['requires']) && is_array($this->module['requires'])) {
|
||||
foreach ($this->module['requires'] as $req) {
|
||||
if (!empty($this->module->get('requires')) && is_array($this->module->get('requires'))) {
|
||||
foreach ($this->module->get('requires') as $req) {
|
||||
if (!is_array($req)) {
|
||||
$req = [$req];
|
||||
}
|
||||
if ($req[0] == 'core') {
|
||||
$this->module['dc_min'] = $req[1];
|
||||
$this->module->set('dc_min', $req[1]);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (empty($this->module['dc_min'])) {
|
||||
if (empty($this->module->get('dc_min'))) {
|
||||
$this->setWarning(__('no minimum dotclear version'));
|
||||
} else {
|
||||
$rsp->insertNode(new xmlTag('da:dcmin', $this->module['dc_min']));
|
||||
$rsp->insertNode(new xmlTag('da:dcmin', $this->module->get('dc_min')));
|
||||
}
|
||||
|
||||
# da details
|
||||
if (empty($this->module['details'])) {
|
||||
if (empty($this->module->get('details'))) {
|
||||
$this->setWarning(__('no details URL'));
|
||||
} else {
|
||||
$rsp->insertNode(new xmlTag('da:details', $this->module['details']));
|
||||
$rsp->insertNode(new xmlTag('da:details', $this->module->get('details')));
|
||||
}
|
||||
|
||||
# da sshot
|
||||
//$rsp->insertNode(new xmlTag('da:sshot', $this->module['sshot']));
|
||||
|
||||
# da section
|
||||
if (!empty($this->module['section'])) {
|
||||
$rsp->insertNode(new xmlTag('da:section', $this->module['section']));
|
||||
if (!empty($this->module->get('section'))) {
|
||||
$rsp->insertNode(new xmlTag('da:section', $this->module->get('section')));
|
||||
}
|
||||
|
||||
# da support
|
||||
if (empty($this->module['support'])) {
|
||||
if (empty($this->module->get('support'))) {
|
||||
$this->setWarning(__('no support URL'));
|
||||
} else {
|
||||
$rsp->insertNode(new xmlTag('da:support', $this->module['support']));
|
||||
$rsp->insertNode(new xmlTag('da:support', $this->module->get('support')));
|
||||
}
|
||||
|
||||
# da tags
|
||||
|
@ -229,10 +226,10 @@ class dcstore extends Action
|
|||
'%author%',
|
||||
],
|
||||
[
|
||||
$this->module['type'],
|
||||
$this->module['id'],
|
||||
$this->module['version'],
|
||||
$this->module['author'],
|
||||
$this->module->get('type'),
|
||||
$this->module->getId(),
|
||||
$this->module->get('version'),
|
||||
$this->module->get('author'),
|
||||
],
|
||||
$this->pattern
|
||||
));
|
||||
|
|
|
@ -154,9 +154,9 @@ class gitshields extends Action
|
|||
],
|
||||
[
|
||||
$this->username,
|
||||
$this->module['id'],
|
||||
$this->module->getId(),
|
||||
$dotclear = $this->getDotclearVersion(),
|
||||
$this->module['type'],
|
||||
$this->module->get('type'),
|
||||
'', '',
|
||||
],
|
||||
$v
|
||||
|
@ -169,8 +169,8 @@ class gitshields extends Action
|
|||
private function getDotclearVersion(): string
|
||||
{
|
||||
$version = null;
|
||||
if (!empty($this->module['requires']) && is_array($this->module['requires'])) {
|
||||
foreach ($this->module['requires'] as $req) {
|
||||
if (!empty($this->module->get('requires')) && is_array($this->module->get('requires'))) {
|
||||
foreach ($this->module->get('requires') as $req) {
|
||||
if (!is_array($req)) {
|
||||
$req = [$req];
|
||||
}
|
||||
|
@ -180,8 +180,8 @@ class gitshields extends Action
|
|||
break;
|
||||
}
|
||||
}
|
||||
} elseif (!empty($this->module['dc_min'])) {
|
||||
$version = $this->module['dc_min'];
|
||||
} elseif (!empty($this->module->get('dc_min'))) {
|
||||
$version = $this->module->get('dc_min');
|
||||
}
|
||||
|
||||
return $version ?: dcCore::app()->getVersion('core');
|
||||
|
|
|
@ -131,13 +131,13 @@ class licensefile extends Action
|
|||
private function writeFullLicense(): ?bool
|
||||
{
|
||||
try {
|
||||
$full = file_get_contents(__DIR__ . '/licensefile/' . $this->getSetting('action_version') . '.full.txt');
|
||||
$full = file_get_contents(__DIR__ . DIRECTORY_SEPARATOR . 'licensefile' . DIRECTORY_SEPARATOR . $this->getSetting('action_version') . '.full.txt');
|
||||
if (empty($full)) {
|
||||
$this->setError(__('Failed to load license content'));
|
||||
|
||||
return null;
|
||||
}
|
||||
files::putContent($this->module['root'] . '/LICENSE', str_replace("\r\n", "\n", $full));
|
||||
files::putContent($this->module->get('root') . DIRECTORY_SEPARATOR . 'LICENSE', str_replace("\r\n", "\n", $full));
|
||||
$this->setSuccess(__('Write new license file "LICENSE"'));
|
||||
} catch (Exception $e) {
|
||||
$this->setError(__('Failed to write new license file'));
|
||||
|
@ -150,13 +150,13 @@ class licensefile extends Action
|
|||
|
||||
private function deleteFullLicense(bool $only_one = false): bool
|
||||
{
|
||||
foreach (self::fileExists($this->module['root']) as $file) {
|
||||
foreach (self::fileExists($this->module->get('root')) as $file) {
|
||||
if ($only_one && $file != 'LICENSE') {
|
||||
continue;
|
||||
}
|
||||
if (!files::isDeletable($this->module['root'] . '/' . $file)) {
|
||||
if (!files::isDeletable($this->module->get('root') . DIRECTORY_SEPARATOR . $file)) {
|
||||
$this->setWarning(sprintf(__('Old license file is not deletable (%s)'), $file));
|
||||
} elseif (!@unlink($this->module['root'] . '/' . $file)) {
|
||||
} elseif (!@unlink($this->module->get('root') . DIRECTORY_SEPARATOR . $file)) {
|
||||
$this->setError(sprintf(__('Failed to delete old license file (%s)'), $file));
|
||||
} else {
|
||||
$this->setSuccess(sprintf(__('Delete old license file "%s"'), $file));
|
||||
|
|
|
@ -137,7 +137,7 @@ class phpcsfixer extends Action
|
|||
'%sphp %s/phpcsfixer/libs/php-cs-fixer.phar fix %s --config=%s/phpcsfixer/phpcsfixer.rules.php --using-cache=no',
|
||||
$this->phpexe_path,
|
||||
__DIR__,
|
||||
$this->module['sroot'],
|
||||
$this->module->get('root'),
|
||||
__DIR__
|
||||
);
|
||||
|
||||
|
|
|
@ -183,10 +183,10 @@ class phpheader extends Action
|
|||
$this->bloc_wildcards,
|
||||
[
|
||||
date('Y'),
|
||||
$this->module['id'],
|
||||
$this->module['name'],
|
||||
$this->module['author'],
|
||||
$this->module['type'],
|
||||
$this->module->getId(),
|
||||
$this->module->get('name'),
|
||||
$this->module->get('author'),
|
||||
$this->module->get('type'),
|
||||
dcCore::app()->auth->getInfo('user_cn'),
|
||||
dcCore::app()->auth->getinfo('user_name'),
|
||||
dcCore::app()->auth->getInfo('user_email'),
|
||||
|
|
|
@ -292,7 +292,7 @@ class phpstan extends Action
|
|||
],
|
||||
[
|
||||
$this->run_level,
|
||||
(string) path::real($this->module['sroot'], false),
|
||||
(string) path::real($this->module->get('root'), false),
|
||||
(string) path::real(DC_ROOT, false),
|
||||
(string) path::real(__DIR__ . '/phpstan', false),
|
||||
],
|
||||
|
|
|
@ -189,10 +189,10 @@ class zip extends Action
|
|||
$file = str_replace(
|
||||
self::$filename_wildcards,
|
||||
[
|
||||
$this->module['type'],
|
||||
$this->module['id'],
|
||||
$this->module['version'],
|
||||
$this->module['author'],
|
||||
$this->module->get('type'),
|
||||
$this->module->getId(),
|
||||
$this->module->get('version'),
|
||||
$this->module->get('author'),
|
||||
time(),
|
||||
],
|
||||
$file
|
||||
|
@ -223,8 +223,8 @@ class zip extends Action
|
|||
$zip->addExclusion($e);
|
||||
}
|
||||
$zip->addDirectory(
|
||||
path::real($this->module['root']),
|
||||
$this->module['id'],
|
||||
path::real($this->module->get('root')),
|
||||
$this->module->getId(),
|
||||
true
|
||||
);
|
||||
$zip->close();
|
||||
|
|
Loading…
Reference in a new issue