removeAll() from repository in scheduler task

225 views Asked by At

For my scheduler task, I want to delete all the existing data from repository before updating it, every time the scheduler runs. I am able to save and add new data from XML File using add().

class FunctionFetcherService {

public function fetchRoomandLesson() {
    $path = 'http:abc.dll?type=room&content=xml';
    $objectManager = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Extbase\\Object\\ObjectManager');
    $roomRepository = $objectManager->get("School\\booking\\Domain\\Repository\\RoomsRepository");
    $this->roomRepository->removeAll();
    $xml = simplexml_load_file($path);
    $json = json_encode($xml);
    $xmlArray = json_decode($json, true);
    $serialized_array = serialize($xmlArray);
    $unserialized_array = unserialize($serialized_array);

An error occurs removeAll() called on Null. I also referred to the already asked question: use removeAll() in scheduler task but it does doe not work.

2

There are 2 answers

0
Rudy Gnodde On

You create the repository as variable $roomRepository and then try to access it through $this->roomRepository. Changing $this->roomRepository to $roomRepository should fix the error.

1
Jacob Rasmussen On

You should create an Extbase CommandController as your scheduler task. All registered commands are available in the scheduler as well as CLI commands.

By using CommandControllers you can use the full extbase framework, such as dependency injections and validations.

Please note that CommandController command methods must be suffixed with Command just like the linked example.