-
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 event to modify categories during destination data one import
A new PSR-14 event is added that allows to modify the categories to be assigned to an event. The event itself (including already existing categories) as well as the list of categories to be used after import are available. It is possible to change the categories to be assigned, e.g. keep some of the existing categories. That way it is possible for installations to add custom categories to events. Relates: #10623
- Loading branch information
1 parent
00946af
commit 2e1d313
Showing
14 changed files
with
549 additions
and
5 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
73 changes: 73 additions & 0 deletions
73
Classes/Service/DestinationDataImportService/Events/CategoriesAssignEvent.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,73 @@ | ||
<?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 TYPO3\CMS\Extbase\Persistence\ObjectStorage; | ||
use Wrm\Events\Domain\Model\Category; | ||
use Wrm\Events\Domain\Model\Event; | ||
|
||
final class CategoriesAssignEvent | ||
{ | ||
/** | ||
* @var Event | ||
*/ | ||
private $event; | ||
|
||
/** | ||
* @var ObjectStorage<Category> | ||
*/ | ||
private $categories; | ||
|
||
/** | ||
* @param ObjectStorage<Category> $categories | ||
*/ | ||
public function __construct( | ||
Event $event, | ||
ObjectStorage $categories | ||
) { | ||
$this->event = $event; | ||
$this->setCategories($categories); | ||
} | ||
|
||
public function getEvent(): Event | ||
{ | ||
return clone $this->event; | ||
} | ||
|
||
/** | ||
* @return ObjectStorage<Category> | ||
*/ | ||
public function getCategories(): ObjectStorage | ||
{ | ||
return clone $this->categories; | ||
} | ||
|
||
/** | ||
* @param ObjectStorage<Category> $categories | ||
*/ | ||
public function setCategories(ObjectStorage $categories): void | ||
{ | ||
$this->categories = $categories; | ||
} | ||
} |
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,31 @@ | ||
3.5.0 | ||
===== | ||
|
||
Breaking | ||
-------- | ||
|
||
Nothing | ||
|
||
Features | ||
-------- | ||
|
||
* Add PSR-14 Events to Destination Data One import. | ||
The following PSR-14 events were added. | ||
They allow individual installation to alter the import. | ||
|
||
See :ref:`psr14` for an overview of PSR-14 Events. | ||
|
||
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: Categories Assign | ||
|
||
Destination Data One Import: ``CategoriesAssignEvent`` | ||
------------------------------------------------------ | ||
|
||
Executed during Destination Data One Import. | ||
Allows to alter the categories to assign to an event. |
90 changes: 90 additions & 0 deletions
90
...estinationDataImport/Assertions/RegisteredEventHandlerCanKeepCustomCategoriesAssigned.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,90 @@ | ||
<?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', | ||
'categories_pid' => 2, | ||
'category_parent' => 2, | ||
], | ||
], | ||
'sys_category' => [ | ||
[ | ||
'uid' => 1, | ||
'pid' => 2, | ||
'parent' => 0, | ||
'title' => 'Events Root', | ||
], | ||
[ | ||
'uid' => 2, | ||
'pid' => 2, | ||
'parent' => 1, | ||
'title' => 'Events Categories', | ||
], | ||
[ | ||
'uid' => 3, | ||
'pid' => 2, | ||
'parent' => 1, | ||
'title' => 'Custom Parent', | ||
], | ||
[ | ||
'uid' => 4, | ||
'pid' => 2, | ||
'parent' => 3, | ||
'title' => 'Custom Category', | ||
], | ||
[ | ||
'uid' => 5, | ||
'pid' => 2, | ||
'parent' => 2, | ||
'title' => 'Konzerte, Festivals, Show & Tanz', | ||
], | ||
[ | ||
'uid' => 6, | ||
'pid' => 2, | ||
'parent' => 2, | ||
'title' => 'Weihnachten', | ||
], | ||
], | ||
'tx_events_domain_model_event' => [ | ||
[ | ||
'uid' => 1, | ||
'pid' => 2, | ||
'title' => 'Event for categories event', | ||
'global_id' => 'e_100350503', | ||
'categories' => 3, | ||
], | ||
], | ||
'sys_category_record_mm' => [ | ||
[ | ||
'uid_local' => 4, | ||
'uid_foreign' => 1, | ||
'tablenames' => 'tx_events_domain_model_event', | ||
'fieldname' => 'categories', | ||
'sorting' => 0, | ||
'sorting_foreign' => 3, | ||
], | ||
[ | ||
'uid_local' => 5, | ||
'uid_foreign' => 1, | ||
'tablenames' => 'tx_events_domain_model_event', | ||
'fieldname' => 'categories', | ||
'sorting' => 0, | ||
'sorting_foreign' => 1, | ||
], | ||
[ | ||
'uid_local' => 6, | ||
'uid_foreign' => 1, | ||
'tablenames' => 'tx_events_domain_model_event', | ||
'fieldname' => 'categories', | ||
'sorting' => 0, | ||
'sorting_foreign' => 2, | ||
], | ||
], | ||
]; |
59 changes: 59 additions & 0 deletions
59
Tests/Functional/Psr14Events/DestinationDataImport/CategoriesAssignEventTest.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 CategoriesAssignEventTest extends AbstractTest | ||
{ | ||
protected function setUp(): void | ||
{ | ||
$this->testExtensionsToLoad[] = 'typo3conf/ext/events/Tests/Functional/Psr14Events/DestinationDataImport/Fixtures/Extensions/custom_categories/'; | ||
|
||
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 registeredEventHandlerCanKeepCustomCategoriesAssigned(): void | ||
{ | ||
$this->importPHPDataSet(__DIR__ . '/Fixtures/Database/RegisteredEventHandlerCanKeepCustomCategoriesAssigned.php'); | ||
$this->setUpResponses([new Response(200, [], file_get_contents(__DIR__ . '/Fixtures/Responses/RegisteredEventHandlerCanKeepCustomCategoriesAssigned.json') ?: '')]); | ||
|
||
$this->executeCommand(); | ||
|
||
$this->assertPHPDataSet(__DIR__ . '/Assertions/RegisteredEventHandlerCanKeepCustomCategoriesAssigned.php'); | ||
} | ||
} |
Oops, something went wrong.