2014-02-26 26 views
1

做新的东西之前,我想我的调度任务从数据库中删除所有条目,在执行功能看起来像这样:使用的removeAll()

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; 
} 

插入新的条目到数据库工作正常,但清理数据库根本不起作用。我究竟做错了什么?

回答

5

由于removeAll()电话findAll()

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

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

+0

谢谢,那就是问题! – sinini