-->

use removeAll() in scheduler task

2019-03-01 12:59发布

问题:

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.