fix nullsafe warnings
This commit is contained in:
parent
3001293077
commit
03d8f64238
14 changed files with 102 additions and 68 deletions
|
@ -82,7 +82,7 @@ abstract class Action
|
|||
$this->class_name = str_replace(__NAMESPACE__ . '\\Module\\', '', get_called_class());
|
||||
$this->module = new dcModuleDefine('undefined');
|
||||
|
||||
$settings = dcCore::app()->blog->settings->get(My::id())->get('settings_' . $this->class_name);
|
||||
$settings = dcCore::app()->blog?->settings->get(My::id())->get('settings_' . $this->class_name);
|
||||
if (null != $settings) {
|
||||
$settings = json_decode($settings, true);
|
||||
}
|
||||
|
@ -91,7 +91,7 @@ abstract class Action
|
|||
$this->init();
|
||||
|
||||
// can overload priority by settings
|
||||
if (1 < ($p = (int) dcCore::app()->blog->settings->get(My::id())->get('priority_' . $this->class_name))) {
|
||||
if (1 < ($p = (int) dcCore::app()->blog?->settings->get(My::id())->get('priority_' . $this->class_name))) {
|
||||
$this->priority = $p;
|
||||
}
|
||||
}
|
||||
|
@ -232,6 +232,7 @@ abstract class Action
|
|||
*/
|
||||
final protected function redirect(string $url): bool
|
||||
{
|
||||
if (!is_null(dcCore::app()->blog)) {
|
||||
dcCore::app()->blog->settings->get(My::id())->put(
|
||||
'settings_' . $this->class_name,
|
||||
json_encode($this->settings),
|
||||
|
@ -242,6 +243,7 @@ abstract class Action
|
|||
);
|
||||
dcCore::app()->blog->triggerBlog();
|
||||
dcPage::addSuccessNotice(__('Configuration successfully updated'));
|
||||
}
|
||||
Http::redirect($url);
|
||||
|
||||
return true;
|
||||
|
|
|
@ -31,6 +31,7 @@ class Backend extends dcNsProcess
|
|||
public static function init(): bool
|
||||
{
|
||||
static::$init = defined('DC_CONTEXT_ADMIN')
|
||||
&& !is_null(dcCore::app()->auth)
|
||||
&& dcCore::app()->auth->isSuperAdmin()
|
||||
&& My::phpCompliant();
|
||||
|
||||
|
@ -43,18 +44,9 @@ class Backend extends dcNsProcess
|
|||
return false;
|
||||
}
|
||||
|
||||
dcCore::app()->addBehavior('adminDashboardFavoritesV2', function (dcFavorites $favs): void {
|
||||
$favs->register(
|
||||
My::id(),
|
||||
[
|
||||
'title' => My::name(),
|
||||
'url' => dcCore::app()->adminurl->get('admin.plugin.' . My::id()),
|
||||
'small-icon' => dcPage::getPF(My::id() . '/icon.svg'),
|
||||
'large-icon' => dcPage::getPF(My::id() . '/icon.svg'),
|
||||
//'permissions' => null,
|
||||
]
|
||||
);
|
||||
});
|
||||
if (is_null(dcCore::app()->auth) || is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
dcCore::app()->menu[dcAdmin::MENU_PLUGINS]->addItem(
|
||||
My::name(),
|
||||
|
@ -64,6 +56,19 @@ class Backend extends dcNsProcess
|
|||
dcCore::app()->auth->isSuperAdmin()
|
||||
);
|
||||
|
||||
dcCore::app()->addBehavior('adminDashboardFavoritesV2', function (dcFavorites $favs): void {
|
||||
$favs->register(
|
||||
My::id(),
|
||||
[
|
||||
'title' => My::name(),
|
||||
'url' => dcCore::app()->adminurl?->get('admin.plugin.' . My::id()),
|
||||
'small-icon' => dcPage::getPF(My::id() . '/icon.svg'),
|
||||
'large-icon' => dcPage::getPF(My::id() . '/icon.svg'),
|
||||
//'permissions' => null,
|
||||
]
|
||||
);
|
||||
});
|
||||
|
||||
$dir = __DIR__ . DIRECTORY_SEPARATOR . 'module' . DIRECTORY_SEPARATOR;
|
||||
$ns = __NAMESPACE__ . '\\Module\\';
|
||||
|
||||
|
|
|
@ -39,6 +39,7 @@ class Config extends dcNsProcess
|
|||
public static function init(): bool
|
||||
{
|
||||
static::$init = defined('DC_CONTEXT_ADMIN')
|
||||
&& !is_null(dcCore::app()->auth)
|
||||
&& dcCore::app()->auth->isSuperAdmin()
|
||||
&& My::phpCompliant();
|
||||
|
||||
|
@ -55,6 +56,10 @@ class Config extends dcNsProcess
|
|||
return true;
|
||||
}
|
||||
|
||||
if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
$pdisabled = '';
|
||||
if (!empty($_POST['disabled']) && is_array($_POST['disabled'])) {
|
||||
|
@ -84,8 +89,13 @@ class Config extends dcNsProcess
|
|||
return;
|
||||
}
|
||||
|
||||
if (is_null(dcCore::app()->blog) || is_null(dcCore::app()->adminurl)) {
|
||||
return;
|
||||
}
|
||||
|
||||
$improve = new Core();
|
||||
$modules = $items = [];
|
||||
$settings = dcCore::app()->blog->settings->get(My::id());
|
||||
|
||||
foreach ($improve->modules() as $action) {
|
||||
$modules[$action->name()] = $action->id();
|
||||
|
@ -103,16 +113,16 @@ class Config extends dcNsProcess
|
|||
(new Fieldset())->class('fieldset')->legend(new Legend(__('List of disabled actions')))->fields($items),
|
||||
(new Fieldset())->class('fieldset')->legend(new Legend(__('Options')))->fields([
|
||||
(new Para())->items([
|
||||
(new Checkbox('nodetails', (bool) dcCore::app()->blog->settings->get(My::id())->get('nodetails')))->value('1'),
|
||||
(new Checkbox('nodetails', (bool) $settings->get('nodetails')))->value('1'),
|
||||
(new Label(__('Hide details of rendered actions'), Label::OUTSIDE_LABEL_AFTER))->class('classic')->for('nodetails'),
|
||||
]),
|
||||
(new Para())->items([
|
||||
(new Checkbox('allow_distrib', (bool) dcCore::app()->blog->settings->get(My::id())->get('allow_distrib')))->value('1'),
|
||||
(new Checkbox('allow_distrib', (bool) $settings->get('allow_distrib')))->value('1'),
|
||||
(new Label(__('Show dotclear distributed modules'), Label::OUTSIDE_LABEL_AFTER))->class('classic')->for('allow_distrib'),
|
||||
]),
|
||||
(new Para())->items([
|
||||
(new Label(__('Sort modules seletion by:'), Label::OUTSIDE_LABEL_BEFORE))->for('combosortby'),
|
||||
(new Select('combosortby'))->items([__('Name') => 'name', __('Id') => 'id'])->default(dcCore::app()->blog->settings->get(My::id())->get('combosortby')),
|
||||
(new Select('combosortby'))->items([__('Name') => 'name', __('Id') => 'id'])->default($settings->get('combosortby')),
|
||||
]),
|
||||
]),
|
||||
])->render();
|
||||
|
|
|
@ -51,7 +51,7 @@ class Core
|
|||
*/
|
||||
public function __construct()
|
||||
{
|
||||
$disabled = explode(';', (string) dcCore::app()->blog->settings->get(My::id())->get('disabled'));
|
||||
$disabled = explode(';', (string) dcCore::app()->blog?->settings->get(My::id())->get('disabled'));
|
||||
$list = new ArrayObject();
|
||||
|
||||
try {
|
||||
|
@ -307,11 +307,6 @@ class Core
|
|||
return $res;
|
||||
}
|
||||
|
||||
public function getURL(array $params = []): string
|
||||
{
|
||||
return dcCore::app()->adminurl->get('admin.plugin.' . My::id(), $params, '&');
|
||||
}
|
||||
|
||||
/**
|
||||
* Check and clean file extension
|
||||
*
|
||||
|
|
|
@ -66,7 +66,7 @@ class Install extends dcNsProcess
|
|||
private static function putSettings(): void
|
||||
{
|
||||
foreach (self::$default_settings as $v) {
|
||||
dcCore::app()->blog->settings->get(My::id())->put(
|
||||
dcCore::app()->blog?->settings->get(My::id())->put(
|
||||
$v[0],
|
||||
$v[2],
|
||||
$v[3],
|
||||
|
@ -80,7 +80,7 @@ class Install extends dcNsProcess
|
|||
/** Update improve < 0.8 : action modules settings name */
|
||||
private static function update_0_8_0(): void
|
||||
{
|
||||
if (version_compare(dcCore::app()->getVersion(My::id()) ?? '0', '0.8', '<')) {
|
||||
if (!is_null(dcCore::app()->blog) && version_compare(dcCore::app()->getVersion(My::id()) ?? '0', '0.8', '<')) {
|
||||
foreach (dcCore::app()->blog->settings->get(My::id())->dumpGlobalSettings() as $id => $values) {
|
||||
$newId = str_replace('ImproveAction', '', $id);
|
||||
if ($id != $newId) {
|
||||
|
|
|
@ -51,11 +51,10 @@ class Manage extends dcNsProcess
|
|||
/** @var Action|null $action Current action module */
|
||||
private static $action = null;
|
||||
|
||||
protected static $init = false;
|
||||
|
||||
public static function init(): bool
|
||||
{
|
||||
static::$init = defined('DC_CONTEXT_ADMIN')
|
||||
&& !is_null(dcCore::app()->auth)
|
||||
&& dcCore::app()->auth->isSuperAdmin()
|
||||
&& My::phpCompliant();
|
||||
|
||||
|
@ -86,7 +85,7 @@ class Manage extends dcNsProcess
|
|||
{
|
||||
try {
|
||||
if (!empty(self::$type)) {
|
||||
$preferences = dcCore::app()->blog->settings->get(My::id())->get('preferences');
|
||||
$preferences = dcCore::app()->blog?->settings->get(My::id())->get('preferences');
|
||||
if (is_string($preferences)) {
|
||||
$preferences = json_decode($preferences, true);
|
||||
if (is_array($preferences)) {
|
||||
|
@ -102,7 +101,7 @@ class Manage extends dcNsProcess
|
|||
|
||||
private static function setPreferences(): bool
|
||||
{
|
||||
if (!empty($_POST['save_preferences'])) {
|
||||
if (!empty($_POST['save_preferences']) && !is_null(dcCore::app()->blog)) {
|
||||
$preferences = self::getPreference(true);
|
||||
$preferences[self::$type] = [];
|
||||
if (!empty($_POST['actions'])) {
|
||||
|
@ -123,6 +122,10 @@ class Manage extends dcNsProcess
|
|||
|
||||
private static function comboModules(): array
|
||||
{
|
||||
if (is_null(dcCore::app()->blog)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (!(dcCore::app()->themes instanceof dcThemes)) {
|
||||
dcCore::app()->themes = new dcThemes();
|
||||
dcCore::app()->themes->loadModules(dcCore::app()->blog->themes_path, null);
|
||||
|
@ -175,7 +178,7 @@ class Manage extends dcNsProcess
|
|||
$_POST['actions']
|
||||
);
|
||||
$log_id = self::$improve->writeLogs();
|
||||
dcCore::app()->blog->triggerBlog();
|
||||
dcCore::app()->blog?->triggerBlog();
|
||||
|
||||
if (self::$improve->hasLog('error')) {
|
||||
$notice = ['type' => dcAdminNotices::NOTICE_ERROR, 'msg' => __('Fix of "%s" complete in %s secondes with errors')];
|
||||
|
@ -197,7 +200,7 @@ class Manage extends dcNsProcess
|
|||
}
|
||||
|
||||
if ($done) {
|
||||
dcCore::app()->adminurl->redirect('admin.plugin.' . My::id(), ['type' => self::$type, 'module' => self::$module, 'upd' => $log_id]);
|
||||
dcCore::app()->adminurl?->redirect('admin.plugin.' . My::id(), ['type' => self::$type, 'module' => self::$module, 'upd' => $log_id]);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -234,14 +237,14 @@ class Manage extends dcNsProcess
|
|||
|
||||
private static function displayConfigurator(): void
|
||||
{
|
||||
$back_url = $_REQUEST['redir'] ?? dcCore::app()->adminurl->get('admin.plugin.' . My::id(), ['type' => self::$type]);
|
||||
$back_url = $_REQUEST['redir'] ?? dcCore::app()->adminurl?->get('admin.plugin.' . My::id(), ['type' => self::$type]);
|
||||
|
||||
if (null === self::$action) {
|
||||
echo '
|
||||
<p class="warning">' . __('Unknow module') . '</p>
|
||||
<p><a class="back" href="' . $back_url . '">' . __('Back') . '</a></p>';
|
||||
} else {
|
||||
$redir = $_REQUEST['redir'] ?? dcCore::app()->adminurl->get('admin.plugin.' . My::id(), ['type' => self::$type, 'config' => self::$action->id()]);
|
||||
$redir = $_REQUEST['redir'] ?? dcCore::app()->adminurl?->get('admin.plugin.' . My::id(), ['type' => self::$type, 'config' => self::$action->id()]);
|
||||
$res = self::$action->configure($redir);
|
||||
|
||||
echo '
|
||||
|
@ -249,7 +252,7 @@ class Manage extends dcNsProcess
|
|||
<p><a class="back" href="' . $back_url . '">' . __('Back') . '</a></p>
|
||||
<h4>' . Html::escapeHTML(self::$action->description()) . '</h4>' .
|
||||
|
||||
(new Form('form-actions'))->method('post')->action(dcCore::app()->adminurl->get('admin.plugin.' . My::id()))->fields([
|
||||
(new Form('form-actions'))->method('post')->action(dcCore::app()->adminurl?->get('admin.plugin.' . My::id()))->fields([
|
||||
empty($res) ? (new Text('p', __('Nothing to configure')))->class('message') : (new Text('', $res)),
|
||||
(new Para())->class('clear')->items([
|
||||
(new Submit(['save']))->value(__('Save')),
|
||||
|
@ -265,7 +268,7 @@ class Manage extends dcNsProcess
|
|||
private static function displayActions(): void
|
||||
{
|
||||
echo
|
||||
(new Form('improve_menu'))->method('get')->action(dcCore::app()->adminurl->get('admin.plugin.' . My::id()))->fields([
|
||||
(new Form('improve_menu'))->method('get')->action(dcCore::app()->adminurl?->get('admin.plugin.' . My::id()))->fields([
|
||||
(new Para())->class('anchor-nav')->items([
|
||||
(new Label(__('Goto:'), Label::OUTSIDE_LABEL_BEFORE))->for('type')->class('classic'),
|
||||
(new Select('type'))->default(self::$type)->items([__('Plugins') => 'plugin', __('Themes') => 'theme']),
|
||||
|
@ -278,7 +281,7 @@ class Manage extends dcNsProcess
|
|||
if (count($combo_modules) == 1) {
|
||||
echo '<p class="message">' . __('No module to manage') . '</p>';
|
||||
} else {
|
||||
echo '<form action="' . dcCore::app()->adminurl->get('admin.plugin.' . My::id()) . '" method="post" id="form-actions">' .
|
||||
echo '<form action="' . dcCore::app()->adminurl?->get('admin.plugin.' . My::id()) . '" method="post" id="form-actions">' .
|
||||
'<table><caption class="hidden">' . __('Actions') . '</caption><thead><tr>' .
|
||||
'<th colspan="2" class="first">' . __('Action') . '</td>' .
|
||||
'<th scope="col">' . __('Description') . '</td>' .
|
||||
|
@ -303,7 +306,7 @@ class Manage extends dcNsProcess
|
|||
'<td class="maximal">' . $action->description() . '</td>' .
|
||||
'<td class="minimal nowrap modules">' . (
|
||||
false === $action->configurator() ? '' :
|
||||
'<a class="module-config" href="' . dcCore::app()->adminurl->get('admin.plugin.' . My::id(), ['type' => self::$type, 'config' => $action->id()]) .
|
||||
'<a class="module-config" href="' . dcCore::app()->adminurl?->get('admin.plugin.' . My::id(), ['type' => self::$type, 'config' => $action->id()]) .
|
||||
'" title="' . sprintf(__("Configure action '%s'"), $action->name()) . '">' . __('Configure') . '</a>'
|
||||
) . '</td>' .
|
||||
(DC_DEBUG ? '<td class="minimal"><span class="debug">' . $action->priority() . '</span></td>' : '') . /* @phpstan-ignore-line */
|
||||
|
@ -327,7 +330,7 @@ class Manage extends dcNsProcess
|
|||
'<br class="clear" />
|
||||
</form>';
|
||||
|
||||
if (!empty($_REQUEST['upd']) && !dcCore::app()->blog->settings->get(My::id())->get('nodetails')) {
|
||||
if (!empty($_REQUEST['upd']) && !dcCore::app()->blog?->settings->get(My::id())->get('nodetails')) {
|
||||
$logs = self::$improve->parseLogs((int) $_REQUEST['upd']);
|
||||
|
||||
if (!empty($logs)) {
|
||||
|
|
|
@ -22,7 +22,7 @@ use dcCore;
|
|||
class My
|
||||
{
|
||||
/** @var string Required php version */
|
||||
public const PHP_MIN = '8.0';
|
||||
public const PHP_MIN = '8.1';
|
||||
|
||||
/**
|
||||
* This module id
|
||||
|
|
|
@ -156,6 +156,12 @@ class cssheader extends Action
|
|||
|
||||
public function openModule(): ?bool
|
||||
{
|
||||
if (is_null(dcCore::app()->auth)) {
|
||||
$this->setWarning(__('Auth is not set'));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$bloc = trim($this->bloc_content);
|
||||
|
||||
if (empty($bloc)) {
|
||||
|
|
|
@ -109,31 +109,31 @@ class dcstore extends Action
|
|||
$rsp = new XmlTag('module');
|
||||
|
||||
# id
|
||||
$rsp->id = $this->module->getId();
|
||||
$rsp->insertAttr('id', $this->module->getId());
|
||||
|
||||
# name
|
||||
if (empty($this->module->get('name'))) {
|
||||
$this->setError(__('unknow module name'));
|
||||
}
|
||||
$rsp->name($this->module->get('name'));
|
||||
$rsp->insertNode(new XmlTag('name', $this->module->get('name')));
|
||||
|
||||
# version
|
||||
if (empty($this->module->get('version'))) {
|
||||
$this->setError(__('unknow module version'));
|
||||
}
|
||||
$rsp->version($this->module->get('version'));
|
||||
$rsp->insertNode(new XmlTag('version', $this->module->get('version')));
|
||||
|
||||
# author
|
||||
if (empty($this->module->get('author'))) {
|
||||
$this->setError(__('unknow module author'));
|
||||
}
|
||||
$rsp->author($this->module->get('author'));
|
||||
$rsp->insertNode(new XmlTag('author', $this->module->get('author')));
|
||||
|
||||
# desc
|
||||
if (empty($this->module->get('desc'))) {
|
||||
$this->setError(__('unknow module description'));
|
||||
}
|
||||
$rsp->desc($this->module->get('desc'));
|
||||
$rsp->insertNode(new XmlTag('desc', $this->module->get('desc')));
|
||||
|
||||
# repository
|
||||
if (empty($this->module->get('repository'))) {
|
||||
|
@ -145,7 +145,7 @@ class dcstore extends Action
|
|||
if (empty($file_pattern)) {
|
||||
$this->setError(__('no zip file pattern set in configuration'));
|
||||
}
|
||||
$rsp->file($file_pattern);
|
||||
$rsp->insertNode(new XmlTag('file', $file_pattern));
|
||||
|
||||
# da dc_min or requires core
|
||||
if (!empty($this->module->get('requires')) && is_array($this->module->get('requires'))) {
|
||||
|
|
|
@ -72,9 +72,11 @@ class phpcsfixer extends Action
|
|||
|
||||
$this->getPhpPath();
|
||||
|
||||
if (null !== dcCore::app()->auth?->user_prefs) {
|
||||
dcCore::app()->auth->user_prefs->addWorkspace('interface');
|
||||
self::$user_ui_colorsyntax = dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax');
|
||||
self::$user_ui_colorsyntax_theme = dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax_theme');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -155,6 +155,12 @@ class phpheader extends Action
|
|||
|
||||
public function openModule(): ?bool
|
||||
{
|
||||
if (is_null(dcCore::app()->auth)) {
|
||||
$this->setWarning(__('Auth is not set'));
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
$bloc = trim($this->bloc_content);
|
||||
|
||||
if (empty($bloc)) {
|
||||
|
|
|
@ -75,16 +75,18 @@ class phpstan extends Action
|
|||
$ignored_vars = $this->getSetting('ignored_vars');
|
||||
$this->ignored_vars = is_string($ignored_vars) ? $ignored_vars : '';
|
||||
|
||||
if (null !== dcCore::app()->auth?->user_prefs) {
|
||||
dcCore::app()->auth->user_prefs->addWorkspace('interface');
|
||||
self::$user_ui_colorsyntax = dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax');
|
||||
self::$user_ui_colorsyntax_theme = dcCore::app()->auth->user_prefs->get('interface')->get('colorsyntax_theme');
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function isConfigured(): bool
|
||||
{
|
||||
return !dcCore::app()->blog->settings->get(My::id())->get('nodetails');
|
||||
return !dcCore::app()->blog?->settings->get(My::id())->get('nodetails');
|
||||
}
|
||||
|
||||
public function header(): ?string
|
||||
|
@ -284,7 +286,7 @@ class phpstan extends Action
|
|||
'%MODULE_ROOT%',
|
||||
'%DC_ROOT%',
|
||||
'%BOOTSTRAP_ROOT%',
|
||||
'%SCAN_DIRECTORIES%'
|
||||
'%SCAN_DIRECTORIES%',
|
||||
],
|
||||
[
|
||||
$this->run_level,
|
||||
|
@ -311,7 +313,7 @@ class phpstan extends Action
|
|||
return (bool) file_put_contents(DC_VAR . '/phpstan.neon', $content);
|
||||
}
|
||||
|
||||
private function getScanDirectories()
|
||||
private function getScanDirectories(): string
|
||||
{
|
||||
$ret = '';
|
||||
if ($this->module->get('type') == 'plugin') {
|
||||
|
@ -323,6 +325,7 @@ class phpstan extends Action
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $ret;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -121,7 +121,7 @@ class zip extends Action
|
|||
]),
|
||||
(new Note())->text(sprintf(
|
||||
__('Preconization: %s'),
|
||||
dcCore::app()->blog->public_path ?
|
||||
dcCore::app()->blog?->public_path ?
|
||||
Path::real(dcCore::app()->blog->public_path) : __("Blog's public directory")
|
||||
))->class('form-note'),
|
||||
]),
|
||||
|
|
|
@ -26,6 +26,8 @@ class Zip extends \Dotclear\Helper\File\Zip\Zip
|
|||
* @param string $file The file
|
||||
* @param string $size The size
|
||||
* @param int|null $mtime The mtime
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
protected function writeFile($name, $file, $size, $mtime)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue