在计划任务中使用removeAll() [英] use removeAll() in scheduler task

查看:67
本文介绍了在计划任务中使用removeAll()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在做新东西之前,我希望我的调度程序任务从数据库中删除所有条目,执行函数如下所示:

Before doing new stuff, i want my scheduler-Task to remove all entries from the database, the execute-function looks like that:

public function execute() {

  $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager');
  $jobRepository = $objectManager->get('\TYPO3\MyExtension\Domain\Repository\JobRepository');

  //clear DB
  $jobRepository->removeAll();

  (...)//insert new entries to DB

  $objectManager->get('TYPO3\CMS\Extbase\Persistence\PersistenceManagerInterface')->persistAll();

  return true;
}

向数据库中插入新条目可以很好地工作,但是清除数据库根本不起作用.我在做什么错了?

inserting new entries to the DB works fine, but clearing the DB doesn't work at all. What am I doing wrong?

推荐答案

由于removeAll()调用findAll():

public function removeAll() {
        foreach ($this->findAll() AS $object) {
            $this->remove($object);
        }
    }

最有可能是findAll()不返回任何对象.您是否处理了存储pid?禁用它或手动传递它.如果您从调度程序上下文中使用存储库的方法,它将不仅仅存在于此.

most likely findAll() returns no objects. Did you handle the storage pid? Either disable it or pass it manually. It won't be just there if you use methods of your repository from scheduler context.

这篇关于在计划任务中使用removeAll()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