[BUGFIX] Do not try to fetch additionalFields for invalid tasks 67/55267/2
authorStephan Großberndt <stephan@grossberndt.de>
Sat, 16 Dec 2017 14:57:00 +0000 (15:57 +0100)
committerChristian Kuhn <lolli@schwarzbu.ch>
Thu, 4 Jan 2018 14:20:51 +0000 (15:20 +0100)
A task may be invalid when editing so there is no instance of
AbstractTask in $task. With this patch the SchedulerModuleController no
longer tries to add the additionalFields for that as the
AdditionalFieldProviders expect a valid task object when being called on
edit.

Additionally some cleanup in the PHPDoc of AdditionalFieldProviders is
made to make it clear the given task may be NULL on create.

Resolves: #79141
Releases: master, 8.7
Change-Id: Ia7cf8173e65cfdede89a776cff7615678e4ffb21
Reviewed-on: https://review.typo3.org/55267
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/extbase/Classes/Scheduler/FieldProvider.php
typo3/sysext/linkvalidator/Classes/Task/ValidatorTaskAdditionalFieldProvider.php
typo3/sysext/reports/Classes/Task/SystemStatusUpdateTaskNotificationEmailField.php
typo3/sysext/scheduler/Classes/Controller/SchedulerModuleController.php
typo3/sysext/scheduler/Classes/Task/FileStorageExtractionAdditionalFieldProvider.php

index b65b8d1..78abc40 100644 (file)
@@ -15,6 +15,8 @@ namespace TYPO3\CMS\Extbase\Scheduler;
  */
 
 use TYPO3\CMS\Extbase\Utility\TypeHandlingUtility;
+use TYPO3\CMS\Scheduler\Controller\SchedulerModuleController;
+use TYPO3\CMS\Scheduler\Task\AbstractTask;
 
 /**
  * Field provider for Extbase CommandController Scheduler task
@@ -59,12 +61,12 @@ class FieldProvider implements \TYPO3\CMS\Scheduler\AdditionalFieldProviderInter
      * Render additional information fields within the scheduler backend.
      *
      * @param array &$taskInfo Array information of task to return
-     * @param mixed $task \TYPO3\CMS\Scheduler\Task\AbstractTask or \TYPO3\CMS\Scheduler\Execution instance
-     * @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $schedulerModule Reference to the calling object (BE module of the Scheduler)
+     * @param AbstractTask|null $task When editing, reference to the current task. NULL when adding.
+     * @param SchedulerModuleController $schedulerModule Reference to the calling object (BE module of the Scheduler)
      * @return array Additional fields
      * @see \TYPO3\CMS\Scheduler\AdditionalFieldProvider#getAdditionalFields($taskInfo, $task, $schedulerModule)
      */
