Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get uid of new record in hook processDatamap_afterDatabaseOperations

When creating new database records, TYPO3 assigns them a temporary UID, which looks like this: NEW56fe740dd5a455.64167468. The record gets its real UID when it is inserted into the database.

In the above hook, the record is already inserted into the database, so it has a numerical uid assigned. How do I get that uid from a given temporary UID?

like image 269
Jost Avatar asked Dec 14 '22 07:12

Jost


1 Answers

Ok, found it. The fourth parameter of the hook-method is the datahandler object, which has a property substNEWwithIDs, an associative array mapping temporary UIDs to the real UIDs.

One can use it like this:

public function processDatamap_afterDatabaseOperations($action, $table, $uid, $datahandler)
{
    if (GeneralUtility::isFirstPartOfStr($uid, 'NEW')) {
        $uid = $datahandler->substNEWwithIDs[$uid];
    }

    // Do something with the UID
}
like image 144
Jost Avatar answered Jan 30 '23 23:01

Jost