Skip to content

Commit

Permalink
Merge pull request #84 from Moongazer/fix/issue-82
Browse files Browse the repository at this point in the history
[FIX] Set the correct record UID in data-handler after the tag-sync
  • Loading branch information
ekkeguembel authored Aug 24, 2023
2 parents 004d39c + c21535e commit e81f8af
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
14 changes: 14 additions & 0 deletions Classes/Domain/Repository/TagRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,20 @@ public function synchronizeTags()
}
}

/**
* @throws \Doctrine\DBAL\DBALException
* @throws \Doctrine\DBAL\Driver\Exception
*/
public function findTagByTitle(string $title): array
{
$queryBuilder = $this->getQueryBuilder();
$result = $queryBuilder->select('*')
->from('tx_mautic_domain_model_tag')
->where($queryBuilder->expr()->eq('title', $queryBuilder->createNamedParameter($title, \PDO::PARAM_STR)))
->execute();
return $result->fetchAssociative();
}

protected function updateTag(array $tag, int $time)
{
$queryBuilder = $this->getQueryBuilder();
Expand Down
10 changes: 9 additions & 1 deletion Classes/Hooks/TCEmainHook.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class TCEmainHook
/**
* Create tags in Mautic and synchronize them with TYPO3 to receive proper IDs
*/
public function processDatamap_afterDatabaseOperations(string $status, string $table, string $id, array $fields, DataHandler &$dataHandler)
public function processDatamap_afterDatabaseOperations(string $status, string $table, string $id, array $fields, DataHandler &$dataHandler): void
{
if ($status === 'new' && $table === 'tx_mautic_domain_model_tag' && !empty($fields['title'])) {
// Dirty way to create tags in Mautic
Expand All @@ -35,6 +35,14 @@ public function processDatamap_afterDatabaseOperations(string $status, string $t
// Synchronize tags to receive proper ids
$tagRepository = GeneralUtility::makeInstance(TagRepository::class);
$tagRepository->synchronizeTags();

// update record UID to display edit-form after syncing the new tag with Mautic to avoid error in case the
// AUTO_INCREMENT value of table 'tx_mautic_domain_model_tag' is different from Mautic's 'lead_tags' table
// (see issue https://github.com/mautic/mautic-typo3/issues/82)
$newTag = $tagRepository->findTagByTitle($fields['title']);
if (!empty($newTag) && $newTag['uid'] !== $dataHandler->substNEWwithIDs[$id]) {
$dataHandler->substNEWwithIDs[$id] = $newTag['uid'];
}
}
}
}

0 comments on commit e81f8af

Please sign in to comment.