-    public function getAdditionalFields(array &$taskInfo, $task, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $schedulerModule)
+    public function getAdditionalFields(array &$taskInfo, $task, SchedulerModuleController $schedulerModule)
     {
         $this->task = $task;
         if ($this->task !== null) {
@@ -86,10 +88,10 @@ class FieldProvider implements \TYPO3\CMS\Scheduler\AdditionalFieldProviderInter
      * Validates additional selected fields
      *
      * @param array &$submittedData
-     * @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $schedulerModule
+     * @param SchedulerModuleController $schedulerModule
      * @return bool
      */
-    public function validateAdditionalFields(array &$submittedData, \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $schedulerModule)
+    public function validateAdditionalFields(array &$submittedData, SchedulerModuleController $schedulerModule)
     {
         return true;
     }
@@ -98,10 +100,10 @@ class FieldProvider implements \TYPO3\CMS\Scheduler\AdditionalFieldProviderInter
      * Saves additional field values
      *
      * @param array $submittedData
-     * @param \TYPO3\CMS\Scheduler\Task\AbstractTask $task
+     * @param AbstractTask $task
      * @return bool
      */
-    public function saveAdditionalFields(array $submittedData, \TYPO3\CMS\Scheduler\Task\AbstractTask $task)
+    public function saveAdditionalFields(array $submittedData, AbstractTask $task)
     {
         $task->setCommandIdentifier($submittedData['task_extbase']['action']);
         $task->setArguments((array)$submittedData['task_extbase']['arguments']);
index 4d77eba..8c6d62c 100644 (file)
@@ -38,7 +38,7 @@ class ValidatorTaskAdditionalFieldProvider implements AdditionalFieldProviderInt
      * Render additional information fields within the scheduler backend.
      *
      * @param array $taskInfo Array information of task to return
-     * @param ValidatorTask $task Task object
+     * @param AbstractTask|null $task The task object being edited. Null when adding a task!
      * @param SchedulerModuleController $schedulerModule Reference to the BE module of the Scheduler
      * @return array Additional fields
      * @see AdditionalFieldProviderInterface->getAdditionalFields($taskInfo, $task, $schedulerModule)
index 4c1b322..f73e252 100644 (file)
@@ -13,6 +13,7 @@ namespace TYPO3\CMS\Reports\Task;
  *
  * The TYPO3 project - inspiring people to share!
  */
+
 use TYPO3\CMS\Core\Messaging\FlashMessage;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Lang\LanguageService;
@@ -44,8 +45,8 @@ class SystemStatusUpdateTaskNotificationEmailField implements AdditionalFieldPro
      * Gets additional fields to render in the form to add/edit a task
      *
      * @param array $taskInfo Values of the fields from the add/edit task form
-     * @param \TYPO3\CMS\Scheduler\Task\AbstractTask $task The task object being edited. Null when adding a task!
-     * @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $schedulerModule Reference to the scheduler backend module
+     * @param AbstractTask|null $task When editing, reference to the current task. NULL when adding.
+     * @param SchedulerModuleController $schedulerModule Reference to the scheduler backend module
      * @return array A two dimensional array, array('Identifier' => array('fieldId' => array('code' => '', 'label' => '', 'cshKey' => '', 'cshLabel' => ''))
      */
     public function getAdditionalFields(array &$taskInfo, $task, SchedulerModuleController $schedulerModule)
@@ -86,7 +87,7 @@ class SystemStatusUpdateTaskNotificationEmailField implements AdditionalFieldPro
      * Validates the additional fields' values
      *
      * @param array $submittedData An array containing the data submitted by the add/edit task form
-     * @param \TYPO3\CMS\Scheduler\Controller\SchedulerModuleController $schedulerModule Reference to the scheduler backend module
+     * @param SchedulerModuleController $schedulerModule Reference to the scheduler backend module
      * @return bool TRUE if validation was ok (or selected class is not relevant), FALSE otherwise
      */
     public function validateAdditionalFields(array &$submittedData, SchedulerModuleController $schedulerModule)
@@ -110,7 +111,7 @@ class SystemStatusUpdateTaskNotificationEmailField implements AdditionalFieldPro
      * Takes care of saving the additional fields' values in the task's object
      *
      * @param array $submittedData An array containing the data submitted by the add/edit task form
-     * @param \TYPO3\CMS\Scheduler\Task\AbstractTask $task Reference to the scheduler backend module
+     * @param AbstractTask $task Reference to the scheduler backend module
      */
     public function saveAdditionalFields(array $submittedData, AbstractTask $task)
     {
index 5166e13..a82d725 100644 (file)
@@ -615,7 +615,7 @@ class SchedulerModuleController extends \TYPO3\CMS\Backend\Module\BaseScriptClas
                 }
             }
         } else {
-            if (!empty($registeredClasses[$taskInfo['class']]['provider'])) {
+            if ($task !== null && !empty($registeredClasses[$taskInfo['class']]['provider'])) {
                 $providerObject = GeneralUtility::getUserObj($registeredClasses[$taskInfo['class']]['provider']);
                 if ($providerObject instanceof \TYPO3\CMS\Scheduler\AdditionalFieldProviderInterface) {
                     $allAdditionalFields[$taskInfo['class']] = $providerObject->getAdditionalFields($taskInfo, $task, $this);
index 9c81372..84884d6 100644 (file)
@@ -50,7 +50,7 @@ class FileStorageExtractionAdditionalFieldProvider implements AdditionalFieldPro
     /**
      * Returns a field configuration including a selectbox for available storages
      *
-     * @param FileStorageExtractionTask $task When editing, reference to the current task object. NULL when adding.
+     * @param FileStorageExtractionTask|null $task When editing, reference to the current task object. NULL when adding.
      * @return array Array containing all the information pertaining to the additional fields
      */
     protected function getAllStoragesField(FileStorageExtractionTask $task = null)
@@ -82,7 +82,7 @@ class FileStorageExtractionAdditionalFieldProvider implements AdditionalFieldPro
     /**
      * Returns a field configuration including an input field for the file count
      *
-     * @param FileStorageExtractionTask $task When editing, reference to the current task object. NULL when adding.
+     * @param FileStorageExtractionTask|null $task When editing, reference to the current task object. NULL when adding.
      * @return array Array containing all the information pertaining to the additional fields
      */
     protected function getFileCountField(FileStorageExtractionTask $task = null)
@@ -104,7 +104,7 @@ class FileStorageExtractionAdditionalFieldProvider implements AdditionalFieldPro
     /**
      * Returns a field configuration telling about the status of registered extractors.
      *
-     * @param FileStorageExtractionTask $task When editing, reference to the current task object. NULL when adding.
+     * @param FileStorageExtractionTask|null $task When editing, reference to the current task object. NULL when adding.
      * @return array Array containing all the information pertaining to the additional fields
      */
     protected function getRegisteredExtractorsField(FileStorageExtractionTask $task = null)
@@ -172,12 +172,12 @@ class FileStorageExtractionAdditionalFieldProvider implements AdditionalFieldPro
      * Save additional field in task
      *
      * @param array $submittedData Contains data submitted by the user
-     * @param \TYPO3\CMS\Scheduler\Task\AbstractTask $task Reference to the current task object
+     * @param AbstractTask $task Reference to the current task object
      * @throws \InvalidArgumentException
      */
-    public function saveAdditionalFields(array $submittedData, \TYPO3\CMS\Scheduler\Task\AbstractTask $task)
+    public function saveAdditionalFields(array $submittedData, AbstractTask $task)
     {
-        if ($task !== null && !$task instanceof FileStorageExtractionTask) {
+        if (!$task instanceof FileStorageExtractionTask) {
             throw new \InvalidArgumentException('Task not of type FileStorageExtractionTask', 1384275698);
         }
         $task->storageUid = (int)$submittedData['scheduler_fileStorageIndexing_storage'];