use removeAll() in scheduler task

孤人 提交于 2019-12-20 04:35:24

问题


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?


回答1:


Since removeAll() calls findAll():

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

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.



来源:https://stackoverflow.com/questions/22040587/use-removeall-in-scheduler-task

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!