-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add PSR-14 Event to modify event objects prior persistence
A new PSR-14 event is added that allows to modify the event right before it is persisted within Destination Data One import. This for example allows to alter dates, prices, etc. Relates: #10597
- Loading branch information
1 parent
00946af
commit 1782bee
Showing
15 changed files
with
414 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
57 changes: 57 additions & 0 deletions
57
Classes/Service/DestinationDataImportService/Events/EventImportEvent.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* Copyright (C) 2023 Daniel Siepmann <coding@daniel-siepmann.de> | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version 2 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
* 02110-1301, USA. | ||
*/ | ||
|
||
namespace Wrm\Events\Service\DestinationDataImportService\Events; | ||
|
||
use Wrm\Events\Domain\Model\Event; | ||
|
||
final class EventImportEvent | ||
{ | ||
/** | ||
* @var Event | ||
*/ | ||
private $existingEvent; | ||
|
||
/** | ||
* @var Event | ||
*/ | ||
private $eventToImport; | ||
|
||
public function __construct( | ||
Event $existingEvent, | ||
Event $eventToImport | ||
) { | ||
$this->existingEvent = $existingEvent; | ||
$this->eventToImport = $eventToImport; | ||
} | ||
|
||
public function getBaseEvent(): Event | ||
{ | ||
return clone $this->existingEvent; | ||
} | ||
|
||
public function getEventToImport(): Event | ||
{ | ||
return $this->eventToImport; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
3.5.0 | ||
===== | ||
|
||
Breaking | ||
-------- | ||
|
||
Nothing | ||
|
||
Features | ||
-------- | ||
|
||
* Add PSR-14 Events to Destination Data One import. | ||
They allow individual installation to alter the import. | ||
|
||
See :ref:`psr14` for an overview of PSR-14 Events. | ||
|
||
Added Events: | ||
|
||
* Allow to modify an event object before importing. | ||
|
||
Fixes | ||
----- | ||
|
||
Nothing | ||
|
||
Tasks | ||
----- | ||
|
||
Nothing | ||
|
||
Deprecation | ||
----------- | ||
|
||
Nothing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
.. index:: single: PSR-14 Events | ||
.. _psr14: | ||
|
||
PSR-14 Events | ||
============= | ||
|
||
.. index:: single: PSR-14 Events; Destination Data One Import: Event Import | ||
|
||
Destination Data One Import: ``EventImportEvent`` | ||
------------------------------------------------- | ||
|
||
Executed during Destination Data One Import. | ||
Allows to alter the event prior persistence. |
29 changes: 29 additions & 0 deletions
29
...nal/Psr14Events/DestinationDataImport/Assertions/RegisteredEventHandlerCanModifyEvent.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
return [ | ||
'tx_events_domain_model_event' => [ | ||
[ | ||
'uid' => 1, | ||
'pid' => 2, | ||
'title' => 'Event for modifying event', | ||
'global_id' => 'e_100350503', | ||
'dates' => 2, | ||
], | ||
], | ||
'tx_events_domain_model_date' => [ | ||
[ | ||
'uid' => 1, | ||
'pid' => 2, | ||
'event' => 1, | ||
'start' => 4097728800, | ||
'end' => null, | ||
], | ||
[ | ||
'uid' => 2, | ||
'pid' => 2, | ||
'event' => 1, | ||
'start' => 4097815200, | ||
'end' => null, | ||
], | ||
], | ||
]; |
59 changes: 59 additions & 0 deletions
59
Tests/Functional/Psr14Events/DestinationDataImport/EventImportEventTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* Copyright (C) 2023 Daniel Siepmann <coding@daniel-siepmann.de> | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version 2 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
* 02110-1301, USA. | ||
*/ | ||
|
||
namespace Wrm\Events\Tests\Functional\Psr14Events\DestinationDataImport; | ||
|
||
use GuzzleHttp\Psr7\Response; | ||
use Wrm\Events\Tests\Functional\Import\DestinationDataTest\AbstractTest; | ||
|
||
final class EventImportEventTest extends AbstractTest | ||
{ | ||
protected function setUp(): void | ||
{ | ||
$this->testExtensionsToLoad[] = 'typo3conf/ext/events/Tests/Functional/Psr14Events/DestinationDataImport/Fixtures/Extensions/custom_event/'; | ||
|
||
parent::setUp(); | ||
|
||
$this->setUpConfiguration([ | ||
'restUrl = https://example.com/some-path/', | ||
'license = example-license', | ||
'restType = Event', | ||
'restLimit = 3', | ||
'restMode = next_months,12', | ||
'restTemplate = ET2014A.json', | ||
]); | ||
} | ||
|
||
/** | ||
* @test | ||
*/ | ||
public function registeredEventHandlerCanModifyEvent(): void | ||
{ | ||
$this->importPHPDataSet(__DIR__ . '/Fixtures/Database/RegisteredEventHandlerCanModifyEvent.php'); | ||
$this->setUpResponses([new Response(200, [], file_get_contents(__DIR__ . '/Fixtures/Responses/RegisteredEventHandlerCanModifyEvent.json') ?: '')]); | ||
|
||
$this->executeCommand(); | ||
|
||
$this->assertPHPDataSet(__DIR__ . '/Assertions/RegisteredEventHandlerCanModifyEvent.php'); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...14Events/DestinationDataImport/Fixtures/Database/RegisteredEventHandlerCanModifyEvent.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
return [ | ||
'tx_events_domain_model_import' => [ | ||
[ | ||
'uid' => '1', | ||
'pid' => '2', | ||
'title' => 'Example import configuration', | ||
'storage_pid' => 2, | ||
'files_folder' => '1:/staedte/beispielstadt/events/', | ||
'region' => '1', | ||
'rest_experience' => 'beispielstadt', | ||
], | ||
], | ||
]; |
43 changes: 43 additions & 0 deletions
43
...DataImport/Fixtures/Extensions/custom_event/Classes/EventListener/EventImportListener.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* Copyright (C) 2023 Daniel Siepmann <coding@daniel-siepmann.de> | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version 2 | ||
* of the License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA | ||
* 02110-1301, USA. | ||
*/ | ||
|
||
namespace WerkraumMedia\CustomEvent\EventListener; | ||
|
||
use Wrm\Events\Service\DestinationDataImportService\Events\EventImportEvent; | ||
|
||
final class EventImportListener | ||
{ | ||
public function __invoke(EventImportEvent $psr14Event): void | ||
{ | ||
$eventToImport = $psr14Event->getEventToImport(); | ||
$dates = $psr14Event->getEventToImport()->getDates(); | ||
foreach ($dates as $date) { | ||
$endToSkip = clone $date->getStart(); | ||
$endToSkip->modify('+15 minutes'); | ||
if ($date->getEnd() == $endToSkip) { | ||
$date->setEnd(null); | ||
} | ||
} | ||
$eventToImport->setDates($dates); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...4Events/DestinationDataImport/Fixtures/Extensions/custom_event/Configuration/Services.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Symfony\Component\DependencyInjection\Loader\Configurator; | ||
|
||
use WerkraumMedia\CustomEvent\EventListener\EventImportListener; | ||
use Wrm\Events\Service\DestinationDataImportService\Events\EventImportEvent; | ||
|
||
return static function (ContainerConfigurator $containerConfigurator) { | ||
$services = $containerConfigurator->services() | ||
->defaults() | ||
->autowire() | ||
->autoconfigure() | ||
; | ||
|
||
$services->load('WerkraumMedia\\CustomEvent\\', '../Classes/'); | ||
$services->set(EventImportListener::class) | ||
->tag( | ||
'event.listener', | ||
[ | ||
'event' => EventImportEvent::class, | ||
] | ||
) | ||
; | ||
}; |
Oops, something went wrong.