* @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)) {
}
$queryArray = array(
- 'SELECT' => 'serialized_task_object',
+ 'SELECT' => 'uid, serialized_task_object',
'FROM' => 'tx_scheduler_task',
'WHERE' => $whereClause,
'LIMIT' => 1
} 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;
}
/**
* $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
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();
}
}
} 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'));
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');