Skip to content

Commit

Permalink
[BUGFIX] Ignore registrations on event copy and localization actions …
Browse files Browse the repository at this point in the history
…in backend

Refs #1289
  • Loading branch information
derhansen committed Oct 17, 2024
1 parent 940efe6 commit 09cf212
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 10 deletions.
55 changes: 45 additions & 10 deletions Classes/Hooks/DataHandlerHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
class DataHandlerHooks
{
public const EVENT_TABLE = 'tx_sfeventmgt_domain_model_event';
public const REGISTRATION_TABLE = 'tx_sfeventmgt_domain_model_registration';
public const CUSTOMNOTIFICATIONLOG_TABLE = 'tx_sfeventmgt_domain_model_customnotificationlog';

/**
Expand Down Expand Up @@ -157,8 +158,11 @@ public function processDatamap_postProcessFieldArray(
}

/**
* Sets the TCA type of the fields 'registration' and 'registration_waitlist' to 'none' for copy and localize,
* so field values will not be duplicated in the copy of the object.
* Hides non deleted event registrations before copy and localize in order to prevent registrations from being
* copied or localized.
*
* @todo: Try to extend TYPO3 core to allow 3rd party extension to modifying `$excludeFields` in
* `DataHandler->copyRecord()` function.
*
* @param string $command
* @param string $table
Expand All @@ -169,14 +173,13 @@ public function processDatamap_postProcessFieldArray(
*/
public function processCmdmap_preProcess($command, $table, $id, $value, $pObj, $pasteUpdate): void
{
if (in_array($command, ['copy', 'localize']) && $table === self::EVENT_TABLE) {
$GLOBALS['TCA'][self::EVENT_TABLE]['columns']['registration']['config']['type'] = 'none';
$GLOBALS['TCA'][self::EVENT_TABLE]['columns']['registration_waitlist']['config']['type'] = 'none';
if ($table === self::EVENT_TABLE && in_array($command, ['copy', 'localize'])) {
$this->hideRegistrationsBeforeCopyAndLocalize($id);
}
}

/**
* (1) Sets the TCA type of certain fields back to their original state after a copy or move command
* (1) Unhides non deleted event registrations after copy and localize
* (2) Handles deletion of custom notifications when deleting an event
*
* @param string $command
Expand All @@ -189,10 +192,13 @@ public function processCmdmap_preProcess($command, $table, $id, $value, $pObj, $
*/
public function processCmdmap_postProcess($command, $table, $id, $value, $pObj, $pasteUpdate, $pasteDatamap): void
{
if (in_array($command, ['copy', 'localize']) && $table === self::EVENT_TABLE) {
$GLOBALS['TCA'][self::EVENT_TABLE]['columns']['registration']['config']['type'] = 'inline';
$GLOBALS['TCA'][self::EVENT_TABLE]['columns']['registration_waitlist']['config']['type'] = 'inline';
} elseif ($command === 'delete' && $table === self::EVENT_TABLE) {
if ($table !== self::EVENT_TABLE) {
return;
}

if (in_array($command, ['copy', 'localize'])) {
$this->unhideRegistrationsAfterCopyAndLocalize($id);
} elseif ($command === 'delete') {
$this->deleteCustomNotificationsByEvent($id);
}
}
Expand All @@ -211,4 +217,33 @@ protected function deleteCustomNotificationsByEvent(int $eventUid): void
)
->executeStatement();
}

protected function hideRegistrationsBeforeCopyAndLocalize(int $eventUid): void
{
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable(self::CUSTOMNOTIFICATIONLOG_TABLE);
$queryBuilder
->update(self::REGISTRATION_TABLE)
->set('deleted', 1)
->set('temp_event_uid', $eventUid)
->where(
$queryBuilder->expr()->eq('event', $queryBuilder->createNamedParameter($eventUid, Connection::PARAM_INT)),
$queryBuilder->expr()->eq('deleted', $queryBuilder->createNamedParameter(0, Connection::PARAM_INT))
)
->executeStatement();
}

protected function unhideRegistrationsAfterCopyAndLocalize(int $eventUid): void
{
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
->getQueryBuilderForTable(self::CUSTOMNOTIFICATIONLOG_TABLE);
$queryBuilder
->update(self::REGISTRATION_TABLE)
->set('deleted', 0)
->set('temp_event_uid', 0)
->where(
$queryBuilder->expr()->eq('temp_event_uid', $queryBuilder->createNamedParameter($eventUid, Connection::PARAM_INT))
)
->executeStatement();
}
}
7 changes: 7 additions & 0 deletions Configuration/TCA/tx_sfeventmgt_domain_model_registration.php
Original file line number Diff line number Diff line change
Expand Up @@ -384,5 +384,12 @@
],
],
],
'temp_event_uid' => [
'exclude' => true,
'label' => 'Holds temporarily the event UID of an event copy/paste/localize process in TYPO3 backend.',
'config' => [
'type' => 'number',
],
],
],
];

0 comments on commit 09cf212

Please sign in to comment.