Follow-up to #12132: New exception was not caught nor handled properly everywhere
authorFrancois Suter <francois.suter@typo3.org>
Fri, 16 Oct 2009 09:06:16 +0000 (09:06 +0000)
committerFrancois Suter <francois.suter@typo3.org>
Fri, 16 Oct 2009 09:06:16 +0000 (09:06 +0000)
git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@6159 709f56b5-9817-0410-a4d7-c38de5d9e867

typo3/sysext/scheduler/class.tx_scheduler.php
typo3/sysext/scheduler/cli/scheduler_cli_dispatch.php
typo3/sysext/scheduler/mod1/index.php

index 7888f91..2c0d13d 100755 (executable)
@@ -299,6 +299,7 @@ class tx_scheduler implements t3lib_Singleton {
         * @return      tx_scheduler_Task       The fetched task object
         */
        public function fetchTask($uid = 0) {
+               $whereClause = '';
                        // Define where clause
                        // If no uid is given, take any non-disabled task which has a next execution time in the past
                if (empty($uid)) {
@@ -308,7 +309,7 @@ class tx_scheduler implements t3lib_Singleton {
                }
 
                $queryArray = array(
-                       'SELECT'        => 'serialized_task_object',
+                       'SELECT'        => 'uid, serialized_task_object',
                        'FROM'          => 'tx_scheduler_task',
                        'WHERE'         => $whereClause,
                        'LIMIT'         => 1
@@ -323,15 +324,23 @@ class tx_scheduler implements t3lib_Singleton {
                } else {
                        $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res);
                        $task = unserialize($row['serialized_task_object']);
-                               // Return the task only if valid, otherwise throw an exception
+
                        if ($this->isValidTaskObject($task)) {
+                               // The task is valid, return it
+
                                $task->setScheduler();
-                               $GLOBALS['TYPO3_DB']->sql_free_result($res);
-                               return $task;
+
                        } else {
+                               // Forcibly set the disable flag to 1 in the database,
+                               // so that the task does not come up again and again for execution
+
+                               $GLOBALS['TYPO3_DB']->exec_UPDATEquery('tx_scheduler_task', "uid = '" . $row['uid'] . "'", array('disable' => 1));
+                                       // Throw an exception to raise the problem
                                throw new UnexpectedValueException('Could not unserialize task', 1255083671);
                        }
+                       $GLOBALS['TYPO3_DB']->sql_free_result($res);
                }
+               return $task;
        }
 
         /**
index 7ff4a6c..0c9b832 100644 (file)
@@ -33,6 +33,7 @@
  * $Id: scheduler_cli_dispatch.php 1261 2009-09-15 20:22:45Z francois $
  */
 if (defined('TYPO3_cliMode') && TYPO3_cliMode && basename(PATH_thisScript) == 'cli_dispatch.phpsh') {
+       $hasTask = true;
                // Create an instance of the scheduler object
                /**
                 * @var tx_scheduler
@@ -58,9 +59,14 @@ if (defined('TYPO3_cliMode') && TYPO3_cliMode && basename(PATH_thisScript) == 'c
                                continue;
                        }
                }
+                       // There are no more tasks, quit the run
                catch (OutOfBoundsException $e) {
                        $hasTask = false;
                }
+                       // A task could not be unserialized properly, skip to next task
+               catch (UnexpectedValueException $e) {
+                       continue;
+               }
        } while ($hasTask);
                // Record the run in the system registry
        $scheduler->recordLastRun();
index 67cdd41..4a63b82 100755 (executable)
@@ -507,7 +507,7 @@ class tx_scheduler_Module extends t3lib_SCbase {
                                }
                        }
                } catch (UnexpectedValueException $e) {
-                               // The could not be unserialized properly, simply delete the database record
+                               // The task could not be unserialized properly, simply delete the database record
                        $result = $GLOBALS['TYPO3_DB']->exec_DELETEquery('tx_scheduler_task', 'uid = ' . intval($this->submittedData['uid']));
                        if ($result) {
                                $this->addMessage($GLOBALS['LANG']->getLL('msg.deleteSuccess'));
@@ -823,6 +823,10 @@ class tx_scheduler_Module extends t3lib_SCbase {
                                catch (OutOfBoundsException $e) {
                                        $this->addMessage(sprintf($GLOBALS['LANG']->getLL('msg.taskNotFound'), $uid), t3lib_FlashMessage::ERROR);
                                }
+                                       // The task object was not valid
+                               catch (UnexpectedValueException $e) {
+                                       $this->addMessage(sprintf($GLOBALS['LANG']->getLL('msg.executionFailed'), $name, $e->getMessage()), t3lib_FlashMessage::ERROR);
+                               }
                        }
                                // Record the run in the system registry
                        $this->scheduler->recordLastRun('manual');