Skip to content

Commit

Permalink
[TASK] Improve EventHandler names
Browse files Browse the repository at this point in the history
Make it easier to understand what the EventHandler does.
  • Loading branch information
mabolek committed Sep 22, 2023
1 parent 17280b8 commit 081e035
Show file tree
Hide file tree
Showing 17 changed files with 109 additions and 108 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
* Sets the UID in the operation if it was successful.
* Adds all the pending relations to the DataHandler's datamap, so the relations are created together with the record
* they point to.
*/
class ResolvePendingRelations implements RecordOperationEventHandlerInterface
class AddResolvedPendingRelationsToDataHandler implements RecordOperationEventHandlerInterface
{
public function __invoke(AbstractRecordOperationEvent $event): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
use Pixelant\Interest\Utility\RelationUtility;

/**
* Converts all array values to comma-separated values.
* Converts relation field values from array to comma-separated string.
*/
class ConvertArrayValuesToScalar implements RecordOperationEventHandlerInterface
class ConvertRelationFieldArraysToCsv implements RecordOperationEventHandlerInterface
{
/**
* @inheritDoc
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
/**
* Defers a record where the remote ID for a PID doesn't exist yet.
*/
class DeferMissingPidRemoteId extends AbstractDetermineDeferredRecordOperation
class DeferIfPidDoesNotYetExist extends AbstractDetermineDeferredRecordOperation
{
protected function getDependentRemoteId(): ?string
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*
* @see RelationSortingAsMetaData
*/
class ForeignRelationSorting implements RecordOperationEventHandlerInterface
class FixSortingPositionsOnRemoteRelationRecords implements RecordOperationEventHandlerInterface
{
protected ?RemoteIdMappingRepository $mappingRepository = null;

Expand All @@ -34,7 +34,10 @@ class ForeignRelationSorting implements RecordOperationEventHandlerInterface
*/
public function __invoke(AbstractRecordOperationEvent $event): void
{
if ($event->getRecordOperation() instanceof DeleteRecordOperation) {
if (
$event->getRecordOperation() instanceof DeleteRecordOperation
|| !$event->getRecordOperation()->isSuccessful()
) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
/**
* Sets the UID in the operation if it was successful.
*/
class MapRemoteId implements RecordOperationEventHandlerInterface
class MapNewUidToRemoteId implements RecordOperationEventHandlerInterface
{
public function __invoke(AbstractRecordOperationEvent $event): void
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
* Filters out pending relations (relations to records not yet created) and issues a PendingRelationMessage for handling
* later.
*/
class FilterPendingRelations implements RecordOperationEventHandlerInterface
class MapUidsAndExtractPendingRelations implements RecordOperationEventHandlerInterface
{
protected RemoteIdMappingRepository $mappingRepository;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

namespace Pixelant\Interest\DataHandling\Operation\Event\Handler\Message;

use Pixelant\Interest\DataHandling\Operation\Event\Handler\FilterPendingRelations;
use Pixelant\Interest\DataHandling\Operation\Event\Handler\MapUidsAndExtractPendingRelations;
use Pixelant\Interest\DataHandling\Operation\Event\Handler\PersistPendingRelationInformation;
use Pixelant\Interest\DataHandling\Operation\Message\RequiredMessageInterface;

/**
* A message concerning pending relations to be persisted.
*
* @see FilterPendingRelations
* @see MapUidsAndExtractPendingRelations
* @see PersistPendingRelationInformation
*/
class PendingRelationMessage implements RequiredMessageInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@

namespace Pixelant\Interest\DataHandling\Operation\Event\Handler\Message;

use Pixelant\Interest\DataHandling\Operation\Event\Handler\DetectUpdatedForeignFieldValues;
use Pixelant\Interest\DataHandling\Operation\Event\Handler\RegisterValuesOfRelationFields;
use Pixelant\Interest\DataHandling\Operation\Message\RequiredMessageInterface;

/**
* Information on an updated foreign relation field.
* The value of a foreign relation field.
*
* @see DetectUpdatedForeignFieldValues
* @see RegisterValuesOfRelationFields
*/
class UpdatedForeignFieldValueMessage implements RequiredMessageInterface
class RelationFieldValueMessage implements RequiredMessageInterface
{
private string $table;

Expand Down
42 changes: 0 additions & 42 deletions Classes/DataHandling/Operation/Event/Handler/PrepareRelations.php

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use Pixelant\Interest\DataHandling\Operation\Event\AbstractRecordOperationEvent;
use Pixelant\Interest\DataHandling\Operation\Event\RecordOperationEventHandlerInterface;
use Pixelant\Interest\DataHandling\Operation\Event\Handler\Message\UpdatedForeignFieldValueMessage;
use Pixelant\Interest\DataHandling\Operation\Event\Handler\Message\RelationFieldValueMessage;
use Pixelant\Interest\DataHandling\Operation\UpdateRecordOperation;
use Pixelant\Interest\Utility\RelationUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
Expand All @@ -25,8 +25,8 @@ public function __invoke(AbstractRecordOperationEvent $event): void
$recordOperation = $event->getRecordOperation();

do {
/** @var UpdatedForeignFieldValueMessage $message */
$message = $recordOperation->retrieveMessage(UpdatedForeignFieldValueMessage::class);
/** @var RelationFieldValueMessage $message */
$message = $recordOperation->retrieveMessage(RelationFieldValueMessage::class);

if ($message === null) {
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@

use Pixelant\Interest\DataHandling\Operation\Event\AbstractRecordOperationEvent;
use Pixelant\Interest\DataHandling\Operation\Event\RecordOperationEventHandlerInterface;
use Pixelant\Interest\DataHandling\Operation\Event\Handler\Message\UpdatedForeignFieldValueMessage;
use Pixelant\Interest\DataHandling\Operation\Event\Handler\Message\RelationFieldValueMessage;
use Pixelant\Interest\DataHandling\Operation\UpdateRecordOperation;
use Pixelant\Interest\Utility\TcaUtility;

/**
* Check datamap fields with foreign field and store value(s) in array. After process_datamap values can be used to
* compare what is actually stored in the database, and we can delete removed values.
* Check datamap fields keeping foreign relations and send a RelationFieldValueMessage for each. After process_datamap
* the values can be used to compare what is actually stored in the database, and we can delete removed values.
*/
class DetectUpdatedForeignFieldValues implements RecordOperationEventHandlerInterface
class RegisterValuesOfRelationFields implements RecordOperationEventHandlerInterface
{
public function __invoke(AbstractRecordOperationEvent $event): void
{
Expand All @@ -34,12 +34,14 @@ public function __invoke(AbstractRecordOperationEvent $event): void
);

if ($tcaFieldConf['foreign_field'] ?? false) {
$recordOperation->dispatchMessage(new UpdatedForeignFieldValueMessage(
$recordOperation->getTable(),
$field,
$id,
$value
));
$recordOperation->dispatchMessage(
new RelationFieldValueMessage(
$recordOperation->getTable(),
$field,
$id,
$value
)
);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
* when persisting the foreign side of the relation to ensure the ordering is correct, even if the foreign relations are
* created one-by-one.
*
* @see ForeignRelationSorting
* @see FixSortingPositionsOnRemoteRelationRecords
*/
class RelationSortingAsMetaData implements RecordOperationEventHandlerInterface
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace Pixelant\Interest\DataHandling\Operation\Event\Handler;

use Pixelant\Interest\DataHandling\Operation\DeleteRecordOperation;
use Pixelant\Interest\DataHandling\Operation\Event\AbstractRecordOperationEvent;
use Pixelant\Interest\DataHandling\Operation\Event\RecordOperationEventHandlerInterface;

/**
* Removes empty values from relation arrays.
*/
class RemoveEmptyValuesFromRelationFieldArrays implements RecordOperationEventHandlerInterface
{
/**
* @inheritDoc
*/
public function __invoke(AbstractRecordOperationEvent $event): void
{
if ($event->getRecordOperation() instanceof DeleteRecordOperation) {
return;
}

foreach ($event->getRecordOperation()->getDataForDataHandler() as $fieldName => $fieldValue) {
if (!is_array($fieldValue)) {
continue;
}

$event->getRecordOperation()->setDataFieldForDataHandler($fieldName, array_filter($fieldValue));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* If a record has been successfully created, we can remove the pending relations records that were pointing to it. They
* were processed earlier, but we couldn't remove them until we knew the record had been successfully created.
*
* @see ResolvePendingRelations
* @see AddResolvedPendingRelationsToDataHandler
*/
class RemovePendingRelationsForCreatedRecord implements RecordOperationEventHandlerInterface
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Pixelant\Interest\DataHandling\Operation\Exception\InvalidArgumentException;

/**
* Simply sets the language in the ContentObjectRenderer's data array.
* Sets the language in the ContentObjectRenderer's data array.
*/
class SetContentObjectRendererLanguage implements RecordOperationEventHandlerInterface
{
Expand Down
62 changes: 31 additions & 31 deletions Configuration/Services.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -82,61 +82,61 @@ services:
- name: event.listener
identifier: sanitizeFieldValues
event: Pixelant\Interest\DataHandling\Operation\Event\RecordOperationSetupEvent
before: deferMissingPidRemoteId
before: deferIfPidDoesNotYetExist

Pixelant\Interest\DataHandling\Operation\Event\Handler\DeferMissingPidRemoteId:
Pixelant\Interest\DataHandling\Operation\Event\Handler\DeferIfPidDoesNotYetExist:
tags:
- name: event.listener
identifier: deferMissingPidRemoteId
identifier: deferIfPidDoesNotYetExist
event: Pixelant\Interest\DataHandling\Operation\Event\RecordOperationSetupEvent
before: filterPendingRelations
before: mapUidsAndExtractPendingRelations

Pixelant\Interest\DataHandling\Operation\Event\Handler\FilterPendingRelations:
Pixelant\Interest\DataHandling\Operation\Event\Handler\MapUidsAndExtractPendingRelations:
tags:
- name: event.listener
identifier: filterPendingRelations
identifier: mapUidsAndExtractPendingRelations
event: Pixelant\Interest\DataHandling\Operation\Event\RecordOperationSetupEvent
before: prepareRelations
before: removeFieldsWithNullValue

Pixelant\Interest\DataHandling\Operation\Event\Handler\PrepareRelations:
Pixelant\Interest\DataHandling\Operation\Event\Handler\RemoveFieldsWithNullValue:
tags:
- name: event.listener
identifier: prepareRelations
identifier: removeFieldsWithNullValue
event: Pixelant\Interest\DataHandling\Operation\Event\RecordOperationSetupEvent
before: removeFieldsWithNullValue
before: removeEmptyValuesFromRelationFieldArrays

Pixelant\Interest\DataHandling\Operation\Event\Handler\RemoveFieldsWithNullValue:
Pixelant\Interest\DataHandling\Operation\Event\Handler\RemoveEmptyValuesFromRelationFieldArrays:
tags:
- name: event.listener
identifier: removeFieldsWithNullValue
identifier: removeEmptyValuesFromRelationFieldArrays
event: Pixelant\Interest\DataHandling\Operation\Event\RecordOperationSetupEvent
before: setPid
before: convertRelationFieldArraysToCsv

Pixelant\Interest\DataHandling\Operation\Event\Handler\SetPid:
Pixelant\Interest\DataHandling\Operation\Event\Handler\ConvertRelationFieldArraysToCsv:
tags:
- name: event.listener
identifier: setPid
identifier: convertRelationFieldArraysToCsv
event: Pixelant\Interest\DataHandling\Operation\Event\RecordOperationSetupEvent
after: removeFieldsWithNullValue
before: setPid

Pixelant\Interest\DataHandling\Operation\Event\Handler\DetectUpdatedForeignFieldValues:
Pixelant\Interest\DataHandling\Operation\Event\Handler\SetPid:
tags:
- name: event.listener
identifier: detectUpdatedForeignFieldValues
event: Pixelant\Interest\DataHandling\Operation\Event\RecordOperationInvocationEvent
before: convertArrayValuesToScalar
identifier: setPid
event: Pixelant\Interest\DataHandling\Operation\Event\RecordOperationSetupEvent
after: convertRelationFieldArraysToCsv

Pixelant\Interest\DataHandling\Operation\Event\Handler\ConvertArrayValuesToScalar:
Pixelant\Interest\DataHandling\Operation\Event\Handler\RegisterValuesOfRelationFields:
tags:
- name: event.listener
identifier: convertArrayValuesToScalar
identifier: registerValuesOfRelationFields
event: Pixelant\Interest\DataHandling\Operation\Event\RecordOperationInvocationEvent
before: resolvePendingRelations
before: addResolvedPendingRelationsToDataHandler

Pixelant\Interest\DataHandling\Operation\Event\Handler\ResolvePendingRelations:
Pixelant\Interest\DataHandling\Operation\Event\Handler\AddResolvedPendingRelationsToDataHandler:
tags:
- name: event.listener
identifier: resolvePendingRelations
identifier: addResolvedPendingRelationsToDataHandler
event: Pixelant\Interest\DataHandling\Operation\Event\RecordOperationInvocationEvent
before: processDatamap

Expand Down Expand Up @@ -166,12 +166,12 @@ services:
- name: event.listener
identifier: setUid
event: Pixelant\Interest\DataHandling\Operation\Event\RecordOperationInvocationEvent
before: mapRemoteId
before: mapNewUidToRemoteId

Pixelant\Interest\DataHandling\Operation\Event\Handler\MapRemoteId:
Pixelant\Interest\DataHandling\Operation\Event\Handler\MapNewUidToRemoteId:
tags:
- name: event.listener
identifier: mapRemoteId
identifier: mapNewUidToRemoteId
event: Pixelant\Interest\DataHandling\Operation\Event\RecordOperationInvocationEvent
before: persistPendingRelationInformation

Expand All @@ -196,10 +196,10 @@ services:
event: Pixelant\Interest\DataHandling\Operation\Event\RecordOperationInvocationEvent
before: cleanUpPendingRelations

Pixelant\Interest\DataHandling\Operation\Event\Handler\ForeignRelationSorting:
Pixelant\Interest\DataHandling\Operation\Event\Handler\FixSortingPositionsOnRemoteRelationRecords:
tags:
- name: event.listener
identifier: foreignRelationSorting
identifier: fixSortingPositionsOnRemoteRelationRecords
event: Pixelant\Interest\DataHandling\Operation\Event\RecordOperationInvocationEvent
before: cleanUpPendingRelations

Expand All @@ -208,7 +208,7 @@ services:
- name: event.listener
identifier: removePendingRelationsForCreatedRecord
event: Pixelant\Interest\DataHandling\Operation\Event\RecordOperationInvocationEvent
after: foreignRelationSorting
after: fixSortingPositionsOnRemoteRelationRecords

Pixelant\Interest\DataHandling\Operation\Event\Handler\RemovePendingRelationsForDeletedRecord:
tags:
Expand Down
Loading

0 comments on commit 081e035

Please sign in to comment.