0

I'm using the "processDatamap_afterDatabaseOperations" hook within my extension to transfer content from a newly created News (tx_news_domain_model_news) to an API.

TYPO3 Version is 6.2.11 and if I var_dump or trying to access the category using $record->getCategories() it's empty. Same with related files, falmedia works. Here is my code:

public function processDatamap_afterDatabaseOperations($status, $table, $id, array $fieldArray, \TYPO3\CMS\Core\DataHandling\DataHandler &$pObj) {
    if ($table == 'tx_news_domain_model_news' && $status == 'new') {
        $objectManager  = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\CMS\Extbase\Object\ObjectManager');
        $news           = $objectManager->get('GeorgRinger\News\Domain\Repository\NewsRepository');
        $record         = $news->findByUid($pObj->substNEWwithIDs[$id]);

Hope anybody knows what I'm doing wrong here. I've been trying this like forever and don't get it.

Thanks in advance for your help.

lufi
  • 610
  • 7
  • 29

1 Answers1

4

That's likely because "afterDatabaseOperations" is called for each record insertion/update in each table, and that the relation between the record and the categories has not been established yet.

Only after all insertions/updates have been done, the method processRemapStack is called by the DataHandler, that sets/fixes all the relations between the various records (e.g. wherever there was a "NEW.." relation in the datamap, the correct uids are set).

The only hook you can use, where alle records have the correct relations is the processDatamap_afterAllOperations hook, that you can find at the very end of the process_datamap in the DataHandler class.

That one only takes a single argument though (the DataHandler instance), so you probably have to try and get the inserted news records using the "datamap" property of the DataHandler reference.

Nitori
  • 669
  • 5
  • 11
  • Thanks for you reply. I had a bad feeling about this. :-) Can I get the ID and the status out of processDatamap_afterAllOperations? Or is this the wrong aproach? – lufi Dec 15 '19 at 18:22
  • 1
    You get an instance of the DataHandler class as first argument to the method. That class has a "datamap" property, that contains the records that have been inserted/updated. Something like `$dh->datamap['tx_news_domain_model_news']` could give you an assoc array (uid => record) of inserted/updated news records (might be empty though), and if the uid starts with "NEW...", then it was an inserted record ... But I have no idea if that is the correct approach. – Nitori Dec 16 '19 at 07:52