Feature #12184: Scheduler: Added BE method to mark a stalled / died task as not running
authorFrancois Suter <francois.suter@typo3.org>
Fri, 30 Oct 2009 16:56:07 +0000 (16:56 +0000)
committerFrancois Suter <francois.suter@typo3.org>
Fri, 30 Oct 2009 16:56:07 +0000 (16:56 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@6304 709f56b5-9817-0410-a4d7-c38de5d9e867

ChangeLog
typo3/sysext/scheduler/class.tx_scheduler_task.php
typo3/sysext/scheduler/doc/manual.sxw
typo3/sysext/scheduler/mod1/index.php
typo3/sysext/scheduler/mod1/locallang.xml
typo3/sysext/scheduler/res/gfx/stop.png [new file with mode: 0755]

index de5bfd2..2c440f1 100755 (executable)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,7 @@
 2009-10-30  Francois Suter  <francois@typo3.org>
 
        * Fixed bug #12406: Scheduler: Performed some minor cleanups in the BE module
+       * Feature #12184: Scheduler: Added BE method to mark a stalled / died task as not running
 
 2009-10-30  Steffen Kamper  <info@sk-typo3.de>
 
index 2c5e912..96aa76b 100755 (executable)
@@ -405,6 +405,23 @@ abstract class tx_scheduler_Task {
                $GLOBALS['TYPO3_DB']->sql_free_result($res);
        }
 
+       /**
+        * Clears all marked executions
+        *
+        * @return      boolean         True if the clearing succeeded, false otherwise
+        */
+       public function unmarkAllExecutions() {
+                       // Set the serialized executions field to empty
+               $result = $GLOBALS['TYPO3_DB']->exec_UPDATEquery(
+                       'tx_scheduler_task',
+                       'uid = ' . intval($this->taskUid),
+                       array(
+                               'serialized_executions' => ''
+                       )
+               );
+               return $result;
+       }
+
        /**
         * Saves the details of the task to the database.
         *
index 2d9d2d3..f20a2a2 100644 (file)
Binary files a/typo3/sysext/scheduler/doc/manual.sxw and b/typo3/sysext/scheduler/doc/manual.sxw differ
index 396f2fb..d087f33 100755 (executable)
@@ -226,6 +226,10 @@ class tx_scheduler_Module extends t3lib_SCbase {
                                                $this->deleteTask();
                                                $content .= $this->listTasks();
                                                break;
+                                       case 'stop':
+                                               $this->stopTask();
+                                               $content .= $this->listTasks();
+                                               break;
                                        case 'list':
                                        default:
                                                $content .= $this->listTasks();
@@ -530,6 +534,41 @@ class tx_scheduler_Module extends t3lib_SCbase {
                }
        }
 
+       /**
+        * Clears the registered running executions from the task
+        * Note that this doesn't actually stop the running script. It just unmarks
+        * all executions.
+        * TODO: find a way to really kill the running task
+        *
+        * @return      void
+        */
+       protected function stopTask() {
+               try {
+                               // Try to fetch the task and stop it
+                               /**
+                                * @var tx_scheduler_Task
+                                */
+                       $task = $this->scheduler->fetchTask($this->submittedData['uid']);
+                       if ($task->isExecutionRunning()) {
+                               // If the task is indeed currently running, clear marked executions
+
+                               $result = $task->unmarkAllExecutions();
+                               if ($result) {
+                                       $this->addMessage($GLOBALS['LANG']->getLL('msg.stopSuccess'));
+                               } else {
+                                       $this->addMessage($GLOBALS['LANG']->getLL('msg.stopError'), t3lib_FlashMessage::ERROR);
+                               }
+                       } else {
+                               // The task is not running, nothing to unmark
+
+                               $this->addMessage($GLOBALS['LANG']->getLL('msg.maynotStopNonRunningTask'), t3lib_FlashMessage::WARNING);
+                       }
+               } catch (Exception $e) {
+                               // The task was not found, for some reason
+                       $this->addMessage(sprintf($GLOBALS['LANG']->getLL('msg.taskNotFound'), $this->submittedData['uid']), t3lib_FlashMessage::ERROR);
+               }
+       }
+
        /**
         * Return a form to add a new task or edit an existing one
         *
@@ -925,6 +964,7 @@ class tx_scheduler_Module extends t3lib_SCbase {
                                        // Define action icons
                                $editAction = '<a href="' . $GLOBALS['MCONF']['_'] . '&CMD=edit&tx_scheduler[uid]=' . $schedulerRecord['uid'] . '" title="'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:edit') . '"><img ' . t3lib_iconWorks::skinImg($this->backPath, 'gfx/edit2.gif') . ' alt="' . $GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:edit') . '" /></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') . '"><img ' . t3lib_iconWorks::skinImg($this->backPath, 'gfx/garbage.gif') . ' alt="'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml: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') . '"><img ' . t3lib_iconWorks::skinImg($this->backPath, t3lib_extMgm::extRelPath('scheduler') . '/res/gfx/stop.png') . ' alt="'.$GLOBALS['LANG']->sL('LLL:EXT:lang/locallang_common.xml:stop') . '" /></a>';
                                        // Define some default values
                                $lastExecution = '-';
                                $isRunning = false;
@@ -1011,7 +1051,7 @@ class tx_scheduler_Module extends t3lib_SCbase {
                                                // Show no action links (edit, delete) if task is running
                                        $actions = $editAction . $deleteAction;
                                        if ($isRunning) {
-                                               $actions = '&nbsp;';
+                                               $actions = $stopAction;
                                        }
 
                                                // Check the disable status
index 712b1bc..d19111c 100644 (file)
@@ -59,6 +59,7 @@
                        <label index="msg.lastRun">The Scheduler was last started (%1$s) on %2$s at %3$s and ended on %4$s at %5$s.</label>
                        <label index="msg.maynotDeleteRunningTask">A running task may not be deleted.</label>
                        <label index="msg.maynotEditRunningTask">A running task may not be edited.</label>
+                       <label index="msg.maynotStopNonRunningTask">The task is not running. There are no executions to unmark.</label>
                        <label index="msg.noEmail">Please enter an email address</label>
                        <label index="msg.noFrequency">No frequency was defined, either as an interval or as a cron command.</label>
                        <label index="msg.noLastRun">The Scheduler has never yet run or the information about the last run has been lost.</label>
@@ -77,7 +78,9 @@
                        <label index="msg.schedulerUserFound">The backend user "_cli_scheduler" was found.</label>
                        <label index="msg.schedulerUserFoundButDisabled">The backend user "_cli_scheduler" exists but is currently disabled.</label>
                        <label index="msg.schedulerUserMissing">The backend user "_cli_scheduler" was not found. &lt;a href="%s" title="Click to create the missing user"&gt;Create the user now&lt;/a&gt;.</label>
-                       <label index="msg.singleExecutionMustBeInFuture">The execution time of single execution tasks has to be in the future.</label>
+                       <label index="msg.stop">Are you sure you want to mark this task as not running? Note that this will not stop the actual script (if unsure please refer to the manual).</label>
+                       <label index="msg.stopError">The task could not be marked as non-running.</label>
+                       <label index="msg.stopSuccess">The task was successfully marked as non-running.</label>
                        <label index="msg.taskNotFound">The requested task (UID: %d) was not found.</label>
                        <label index="msg.updateSuccess">The task was updated successfully.</label>
                        <label index="msg.updateError">The task could not be updated.</label>
diff --git a/typo3/sysext/scheduler/res/gfx/stop.png b/typo3/sysext/scheduler/res/gfx/stop.png
new file mode 100755 (executable)
index 0000000..0cfd585
Binary files /dev/null and b/typo3/sysext/scheduler/res/gfx/stop.png differ