add namespace related values from Uninstaller 0.6, fix #1
This commit is contained in:
parent
1d0caa58fe
commit
3352cefc92
100
src/Manage.php
100
src/Manage.php
@ -76,9 +76,20 @@ class Manage extends dcNsProcess
|
||||
|
||||
if (!empty($vars->entries) && !empty($vars->action)) {
|
||||
try {
|
||||
// special related
|
||||
if (!empty($vars->related) && $vars->action == 'delete_related') {
|
||||
$ns = '';
|
||||
foreach ($vars->entries as $id) {
|
||||
$ns .= $vars->related . ':' . $id . ';';
|
||||
}
|
||||
$vars->cleaners->execute($vars->cleaner->id, $vars->action, $ns);
|
||||
// other actions
|
||||
} elseif ($vars->action != 'delete_related') {
|
||||
foreach ($vars->entries as $ns) {
|
||||
$vars->cleaners->execute($vars->cleaner->id, $vars->action, $ns);
|
||||
}
|
||||
}
|
||||
|
||||
dcPage::addSuccessNotice(__('Action successfuly excecuted'));
|
||||
dcCore::app()->adminurl?->redirect(
|
||||
'admin.plugin.' . My::id(),
|
||||
@ -110,20 +121,35 @@ class Manage extends dcNsProcess
|
||||
# --BEHAVIOR-- dcAdvancedCleanerAdminHeader
|
||||
dcCore::app()->callBehavior('dcAdvancedCleanerAdminHeader');
|
||||
|
||||
echo
|
||||
dcPage::breadcrumb([
|
||||
$breadcrumb = [
|
||||
__('Plugins') => '',
|
||||
My::name() => '',
|
||||
]) .
|
||||
dcPage::notices();
|
||||
];
|
||||
|
||||
// something went wrong !
|
||||
if (null === $vars->cleaner) {
|
||||
echo
|
||||
dcPage::breadcrumb($breadcrumb) .
|
||||
dcPage::notices();
|
||||
echo (new Text('p', __('There is nothing to display')))->class('error')->render();
|
||||
dcPage::closeModule();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
$breadcrumb[My::name()] = dcCore::app()->adminurl?->get('admin.plugin.' . My::id());
|
||||
$breadcrumb[$vars->cleaner->name] = '';
|
||||
|
||||
if (!empty($vars->related)) {
|
||||
$breadcrumb[$vars->cleaner->name] = dcCore::app()->adminurl?->get('admin.plugin.' . My::id(), ['part' => $vars->cleaner->id]);
|
||||
$breadcrumb[$vars->related] = '';
|
||||
}
|
||||
|
||||
echo
|
||||
dcPage::breadcrumb($breadcrumb) .
|
||||
dcPage::notices();
|
||||
|
||||
if (empty($vars->related)) {
|
||||
echo
|
||||
(new Form('parts_menu'))->method('get')->action(dcCore::app()->adminurl?->get('admin.plugin.' . My::id()))->fields([
|
||||
(new Para())->class('anchor-nav')->items([
|
||||
@ -137,14 +163,16 @@ class Manage extends dcNsProcess
|
||||
'<h3>' . $vars->cleaner->name . '</h3><p>' . $vars->cleaner->desc . '</p>';
|
||||
|
||||
$rs = $vars->cleaner->values();
|
||||
|
||||
if (empty($rs)) {
|
||||
echo (new Text('p', __('There is nothing to display')))->class('error')->render();
|
||||
} else {
|
||||
$combo_actions = [];
|
||||
$has_related = false;
|
||||
foreach ($vars->cleaner->actions as $descriptor) {
|
||||
// exception
|
||||
if ($descriptor->id == 'delete_related') {
|
||||
$has_related = true;
|
||||
|
||||
continue;
|
||||
}
|
||||
$combo_actions[$descriptor->select] = $descriptor->id;
|
||||
@ -155,10 +183,11 @@ class Manage extends dcNsProcess
|
||||
'<div class="table-outer">' .
|
||||
'<table><caption>' . sprintf(__('There are %s entries'), count($rs)) . '</caption><thead><tr>' .
|
||||
'<th colspan="2">' . __('Name') . '</th><th colspan="2">' . __('Objects') . '</th>' .
|
||||
'<th></th>' .
|
||||
'</tr></thead><tbody>';
|
||||
|
||||
foreach ($rs as $k => $v) {
|
||||
$distrib = in_array($v['key'], $vars->cleaner->distributed());
|
||||
foreach ($rs as $key => $value) {
|
||||
$distrib = in_array($value->ns, $vars->cleaner->distributed());
|
||||
|
||||
if ($distrib && dcCore::app()->blog?->settings->get(My::id())->get('dcproperty_hide')) {
|
||||
continue;
|
||||
@ -166,17 +195,20 @@ class Manage extends dcNsProcess
|
||||
echo
|
||||
'<tr class="line' . ($distrib ? ' offline' : '') . '">' .
|
||||
'<td class="nowrap">' .
|
||||
(new Checkbox(['entries[' . $k . ']', 'entries_' . $k]))->value(Html::escapeHTML($v['key']))->render() .
|
||||
(new Checkbox(['entries[' . $key . ']', 'entries_' . $key]))->value(Html::escapeHTML($value->ns))->render() .
|
||||
'</td> ' .
|
||||
'<td class="nowrap">' .
|
||||
(new Label($v['key'], Label::OUTSIDE_LABEL_AFTER))->for('entries_' . $k)->class('classic')->render() .
|
||||
(new Label($value->ns, Label::OUTSIDE_LABEL_AFTER))->for('entries_' . $key)->class('classic')->render() .
|
||||
'</td>' .
|
||||
'<td class="nowrap">' . $v['value'] . '</td>' .
|
||||
'<td class="module-distrib maximal">' . ($distrib ?
|
||||
'<td class="nowrap">' . ($value->id != '' ? $value->id : $value->count) . '</td>' .
|
||||
'<td class="module-distrib">' . ($distrib ?
|
||||
'<img src="images/dotclear-leaf.svg" alt="' .
|
||||
__('Values from official distribution') . '" title="' .
|
||||
__('Values from official distribution') . '" />'
|
||||
: '') . '</td>' .
|
||||
'<td class="maximal">' . ($has_related ? ' <a href="' .
|
||||
dcCore::app()->adminurl?->get('admin.plugin.' . My::id(), ['part' => $vars->cleaner->id, 'related' => $value->ns]) .
|
||||
'">' . __('Details') . '<a>' : '') . '</td>' .
|
||||
'</tr>';
|
||||
}
|
||||
|
||||
@ -206,6 +238,52 @@ class Manage extends dcNsProcess
|
||||
dcCore::app()->formNonce(false),
|
||||
]),
|
||||
])->render();
|
||||
} else {
|
||||
echo
|
||||
'<p><a class="back" href="' . dcCore::app()->adminurl?->get('admin.plugin.' . My::id(), ['part' => $vars->cleaner->id]) . '">' . __('Back') . '</a></p>' .
|
||||
'<h3>' . $vars->cleaner->name . ' : ' . $vars->related . '</h3><p>' . $vars->cleaner->desc . '</p>';
|
||||
|
||||
$distrib = in_array($vars->related, $vars->cleaner->distributed());
|
||||
$rs = $vars->cleaner->related($vars->related);
|
||||
if (empty($rs)) {
|
||||
echo (new Text('p', __('There is nothing to display')))->class('error')->render();
|
||||
} else {
|
||||
echo
|
||||
'<form method="post" action="' . dcCore::app()->adminurl?->get('admin.plugin.' . My::id()) . '" id="form-funcs">' .
|
||||
'<div class="table-outer">' .
|
||||
'<table><caption>' . sprintf(__('There are %s related entries for the group "%s"'), count($rs), $vars->related) . '</caption><thead><tr>' .
|
||||
'<th colspan="2">' . __('Name') . '</th><th>' . __('Objects') . '</th>' .
|
||||
'</tr></thead><tbody>';
|
||||
|
||||
foreach ($rs as $key => $value) {
|
||||
echo
|
||||
'<tr class="line">' .
|
||||
'<td class="nowrap">' .
|
||||
(new Checkbox(['entries[' . $key . ']', 'entries_' . $key]))->value(Html::escapeHTML($value->id))->render() .
|
||||
'</td> ' .
|
||||
'<td class="nowrap">' .
|
||||
(new Label($value->id, Label::OUTSIDE_LABEL_AFTER))->for('entries_' . $key)->class('classic')->render() .
|
||||
'</td>' .
|
||||
'<td class="nowrap maximal">' . $value->count . '</td>' .
|
||||
'</tr>';
|
||||
}
|
||||
|
||||
echo
|
||||
'</tbody></table></div>' .
|
||||
(new Para())->items([
|
||||
(new Submit('do-action'))->class('delete')->value(__('I understand and I am want to delete this')),
|
||||
(new Hidden(['p'], My::id())),
|
||||
(new Hidden(['related'], $vars->related)),
|
||||
(new Hidden(['part'], $vars->cleaner->id)),
|
||||
(new Hidden(['action'], 'delete_related')),
|
||||
dcCore::app()->formNonce(false),
|
||||
])->render() .
|
||||
'<p class="warning">' .
|
||||
__('Beware: All actions done here are irreversible and are directly applied') .
|
||||
'</p>' .
|
||||
'</form>';
|
||||
}
|
||||
}
|
||||
|
||||
dcPage::closeModule();
|
||||
}
|
||||
|
@ -30,6 +30,7 @@ class ManageVars
|
||||
|
||||
public readonly Cleaners $cleaners;
|
||||
public readonly ?AbstractCleaner $cleaner;
|
||||
public readonly string $related;
|
||||
public readonly array $entries;
|
||||
public readonly string $action;
|
||||
public readonly array $combo;
|
||||
@ -38,6 +39,7 @@ class ManageVars
|
||||
{
|
||||
$this->cleaners = Uninstaller::instance()->cleaners;
|
||||
|
||||
$related = $_REQUEST['related'] ?? '';
|
||||
$entries = $_REQUEST['entries'] ?? [];
|
||||
$action = $_POST['action'] ?? '';
|
||||
|
||||
@ -50,12 +52,14 @@ class ManageVars
|
||||
}
|
||||
}
|
||||
if ($cleaner === null) {
|
||||
$related = '';
|
||||
if (!($cleaner = $this->cleaners->get('caches'))) {
|
||||
throw new Exception(__('Failed to load cleaner'));
|
||||
}
|
||||
}
|
||||
|
||||
$this->cleaner = $cleaner;
|
||||
$this->related = $related;
|
||||
$this->entries = is_array($entries) ? $entries : [];
|
||||
$this->action = is_string($action) ? $action : '';
|
||||
$this->combo = $combo;
|
||||
|
Loading…
Reference in New Issue
Block a user