[FEATURE] Add a disable/enable button to tasks overview 18/18018/4
authorThomas Löffler <loeffler@spooner-web.de>
Mon, 4 Feb 2013 23:09:59 +0000 (00:09 +0100)
committerIngo Renner <ingo@typo3.org>
Tue, 5 Feb 2013 20:21:00 +0000 (21:21 +0100)
Adds an option in the task list to enable or disable
a scheduler task.

Releases: 6.1
Resolves: #25631
Change-Id: I6bd38be3207c9ccc59baf653a2da16bdf824ceab
Reviewed-on: https://review.typo3.org/18018
Reviewed-by: Philipp Gampe
Tested-by: Philipp Gampe
Reviewed-by: Thomas Loeffler
Tested-by: Thomas Loeffler
Reviewed-by: Stefan Neufeind
Reviewed-by: Ingo Renner
Tested-by: Ingo Renner
typo3/sysext/scheduler/Classes/Controller/SchedulerModuleController.php
typo3/sysext/scheduler/mod1/locallang.xlf

index 3de68dc..c10b436 100644 (file)
@@ -209,6 +209,14 @@ class SchedulerModuleController extends \TYPO3\CMS\Backend\Module\BaseScriptClas
                                $this->stopTask();
                                $content .= $this->listTasks();
                                break;
+                       case 'enable':
+                               $this->enableTask();
+                               $content .= $this->listTasks();
+                               break;
+                       case 'disable':
+                               $this->disableTask();
+                               $content .= $this->listTasks();
+                               break;
                        case 'list':
 
                        default:
