TYPO3 ExtBase - 通过UID获取调度程序任务并执行它

时间:2017-01-16 12:56:57

标签: php typo3 typo3-6.2.x

我的调度程序中有一个ID为5的任务:

task in schedueler

现在我尝试获取任务然后执行它。

...

/**
 * @var \TYPO3\CMS\Scheduler\Scheduler
 * @inject
 */
protected $scheduler;

...

public function createAction($filepath, Strategy $strategy)
{
    ...
    $taskObject = $this->scheduler->fetchTaskRecord(5)["serialized_task_object"];

    $task = unserialize($taskObject);

    if ($this->scheduler->isValidTaskObject($task)) {

        // The task is valid, return it
        $this->scheduler->executeTask($task);
    }

    ...
}

但是我收到以下错误: Fatal error: Call to a member function saveTask() on null in /var/www/typo3/typo3_src-6.2.25/typo3/sysext/scheduler/Classes/Task/AbstractTask.php on line 469

如果我执行var_dump($taskObject);

,这就是我得到的
  

的字符串(588)   “○:32:” TYPO3 \ CMS \ Extbase \调度\任务 “:9:{S:20:” * commandIdentifier “; S:39:” importr:导入:initializeservicemanager “; S:12:” *参数“;一个:1:{S:12: “extensionKey”; S:0: “”;} S:11: “*默认”;一个:2:{S:12: “extensionKey”; N; S:4:”邮件 “; N;} S:10:” * taskUid “; I:5; S:11:” *禁用 “; b:1; S:12:” *执行 “O:29:” TYPO3 \ CMS \调度\执行 “:6:{S:8:” *开始 “; I:1475152860; S:6:” *结束 “; I:1475152860; S:11:” *间隔“; I:0; S:11 : “*多个”; I:0; S:10: “* cronCmd”; S:0: “”; S:23: “* isNewSingleExecution”; b:0;} S:16: “* executionTime” 我:1475152860; S:14: “*描述”; S:0: “”; S:12: “*任务组”; I:0;}“

如果我在isValidTaskObject检查后立即输出$task var_dump,那么我只是得到一个空页。

更准确地说,我在createAction函数内部Importr/Classes/Controller/ImportrController.php函数,该文件属于扩展名Importr

的一部分

1 个答案:

答案 0 :(得分:3)

我想您应该使用fetchTask()而不是fetchTaskRecord()来获取任务对象而不是数组。 我刚尝试了这个并且没有错误。

$scheduler = $this->objectManager->get(\TYPO3\CMS\Scheduler\Scheduler::class);
$schedulerTask = $scheduler->fetchTask(1);
$schedulerTask->execute();

不多,但至少有一点信息/文件: https://docs.typo3.org/typo3cms/extensions/scheduler/latest/DevelopersGuide/SchedulerApi/Index.html

HTH merzilla