Skip to content
Snippets Groups Projects
Commit d72b27c5 authored by Thomas Hohn's avatar Thomas Hohn Committed by Stefan B�rk
Browse files

[!!!][TASK] Convert Action to backed enum

This change converts class Action to a native backed enum.
In addition it's moved to namespace \TYPO3\CMS\Scheduler\ and
renamed to SchedulerManagementAction.

Resolves: #101129
Releases: main
Change-Id: I3752754b021a75cb9873806cb670d1adbc20fce4
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/79476


Tested-by: default avatarAlexander Schnitzler <git@alexanderschnitzler.de>
Reviewed-by: default avatarOliver Klee <typo3-coding@oliverklee.de>
Tested-by: default avatarBenni Mack <benni@typo3.org>
Tested-by: default avatarStefan B�rk <stefan@buerk.tech>
Reviewed-by: default avatarStefan B�rk <stefan@buerk.tech>
Tested-by: default avatarcore-ci <typo3@b13.com>
Reviewed-by: default avatarAlexander Schnitzler <git@alexanderschnitzler.de>
Reviewed-by: default avatarBenni Mack <benni@typo3.org>
parent 933dab53
Branches
Tags
No related merge requests found
Showing
with 108 additions and 54 deletions
.. include:: /Includes.rst.txt
.. _breaking-Action-1687355374:
========================================================
Breaking: #101129 - Convert Action to native backed enum
========================================================
See :issue:`101129`
Description
===========
The class :php:`\TYPO3\CMS\Scheduler\Task\Enumeration\Action` is now
converted to a native backed enum. In addition the class is moved to
the namespace :php:`\TYPO3\CMS\Scheduler\` and renamed to
SchedulerManagementAction.
Impact
======
Since :php:`\TYPO3\CMS\Scheduler\Task\Enumeration\Action` is no longer
a class, the existing class constants are no longer available.
In addition it's not possible to instantiate it anymore.
Affected installations
======================
Third-party extensions using the following class constants:
- :php:`\TYPO3\CMS\Scheduler\Task\Enumeration\Action::ADD`
- :php:`\TYPO3\CMS\Scheduler\Task\Enumeration\Action::EDIT`
- :php:`\TYPO3\CMS\Scheduler\Task\Enumeration\Action::LIST`
Class instantiation:
- :php:`new Action('a-string')`
Migration
=========
Include enum :php:`SchedulerManagementAction` from namespace :php:`\TYPO3\CMS\Scheduler\`
as a replacement for :php:`Action`
Use the new syntax
- :php:`\TYPO3\CMS\Scheduler\SchedulerManagementAction::ADD`
- :php:`\TYPO3\CMS\Scheduler\SchedulerManagementAction::EDIT`
- :php:`\TYPO3\CMS\Scheduler\SchedulerManagementAction::LIST`
as well as the :php:`tryFrom($aString)` static method of the Backed enum.
.. index:: Backend, NotScanned, ext:linkvalidator, ext:recycler, ext:reports, ext:scheduler
......@@ -23,8 +23,8 @@ use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Scheduler\AbstractAdditionalFieldProvider;
use TYPO3\CMS\Scheduler\Controller\SchedulerModuleController;
use TYPO3\CMS\Scheduler\SchedulerManagementAction;
use TYPO3\CMS\Scheduler\Task\AbstractTask;
use TYPO3\CMS\Scheduler\Task\Enumeration\Action;
/**
* This class provides Scheduler Additional Field plugin implementation
......@@ -55,63 +55,63 @@ class ValidatorTaskAdditionalFieldProvider extends AbstractAdditionalFieldProvid
$lang = $this->getLanguageService();
if (empty($taskInfo['configuration'])) {
if ($currentSchedulerModuleAction->equals(Action::ADD)) {
if ($currentSchedulerModuleAction === SchedulerManagementAction::ADD) {
$taskInfo['configuration'] = $taskInfo['linkvalidator']['configuration'] ?? '';
} elseif ($currentSchedulerModuleAction->equals(Action::EDIT)) {
} elseif ($currentSchedulerModuleAction === SchedulerManagementAction::EDIT) {
$taskInfo['configuration'] = $task->getConfiguration();
} else {
$taskInfo['configuration'] = $task->getConfiguration();
}
}
if (empty($taskInfo['depth'])) {
if ($currentSchedulerModuleAction->equals(Action::ADD)) {
if ($currentSchedulerModuleAction === SchedulerManagementAction::ADD) {
$taskInfo['depth'] = $taskInfo['linkvalidator']['depth'] ?? 0;
} elseif ($currentSchedulerModuleAction->equals(Action::EDIT)) {
} elseif ($currentSchedulerModuleAction === SchedulerManagementAction::EDIT) {
$taskInfo['depth'] = $task->getDepth();
} else {
$taskInfo['depth'] = $task->getDepth();
}
}
if (empty($taskInfo['page'])) {
if ($currentSchedulerModuleAction->equals(Action::ADD)) {
if ($currentSchedulerModuleAction === SchedulerManagementAction::ADD) {
$taskInfo['page'] = $taskInfo['linkvalidator']['page'] ?? 0;
} elseif ($currentSchedulerModuleAction->equals(Action::EDIT)) {
} elseif ($currentSchedulerModuleAction === SchedulerManagementAction::EDIT) {
$taskInfo['page'] = $task->getPage();
} else {
$taskInfo['page'] = $task->getPage();
}
}
if (empty($taskInfo['languages'])) {
if ($currentSchedulerModuleAction->equals(Action::ADD)) {
if ($currentSchedulerModuleAction === SchedulerManagementAction::ADD) {
$taskInfo['languages'] = $taskInfo['linkvalidator']['languages'] ?? '';
} elseif ($currentSchedulerModuleAction->equals(Action::EDIT)) {
} elseif ($currentSchedulerModuleAction === SchedulerManagementAction::EDIT) {
$taskInfo['languages'] = $task->getLanguages();
} else {
$taskInfo['languages'] = $task->getLanguages();
}
}
if (empty($taskInfo['email'])) {
if ($currentSchedulerModuleAction->equals(Action::ADD)) {
if ($currentSchedulerModuleAction === SchedulerManagementAction::ADD) {
$taskInfo['email'] = $taskInfo['linkvalidator']['email'] ?? '';
} elseif ($currentSchedulerModuleAction->equals(Action::EDIT)) {
} elseif ($currentSchedulerModuleAction === SchedulerManagementAction::EDIT) {
$taskInfo['email'] = $task->getEmail();
} else {
$taskInfo['email'] = $task->getEmail();
}
}
if (empty($taskInfo['emailOnBrokenLinkOnly'])) {
if ($currentSchedulerModuleAction->equals(Action::ADD)) {
if ($currentSchedulerModuleAction === SchedulerManagementAction::ADD) {
$taskInfo['emailOnBrokenLinkOnly'] = ($taskInfo['linkvalidator']['emailOnBrokenLinkOnly'] ?? false) ? (bool)$taskInfo['linkvalidator']['emailOnBrokenLinkOnly'] : true;
} elseif ($currentSchedulerModuleAction->equals(Action::EDIT)) {
} elseif ($currentSchedulerModuleAction === SchedulerManagementAction::EDIT) {
$taskInfo['emailOnBrokenLinkOnly'] = $task->getEmailOnBrokenLinkOnly();
} else {
$taskInfo['emailOnBrokenLinkOnly'] = $task->getEmailOnBrokenLinkOnly();
}
}
if (empty($taskInfo['emailTemplateName'])) {
if ($currentSchedulerModuleAction->equals(Action::ADD)) {
if ($currentSchedulerModuleAction === SchedulerManagementAction::ADD) {
$taskInfo['emailTemplateName'] = ($taskInfo['linkvalidator']['emailTemplateName'] ?? false) ? $taskInfo['linkvalidator']['emailTemplateName'] : '';
} elseif ($currentSchedulerModuleAction->equals(Action::EDIT)) {
} elseif ($currentSchedulerModuleAction === SchedulerManagementAction::EDIT) {
$taskInfo['emailTemplateName'] = $task->getEmailTemplateName();
} else {
$taskInfo['emailTemplateName'] = $task->getEmailTemplateName();
......
......@@ -19,8 +19,8 @@ use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
use TYPO3\CMS\Scheduler\AbstractAdditionalFieldProvider;
use TYPO3\CMS\Scheduler\Controller\SchedulerModuleController;
use TYPO3\CMS\Scheduler\SchedulerManagementAction;
use TYPO3\CMS\Scheduler\Task\AbstractTask;
use TYPO3\CMS\Scheduler\Task\Enumeration\Action;
/**
* A task that should be run regularly that deletes
......@@ -41,7 +41,7 @@ class CleanerFieldProvider extends AbstractAdditionalFieldProvider
{
$currentSchedulerModuleAction = $schedulerModule->getCurrentAction();
if ($currentSchedulerModuleAction->equals(Action::EDIT)) {
if ($currentSchedulerModuleAction === SchedulerManagementAction::EDIT) {
$taskInfo['RecyclerCleanerTCA'] = $task->getTcaTables();
$taskInfo['RecyclerCleanerPeriod'] = $task->getPeriod();
}
......
......@@ -20,8 +20,8 @@ use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Scheduler\AbstractAdditionalFieldProvider;
use TYPO3\CMS\Scheduler\Controller\SchedulerModuleController;
use TYPO3\CMS\Scheduler\SchedulerManagementAction;
use TYPO3\CMS\Scheduler\Task\AbstractTask;
use TYPO3\CMS\Scheduler\Task\Enumeration\Action;
/**
* Additional field to set the notification email address(es) for system health
......@@ -56,7 +56,7 @@ class SystemStatusUpdateTaskNotificationEmailField extends AbstractAdditionalFie
{
$currentSchedulerModuleAction = $schedulerModule->getCurrentAction();
if ($currentSchedulerModuleAction->equals(Action::EDIT)) {
if ($currentSchedulerModuleAction === SchedulerManagementAction::EDIT) {
$taskInfo[$this->fieldPrefix . 'NotificationEmail'] = $task->getNotificationEmail();
$taskInfo[$this->fieldPrefix . 'NotificationAll'] = $task->getNotificationAll();
}
......
......@@ -43,9 +43,9 @@ use TYPO3\CMS\Scheduler\Domain\Repository\SchedulerTaskRepository;
use TYPO3\CMS\Scheduler\Exception\InvalidDateException;
use TYPO3\CMS\Scheduler\Exception\InvalidTaskException;
use TYPO3\CMS\Scheduler\Scheduler;
use TYPO3\CMS\Scheduler\SchedulerManagementAction;
use TYPO3\CMS\Scheduler\Service\TaskService;
use TYPO3\CMS\Scheduler\Task\AbstractTask;
use TYPO3\CMS\Scheduler\Task\Enumeration\Action;
use TYPO3\CMS\Scheduler\Task\TaskSerializer;
use TYPO3\CMS\Scheduler\Validation\Validator\TaskValidator;
......@@ -57,7 +57,7 @@ use TYPO3\CMS\Scheduler\Validation\Validator\TaskValidator;
#[BackendController]
final class SchedulerModuleController
{
protected Action $currentAction;
protected SchedulerManagementAction $currentAction;
public function __construct(
protected readonly Scheduler $scheduler,
......@@ -132,7 +132,9 @@ final class SchedulerModuleController
return $this->renderListTasksView($view, $moduleData);
}
if (($parsedBody['action'] ?? '') === Action::ADD
$parsedAction = SchedulerManagementAction::tryFrom($parsedBody['action'] ?? '') ?? SchedulerManagementAction::LIST;
if ($parsedAction === SchedulerManagementAction::ADD
&& in_array($parsedBody['CMD'] ?? '', ['save', 'saveclose', 'close'], true)
) {
// Received data for adding a new task - validate, persist, render requested 'next' action.
......@@ -152,7 +154,7 @@ final class SchedulerModuleController
}
}
if (($parsedBody['action'] ?? '') === Action::EDIT
if ($parsedAction === SchedulerManagementAction::EDIT
&& in_array($parsedBody['CMD'] ?? '', ['save', 'close', 'saveclose', 'new'], true)
) {
// Received data for updating existing task - validate, persist, render requested 'next' action.
......@@ -175,11 +177,12 @@ final class SchedulerModuleController
}
}
$queryAction = SchedulerManagementAction::tryFrom($queryParams['action'] ?? '') ?? SchedulerManagementAction::LIST;
// Add new task form / edit existing task form.
if (($queryParams['action'] ?? '') === Action::ADD) {
if ($queryAction === SchedulerManagementAction::ADD) {
return $this->renderAddTaskFormView($view, $request);
}
if (($queryParams['action'] ?? '') === Action::EDIT) {
if ($queryAction === SchedulerManagementAction::EDIT) {
return $this->renderEditTaskFormView($view, $request);
}
......@@ -190,7 +193,7 @@ final class SchedulerModuleController
/**
* This is (unfortunately) used by additional field providers to distinct between "create new task" and "edit task".
*/
public function getCurrentAction(): Action
public function getCurrentAction(): SchedulerManagementAction
{
return $this->currentAction;
}
......@@ -348,7 +351,7 @@ final class SchedulerModuleController
ksort($groupedClasses);
// Additional field provider access $this->getCurrentAction() - Init it for them
$this->currentAction = new Action(Action::ADD);
$this->currentAction = SchedulerManagementAction::ADD;
// Get the extra fields to display for each task that needs some.
$additionalFields = [];
foreach ($registeredClasses as $class => $registrationInfo) {
......@@ -451,7 +454,7 @@ final class SchedulerModuleController
];
// Additional field provider access $this->getCurrentAction() - Init it for them
$this->currentAction = new Action(Action::EDIT);
$this->currentAction = SchedulerManagementAction::EDIT;
$additionalFields = [];
if (!empty($registeredClasses[$class]['provider'])) {
$providerObject = GeneralUtility::makeInstance($registeredClasses[$class]['provider']);
......
......@@ -15,18 +15,15 @@ declare(strict_types=1);
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Scheduler\Task\Enumeration;
use TYPO3\CMS\Core\Type\Enumeration;
namespace TYPO3\CMS\Scheduler;
/**
* List of possible scheduler actions. Additional field providers use this.
* Set by SchedulerModuleController.
* Used by SchedulerModuleController.
*/
final class Action extends Enumeration
enum SchedulerManagementAction: string
{
public const __default = self::LIST;
public const ADD = 'add';
public const EDIT = 'edit';
public const LIST = 'list';
case ADD = 'add';
case EDIT = 'edit';
case LIST = 'list';
}
......@@ -20,7 +20,7 @@ use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
use TYPO3\CMS\Scheduler\AbstractAdditionalFieldProvider;
use TYPO3\CMS\Scheduler\Controller\SchedulerModuleController;
use TYPO3\CMS\Scheduler\Task\Enumeration\Action;
use TYPO3\CMS\Scheduler\SchedulerManagementAction;
/**
* Additional BE fields for caching framework garbage collection task.
......@@ -44,12 +44,12 @@ class CachingFrameworkGarbageCollectionAdditionalFieldProvider extends AbstractA
// Initialize selected fields
if (empty($taskInfo['scheduler_cachingFrameworkGarbageCollection_selectedBackends'])) {
$taskInfo['scheduler_cachingFrameworkGarbageCollection_selectedBackends'] = [];
if ($currentSchedulerModuleAction->equals(Action::ADD)) {
if ($currentSchedulerModuleAction === SchedulerManagementAction::ADD) {
// In case of new task, set to dbBackend if it's available
if (in_array(Typo3DatabaseBackend::class, $this->getRegisteredBackends())) {
$taskInfo['scheduler_cachingFrameworkGarbageCollection_selectedBackends'][] = Typo3DatabaseBackend::class;
}
} elseif ($currentSchedulerModuleAction->equals(Action::EDIT)) {
} elseif ($currentSchedulerModuleAction === SchedulerManagementAction::EDIT) {
// In case of editing the task, set to currently selected value
$taskInfo['scheduler_cachingFrameworkGarbageCollection_selectedBackends'] = $task->selectedBackends;
}
......
......@@ -19,7 +19,7 @@ use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
use TYPO3\CMS\Scheduler\AbstractAdditionalFieldProvider;
use TYPO3\CMS\Scheduler\Controller\SchedulerModuleController;
use TYPO3\CMS\Scheduler\Task\Enumeration\Action;
use TYPO3\CMS\Scheduler\SchedulerManagementAction;
/**
* Additional BE fields for ip address anonymization task.
......@@ -59,11 +59,11 @@ class IpAnonymizationAdditionalFieldProvider extends AbstractAdditionalFieldProv
$options = [];
// Add an empty option on top if an existing task is configured
// with a table that can not be found in configuration anymore
if ($task && !array_key_exists($task->table, $tableConfiguration) && $currentSchedulerModuleAction->equals(Action::EDIT)) {
if ($task && !array_key_exists($task->table, $tableConfiguration) && $currentSchedulerModuleAction === SchedulerManagementAction::EDIT) {
$options[] = '<option value="" selected="selected"></option>';
}
foreach ($tableConfiguration as $tableName => $configuration) {
if ($currentSchedulerModuleAction->equals(Action::ADD) && empty($options)) {
if ($currentSchedulerModuleAction === SchedulerManagementAction::ADD && empty($options)) {
// Select first table by default if adding a new task
$options[] = '<option value="' . $tableName . '" selected="selected">' . $tableName . '</option>';
} elseif ($task && $task->table === $tableName) {
......
......@@ -22,7 +22,7 @@ use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Scheduler\AbstractAdditionalFieldProvider;
use TYPO3\CMS\Scheduler\Controller\SchedulerModuleController;
use TYPO3\CMS\Scheduler\Task\Enumeration\Action;
use TYPO3\CMS\Scheduler\SchedulerManagementAction;
/**
* Additional BE fields for optimize database table task.
......@@ -50,10 +50,10 @@ class OptimizeDatabaseTableAdditionalFieldProvider extends AbstractAdditionalFie
// Initialize selected fields
if (empty($taskInfo['scheduler_optimizeDatabaseTables_selectedTables'])) {
$taskInfo['scheduler_optimizeDatabaseTables_selectedTables'] = [];
if ($currentSchedulerModuleAction->equals(Action::ADD)) {
if ($currentSchedulerModuleAction === SchedulerManagementAction::ADD) {
// In case of new task, select no tables by default
$taskInfo['scheduler_optimizeDatabaseTables_selectedTables'] = [];
} elseif ($currentSchedulerModuleAction->equals(Action::EDIT)) {
} elseif ($currentSchedulerModuleAction === SchedulerManagementAction::EDIT) {
// In case of editing the task, set to currently selected value
$taskInfo['scheduler_optimizeDatabaseTables_selectedTables'] = $task->selectedTables;
}
......
......@@ -19,7 +19,7 @@ use TYPO3\CMS\Core\Localization\LanguageService;
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
use TYPO3\CMS\Scheduler\AbstractAdditionalFieldProvider;
use TYPO3\CMS\Scheduler\Controller\SchedulerModuleController;
use TYPO3\CMS\Scheduler\Task\Enumeration\Action;
use TYPO3\CMS\Scheduler\SchedulerManagementAction;
/**
* Additional BE fields for recycler garbage collection task.
......@@ -53,7 +53,7 @@ class RecyclerGarbageCollectionAdditionalFieldProvider extends AbstractAdditiona
// Initialize selected fields
if (!isset($taskInfo['scheduler_recyclerGarbageCollection_numberOfDays'])) {
$taskInfo['scheduler_recyclerGarbageCollection_numberOfDays'] = $this->defaultNumberOfDays;
if ($currentSchedulerModuleAction->equals(Action::EDIT)) {
if ($currentSchedulerModuleAction === SchedulerManagementAction::EDIT) {
$taskInfo['scheduler_recyclerGarbageCollection_numberOfDays'] = $task->numberOfDays;
}
}
......
......@@ -20,7 +20,7 @@ use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Scheduler\AbstractAdditionalFieldProvider;
use TYPO3\CMS\Scheduler\Controller\SchedulerModuleController;
use TYPO3\CMS\Scheduler\Task\Enumeration\Action;
use TYPO3\CMS\Scheduler\SchedulerManagementAction;
/**
* Additional BE fields for sys log table garbage collection task.
......@@ -76,7 +76,7 @@ class TableGarbageCollectionAdditionalFieldProvider extends AbstractAdditionalFi
{
$currentSchedulerModuleAction = $schedulerModule->getCurrentAction();
if ($currentSchedulerModuleAction->equals(Action::EDIT)) {
if ($currentSchedulerModuleAction === SchedulerManagementAction::EDIT) {
$checked = $task->allTables === true ? 'checked="checked" ' : '';
} else {
$checked = '';
......@@ -112,11 +112,11 @@ class TableGarbageCollectionAdditionalFieldProvider extends AbstractAdditionalFi
$options = [];
// Add an empty option on top if an existing task is configured
// with a table that can not be found in configuration anymore
if ($task && !array_key_exists($task->table, $tableConfiguration) && $currentSchedulerModuleAction->equals(Action::EDIT)) {
if ($task && !array_key_exists($task->table, $tableConfiguration) && $currentSchedulerModuleAction === SchedulerManagementAction::EDIT) {
$options[] = '<option value="" selected="selected"></option>';
}
foreach ($tableConfiguration as $tableName => $configuration) {
if ($currentSchedulerModuleAction->equals(Action::ADD) && empty($options)) {
if ($currentSchedulerModuleAction === SchedulerManagementAction::ADD && empty($options)) {
// Select first table by default if adding a new task
$options[] = '<option value="' . $tableName . '" selected="selected">' . $tableName . '</option>';
} elseif ($task && $task->table === $tableName) {
......@@ -158,10 +158,10 @@ class TableGarbageCollectionAdditionalFieldProvider extends AbstractAdditionalFi
// Initialize selected fields
$disabled = '';
if (empty($taskInfo['scheduler_tableGarbageCollection_numberOfDays'])) {
if ($currentSchedulerModuleAction->equals(Action::ADD)) {
if ($currentSchedulerModuleAction === SchedulerManagementAction::ADD) {
// In case of new task, set to 180 days
$taskInfo['scheduler_tableGarbageCollection_numberOfDays'] = 180;
} elseif ($currentSchedulerModuleAction->equals(Action::EDIT)) {
} elseif ($currentSchedulerModuleAction === SchedulerManagementAction::EDIT) {
// In case of editing the task, set to currently selected value
$taskInfo['scheduler_tableGarbageCollection_numberOfDays'] = $task->numberOfDays;
if ($task->numberOfDays === 0 && !isset($this->defaultNumberOfDays[$task->table])) {
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment