简体   繁体   English

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

[英]TYPO3 ExtBase - Get scheduler task by UID and execute it

I have a task in my scheduler with ID 5: 我的调度程序中有一个ID为5的任务:

计划任务

Now I try to fetch the Task and then execute it. 现在,我尝试获取任务,然后执行它。

...

/**
 * @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);
    }

    ...
}

But I get the following error: 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 但是我收到以下错误: 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

This is what I get if I execute var_dump($taskObject); 这是我执行var_dump($taskObject);

string(588) "O:32:"TYPO3\\CMS\\Extbase\\Scheduler\\Task":9:{s:20:"*commandIdentifier";s:39:"importr:import:initializeservicemanager";s:12:"*arguments";a:1:{s:12:"extensionKey";s:0:"";}s:11:"*defaults";a:2:{s:12:"extensionKey";N;s:4:"mail";N;}s:10:"*taskUid";i:5;s:11:"*disabled";b:1;s:12:"*execution";O:29:"TYPO3\\CMS\\Scheduler\\Execution":6:{s:8:"*start";i:1475152860;s:6:"*end";i:1475152860;s:11:"*interval";i:0;s:11:"*multiple";i:0;s:10:"*cronCmd";s:0:"";s:23:"*isNewSingleExecution";b:0;}s:16:"*executionTime";i:1475152860;s:14:"*description";s:0:"";s:12:"*taskGroup";i:0;}" 字符串(588)“ O:32:” TYPO3 \\ CMS \\ Extbase \\ Scheduler \\ Task“:9:{s:20:” * commandIdentifier“; s:39:” importr:import: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 “; I:1475152860; S:14:” *描述 “; S:0:” “; S:12:” *任务组 “; I:0;}”

If I output $task with var_dump right after the isValidTaskObject check, then I just get an empty page. 如果在isValidTaskObject检查之后立即输出带有var_dump $task ,那么我只会得到一个空页面。

To be more precise, I am working inside the createAction function from the file Importr/Classes/Controller/ImportrController.php which is part of the extension Importr 更确切地说,我正在文件Importr/Classes/Controller/ImportrController.phpcreateAction函数内部进行工作,该文件是扩展程序Importr一部分

I guess you should just use fetchTask() instead of fetchTaskRecord() , to get the task object instead of an array. 我猜您应该只使用fetchTask()而不是fetchTaskRecord()来获取任务对象而不是数组。 I just tried this and got no error. 我只是试过了,没有任何错误。

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

Not much but at least a bit information / documentation: https://docs.typo3.org/typo3cms/extensions/scheduler/latest/DevelopersGuide/SchedulerApi/Index.html 没有多少,但至少有一点信息/文档: https : //docs.typo3.org/typo3cms/extensions/scheduler/latest/DevelopersGuide/SchedulerApi/Index.html

HTH merzilla HTH Merzilla

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM