Skip to content

Commit

Permalink
[TASK] Use ModuleData API in SchedulerModuleController
Browse files Browse the repository at this point in the history
The ModuleData API, introduced in #96895,
is now used in the LinkValidatorController.

Additionally, collapsing tasks in the special
"No task group" group is now possible again.

Resolves: #96946
Related: #96895
Related: #96574
Releases: main
Change-Id: Ifa7a475ab18a12495748d774ea2a80da852609b7
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/73579
Tested-by: core-ci <typo3@b13.com>
Tested-by: Stefan Bürk <stefan@buerk.tech>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Stefan Bürk <stefan@buerk.tech>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
  • Loading branch information
o-ba authored and lolli42 committed Feb 18, 2022
1 parent d585226 commit a3b3e60
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 30 deletions.
6 changes: 3 additions & 3 deletions Build/Sources/TypeScript/scheduler/scheduler.ts
Expand Up @@ -54,15 +54,15 @@ class Scheduler {
private static storeCollapseState(table: string, isCollapsed: boolean): void {
let storedModuleData = {};

if (PersistentStorage.isset('moduleData.scheduler')) {
storedModuleData = PersistentStorage.get('moduleData.scheduler');
if (PersistentStorage.isset('moduleData.system_txschedulerM1')) {
storedModuleData = PersistentStorage.get('moduleData.system_txschedulerM1');
}

const collapseConfig: any = {};
collapseConfig[table] = isCollapsed ? 1 : 0;

$.extend(storedModuleData, collapseConfig);
PersistentStorage.set('moduleData.scheduler', storedModuleData);
PersistentStorage.set('moduleData.system_txschedulerM1', storedModuleData);
}

constructor() {
Expand Down
Expand Up @@ -19,6 +19,7 @@

use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Backend\Module\ModuleData;
use TYPO3\CMS\Backend\Routing\UriBuilder;
use TYPO3\CMS\Backend\Template\Components\ButtonBar;
use TYPO3\CMS\Backend\Template\ModuleTemplate;
Expand Down Expand Up @@ -89,18 +90,11 @@ public function handleRequest(ServerRequestInterface $request): ResponseInterfac

// See if action from main module drop down is given, else fetch from user data and update if needed.
$backendUser = $this->getBackendUser();
$storedModuleData = $backendUser->getModuleData('scheduler');
$requestedSubModule = $queryParams['subModule'] ?? $storedModuleData['subModule'] ?? 'scheduler';
if (!empty($requestedSubModule) && !in_array($requestedSubModule, ['scheduler', 'info', 'check'], true)) {
// Reset to 'scheduler list view' if stored moduleData or GET was invalid.
$requestedSubModule = 'scheduler';
$moduleData = $request->getAttribute('moduleData');
if ($moduleData->clean('subModule', ['scheduler', 'info', 'check'])) {
$backendUser->pushModuleData($moduleData->getModuleIdentifier(), $moduleData->toArray());
}
if (!isset($storedModuleData['subModule']) || $storedModuleData['subModule'] !== $requestedSubModule) {
$storedModuleData['subModule'] = $requestedSubModule;
$backendUser->pushModuleData('scheduler', $storedModuleData);
}
// Don't further fiddle with backend user module data from here on.
unset($storedModuleData);
$requestedSubModule = (string)$moduleData->get('subModule');

// 'info' and 'check' submodules have no other action and can be rendered directly.
if ($requestedSubModule === 'info') {
Expand All @@ -113,26 +107,26 @@ public function handleRequest(ServerRequestInterface $request): ResponseInterfac
// Simple actions from list view.
if (!empty($parsedBody['action']['toggleHidden'])) {
$this->toggleDisabledFlag($view, (int)$parsedBody['action']['toggleHidden']);
return $this->renderListTasksView($view);
return $this->renderListTasksView($view, $moduleData);
}
if (!empty($queryParams['action']['delete'])) {
// @todo: This should be POST only, but modals on button type="submit" don't trigger and buttons in doc header can't do that, either.
// Compare with 'toggleHidden' solution above which has no modal.
$this->deleteTask($view, (int)$queryParams['action']['delete']);
return $this->renderListTasksView($view);
return $this->renderListTasksView($view, $moduleData);
}
if (!empty($queryParams['action']['stop'])) {
// @todo: Same as above.
$this->stopTask($view, (int)$queryParams['action']['stop']);
return $this->renderListTasksView($view);
return $this->renderListTasksView($view, $moduleData);
}
if (!empty($parsedBody['execute'])) {
$this->executeTasks($view, (string)$parsedBody['execute']);
return $this->renderListTasksView($view);
return $this->renderListTasksView($view, $moduleData);
}
if (!empty($parsedBody['scheduleCron'])) {
$this->scheduleCrons($view, (string)$parsedBody['scheduleCron']);
return $this->renderListTasksView($view);
return $this->renderListTasksView($view, $moduleData);
}

if (($parsedBody['action'] ?? '') === Action::ADD
Expand All @@ -148,7 +142,7 @@ public function handleRequest(ServerRequestInterface $request): ResponseInterfac
return $this->renderAddTaskFormView($view, $request);
}
if ($parsedBody['CMD'] === 'saveclose') {
return $this->renderListTasksView($view);
return $this->renderListTasksView($view, $moduleData);
}
if ($parsedBody['CMD'] === 'save') {
return $this->renderEditTaskFormView($view, $request, $newTaskUid);
Expand All @@ -168,7 +162,7 @@ public function handleRequest(ServerRequestInterface $request): ResponseInterfac
return $this->renderAddTaskFormView($view, $request);
}
if ($parsedBody['CMD'] === 'saveclose') {
return $this->renderListTasksView($view);
return $this->renderListTasksView($view, $moduleData);
}
if ($parsedBody['CMD'] === 'save') {
return $this->renderEditTaskFormView($view, $request);
Expand All @@ -184,7 +178,7 @@ public function handleRequest(ServerRequestInterface $request): ResponseInterfac
}

// Render list if no other action kicked in.
return $this->renderListTasksView($view);
return $this->renderListTasksView($view, $moduleData);
}

/**
Expand Down Expand Up @@ -468,6 +462,7 @@ protected function renderEditTaskFormView(ModuleTemplate $view, ServerRequestInt
$languageService = $this->getLanguageService();
$registeredClasses = $this->getRegisteredClasses();
$parsedBody = $request->getParsedBody()['tx_scheduler'] ?? [];
$moduleData = $request->getAttribute('moduleData');
$taskUid = (int)($taskUid ?? $request->getQueryParams()['uid'] ?? $parsedBody['uid'] ?? 0);
if (empty($taskUid)) {
throw new \RuntimeException('No valid task uid given to edit task', 1641720929);
Expand All @@ -478,13 +473,13 @@ protected function renderEditTaskFormView(ModuleTemplate $view, ServerRequestInt
} catch (\OutOfBoundsException $e) {
// Task not found - removed meanwhile?
$this->addMessage($view, sprintf($languageService->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:msg.taskNotFound'), $taskUid), AbstractMessage::ERROR);
return $this->renderListTasksView($view);
return $this->renderListTasksView($view, $moduleData);
}

if (!empty($taskRecord['serialized_executions'])) {
// If there's a registered execution, the task should not be edited. May happen if a cron started the task meanwhile.
$this->addMessage($view, $languageService->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:msg.maynotEditRunningTask'), AbstractMessage::ERROR);
return $this->renderListTasksView($view);
return $this->renderListTasksView($view, $moduleData);
}

$task = null;
Expand All @@ -500,7 +495,7 @@ protected function renderEditTaskFormView(ModuleTemplate $view, ServerRequestInt
if ($isInvalidTask || !isset($registeredClasses[$class]) || !$this->scheduler->isValidTaskObject($task)) {
// The task object is not valid anymore. Add flash message and go back to list view.
$this->addMessage($view, sprintf($languageService->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang.xlf:msg.invalidTaskClassEdit'), $class), AbstractMessage::ERROR);
return $this->renderListTasksView($view);
return $this->renderListTasksView($view, $moduleData);
}

$taskExecution = $task->getExecution();
Expand Down Expand Up @@ -631,11 +626,10 @@ protected function scheduleCrons(ModuleTemplate $view, string $taskUids): void
/**
* Assemble display of list of scheduled tasks
*/
protected function renderListTasksView(ModuleTemplate $view): ResponseInterface
protected function renderListTasksView(ModuleTemplate $view, ModuleData $moduleData): ResponseInterface
{
$languageService = $this->getLanguageService();
$registeredClasses = $this->getRegisteredClasses();
$schedulerModuleData = $this->getBackendUser()->getModuleData('scheduler') ?? [];

// Get all registered tasks
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_scheduler_task');
Expand Down Expand Up @@ -727,7 +721,7 @@ protected function renderListTasksView(ModuleTemplate $view): ResponseInterface
'tasks' => [],
'groupName' => $row['taskGroupName'],
'groupDescription' => $row['taskGroupDescription'],
'taskGroupCollapsed' => (bool)($schedulerModuleData['task-group-' . $row['taskGroupId']] ?? false),
'taskGroupCollapsed' => (bool)($moduleData->get('task-group-' . ($row['taskGroupId'] ?? 0), false)),
];
}
$taskGroupsWithTasks[(int)$row['task_group']]['tasks'][] = $taskData;
Expand All @@ -737,7 +731,7 @@ protected function renderListTasksView(ModuleTemplate $view): ResponseInterface
'tasks' => $taskGroupsWithTasks,
'now' => $this->context->getAspect('date')->get('timestamp'),
'errorClasses' => $errorClasses,
'errorClassesCollapsed' => (bool)($schedulerModuleData['task-group-missing'] ?? false),
'errorClassesCollapsed' => (bool)($moduleData->get('task-group-missing', false)),
]);
$view->setTitle(
$languageService->sL('LLL:EXT:scheduler/Resources/Private/Language/locallang_mod.xlf:mlang_tabs_tab'),
Expand Down
3 changes: 3 additions & 0 deletions typo3/sysext/scheduler/Configuration/Backend/Modules.php
Expand Up @@ -17,5 +17,8 @@
'target' => SchedulerModuleController::class . '::handleRequest',
],
],
'moduleData' => [
'subModule' => 'scheduler',
],
],
];

0 comments on commit a3b3e60

Please sign in to comment.