@@ -533,6 +541,57 @@ class SchedulerModuleController extends \TYPO3\CMS\Backend\Module\BaseScriptClas
        }
 
        /**
+        * Activates the task
+        *
+        * @return void
+        */
+       protected function enableTask() {
+               try {
+                       // Try to fetch the task and activate it
+                       $task = $this->scheduler->fetchTask($this->submittedData['uid']);
+                       if ($task->isDisabled()) {
+                               $task->setDisabled(FALSE);
+                               if (!$task->getExecution()->getMultiple()) {
+                                       $task->setExecutionTime(time());
+                               }
+                               $task->save();
+                               $this->addMessage($GLOBALS['LANG']->getLL('msg.enableSuccess'));
+                       } else {
+                               // The task is enable, nothing to enable
+                               $this->addMessage($GLOBALS['LANG']->getLL('msg.maynotEnableEnabledTask'), \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING);
+                       }
+               } catch (\Exception $e) {
+                       // The task was not found, for some reason
+                       $this->addMessage(sprintf($GLOBALS['LANG']->getLL('msg.taskNotFound'), $this->submittedData['uid']), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
+               }
+       }
+
+       /**
+        * Disables the task
+        *
+        * @return void
+        */
+       protected function disableTask() {
+               try {
+                       // Try to fetch the task and disable it
+                       $task = $this->scheduler->fetchTask($this->submittedData['uid']);
+                       if ($task->isExecutionRunning()) {
+                               $this->addMessage($GLOBALS['LANG']->getLL('msg.maynotDisableRunningTask'), \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING);
+                       } elseif (!$task->isDisabled()) {
+                               $task->setDisabled(TRUE);
+                               $task->save();
+                               $this->addMessage($GLOBALS['LANG']->getLL('msg.disableSuccess'));
+                       } else {
+                               // The task is disabled, nothing to disable
+                               $this->addMessage($GLOBALS['LANG']->getLL('msg.maynotDisableDisabledTask'), \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING);
+                       }
+               } catch (\Exception $e) {
+                       // The task was not found, for some reason
+                       $this->addMessage(sprintf($GLOBALS['LANG']->getLL('msg.taskNotFound'), $this->submittedData['uid']), \TYPO3\CMS\Core\Messaging\FlashMessage::ERROR);
+               }
+       }
+
+       /**
         * Return a form to add a new task or edit an existing one
         *
         * @return      string  HTML form to add or edit a task
@@ -886,7 +945,7 @@ class SchedulerModuleController extends \TYPO3\CMS\Backend\Module\BaseScriptClas
                                '0' => array(
                                        'tr' => array('<tr class="t3-row-header">', '</tr>'),
                                        'defCol' => array('<td>', '</td>'),
-                                       '1' => array('<td style="width: 36px;">', '</td>'),
+                                       '1' => array('<td style="width: 56px;">', '</td>'),
                                        '3' => array('<td colspan="2">', '</td>')
                                ),
                                'defRow' => array(
@@ -928,6 +987,8 @@ class SchedulerModuleController extends \TYPO3\CMS\Backend\Module\BaseScriptClas
                                $editAction = '<a href="' . $GLOBALS['MCONF']['_'] . '&CMD=edit&tx_scheduler[uid]=' . $schedulerRecord['uid'] . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:edit', TRUE) . '" class="icon">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-document-open') . '</a>';
                                $deleteAction = '<a href="' . $GLOBALS['MCONF']['_'] . '&CMD=delete&tx_scheduler[uid]=' . $schedulerRecord['uid'] . '" onclick="return confirm(\'' . $GLOBALS['LANG']->getLL('msg.delete') . '\');" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:delete', TRUE) . '" class="icon">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-edit-delete') . '</a>';
                                $stopAction = '<a href="' . $GLOBALS['MCONF']['_'] . '&CMD=stop&tx_scheduler[uid]=' . $schedulerRecord['uid'] . '" onclick="return confirm(\'' . $GLOBALS['LANG']->getLL('msg.stop') . '\');" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:stop', TRUE) . '" class="icon"><img ' . \TYPO3\CMS\Backend\Utility\IconUtility::skinImg($this->backPath, (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath('scheduler') . '/res/gfx/stop.png')) . ' alt="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:stop') . '" /></a>';
+                               $enableAction = '<a href="' . $GLOBALS['MCONF']['_'] . '&CMD=enable&tx_scheduler[uid]=' . $schedulerRecord['uid'] . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:activate', TRUE) . '" class="icon">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-edit-unhide') . '</a>';
+                               $disableAction = '<a href="' . $GLOBALS['MCONF']['_'] . '&CMD=disable&tx_scheduler[uid]=' . $schedulerRecord['uid'] . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:deactivate', TRUE) . '" class="icon">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-edit-hide') . '</a>';
                                // Define some default values
                                $lastExecution = '-';
                                $isRunning = FALSE;
@@ -1019,6 +1080,9 @@ class SchedulerModuleController extends \TYPO3\CMS\Backend\Module\BaseScriptClas
                                        if ($schedulerRecord['disable'] == 1 && !$isRunning) {
                                                $tableLayout[$tr] = $disabledTaskRow;
                                                $executionStatus = 'disabled';
+                                               $actions .= $enableAction;
+                                       } elseif (!$isRunning) {
+                                               $actions .= $disableAction;
                                        }
                                        // Check if the last run failed
                                        $failureOutput = '';
@@ -1396,7 +1460,7 @@ class SchedulerModuleController extends \TYPO3\CMS\Backend\Module\BaseScriptClas
                        'reload' => '',
                        'shortcut' => $this->getShortcutButton()
                );
-               if (empty($this->CMD) || $this->CMD == 'list' || $this->CMD == 'delete') {
+               if (empty($this->CMD) || $this->CMD == 'list' || $this->CMD == 'delete' || $this->CMD == 'enable' || $this->CMD == 'disable') {
                        $buttons['reload'] = '<a href="' . $GLOBALS['MCONF']['_'] . '" title="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_core.php:labels.reload', TRUE) . '">' . \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIcon('actions-system-refresh') . '</a>';
                        if ($this->MOD_SETTINGS['function'] === 'scheduler' && count(self::getRegisteredClasses())) {
                                $link = $GLOBALS['MCONF']['_'] . '&CMD=add';
index eada08c..116ce0c 100644 (file)
                        <trans-unit id="msg.maynotEditRunningTask" xml:space="preserve">
                                <source>A running task may not be edited.</source>
                        </trans-unit>
+                       <trans-unit id="msg.maynotDisableRunningTask" xml:space="preserve">
+                               <source>A running task may not be disabled.</source>
+                       </trans-unit>
                        <trans-unit id="msg.maynotStopNonRunningTask" xml:space="preserve">
                                <source>The task is not running. There are no executions to unmark.</source>
                        </trans-unit>
+                       <trans-unit id="msg.maynotEnableEnabledTask" xml:space="preserve">
+                               <source>The task is enabled. There is no need to enable it.</source>
+                       </trans-unit>
+                       <trans-unit id="msg.maynotDisableDisabledTask" xml:space="preserve">
+                               <source>The task is disabled. There is no need to disable it.</source>
+                       </trans-unit>
                        <trans-unit id="msg.noEmail" xml:space="preserve">
                                <source>Please enter an email address.</source>
                        </trans-unit>
                        <trans-unit id="msg.stopSuccess" xml:space="preserve">
                                <source>The task was successfully marked as non-running.</source>
                        </trans-unit>
+                       <trans-unit id="msg.enableSuccess" xml:space="preserve">
+                               <source>The task was successfully marked as enabled.</source>
+                       </trans-unit>
+                       <trans-unit id="msg.disableSuccess" xml:space="preserve">
+                               <source>The task was successfully marked as disabled.</source>
+                       </trans-unit>
                        <trans-unit id="msg.taskNotFound" xml:space="preserve">
                                <source>The requested task (UID: %d) was not found.</source>
                        </trans-unit>