From 3d98475a6cb6b5c651d610d4b73f1f44a602d31e Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Thu, 7 Jul 2022 08:22:45 +0200 Subject: [PATCH] Fix none working import of ticket links from destination data The existing code didn't work with the provided data. We added a new test case to cover the situation. We adjusted the existing code to check on the actual rel value instead of the keys. --- .../Service/DestinationDataImportService.php | 41 ++- Documentation/Changelog/2.4.2.rst | 29 ++ .../Assertions/ImportsTickets.csv | 4 + .../Fixtures/ResponseWithTickets.json | 347 ++++++++++++++++++ .../ImportsTicketsTest.php | 61 +++ ext_emconf.php | 2 +- 6 files changed, 469 insertions(+), 15 deletions(-) create mode 100644 Documentation/Changelog/2.4.2.rst create mode 100644 Tests/Functional/Import/DestinationDataTest/Assertions/ImportsTickets.csv create mode 100644 Tests/Functional/Import/DestinationDataTest/Fixtures/ResponseWithTickets.json create mode 100644 Tests/Functional/Import/DestinationDataTest/ImportsTicketsTest.php diff --git a/Classes/Service/DestinationDataImportService.php b/Classes/Service/DestinationDataImportService.php index 2a93c63..33edc7a 100644 --- a/Classes/Service/DestinationDataImportService.php +++ b/Classes/Service/DestinationDataImportService.php @@ -359,36 +359,49 @@ class DestinationDataImportService } } - /** - * @param array $media - */ private function setTickets(array $media): void { foreach ($media as $link) { - if ($link['rel'] == "ticket") { + if (isset($link['rel']) === false) { + continue; + } + + if ($link['rel'] === 'ticket') { $this->tmpCurrentEvent->setTicket($link['url']); - break; - } elseif ($link['rel'] == "booking" && !$this->multiArrayKeyExists('ticket', $media)) { + return; + } + + if ( + $link['rel'] === 'booking' + && !$this->hasRelation('ticket', $media) + ) { $this->tmpCurrentEvent->setTicket($link['url']); - break; - } elseif ($link['rel'] == "PRICE_KARTENLINK" && !$this->multiArrayKeyExists('ticket', $media) && !$this->multiArrayKeyExists('booking', $media)) { + return; + } + + if ( + $link['rel'] === 'PRICE_KARTENLINK' + && !$this->hasRelation('ticket', $media) + && !$this->hasRelation('booking', $media) + ) { $this->tmpCurrentEvent->setTicket($link['url']); + return; } } } - private function multiArrayKeyExists(string $needle, array $haystack): bool + private function hasRelation(string $needle, array $haystack): bool { foreach ($haystack as $key => $value) { - if ($needle == $key) { + if (isset($haystack['rel']) && $haystack['rel'] === $needle) { return true; } - if (is_array($value)) { - if ($this->multiArrayKeyExists($needle, $value) == true) { - return true; - } + + if (is_array($value) && $this->hasRelation($needle, $value)) { + return true; } } + return false; } diff --git a/Documentation/Changelog/2.4.2.rst b/Documentation/Changelog/2.4.2.rst new file mode 100644 index 0000000..a8d4887 --- /dev/null +++ b/Documentation/Changelog/2.4.2.rst @@ -0,0 +1,29 @@ +2.4.2 +===== + +Breaking +-------- + +Nothing + +Features +-------- + +Nothing + +Fixes +----- + +* Fix broken import of "ticket" property. + The existing code didn't work if the ticket was of type "booking" or "PRICE_KARTENLINK". + This got fixed and tests were added. + +Tasks +----- + +Nothing + +Deprecation +----------- + +Nothing diff --git a/Tests/Functional/Import/DestinationDataTest/Assertions/ImportsTickets.csv b/Tests/Functional/Import/DestinationDataTest/Assertions/ImportsTickets.csv new file mode 100644 index 0000000..85511cb --- /dev/null +++ b/Tests/Functional/Import/DestinationDataTest/Assertions/ImportsTickets.csv @@ -0,0 +1,4 @@ +"tx_events_domain_model_event",,,,, +,"uid","pid","title","global_id","ticket" +,"1","2","PRICE_KARTENLINK","e_100347853","https://www.ticketshop-thueringen.de/veranstaltungen/comedy/sonstiges/bodo-wartke-24230" +,"2","2","Booking","e_100354481","https://www.erfurt-tourismus.de/stadtfuehrung/individuell/altstadtfuehrung/onlinebuchung-altstadtfuehrung" diff --git a/Tests/Functional/Import/DestinationDataTest/Fixtures/ResponseWithTickets.json b/Tests/Functional/Import/DestinationDataTest/Fixtures/ResponseWithTickets.json new file mode 100644 index 0000000..544e239 --- /dev/null +++ b/Tests/Functional/Import/DestinationDataTest/Fixtures/ResponseWithTickets.json @@ -0,0 +1,347 @@ +{ + "status": "OK", + "count": 3, + "overallcount": 50, + "channels": [], + "facetGroups": [], + "items": [ + { + "global_id": "e_100347853", + "id": "100347853", + "title": "PRICE_KARTENLINK", + "type": "Event", + "categories": [ + "Weihnachten" + ], + "texts": [ + { + "rel": "details", + "type": "text/html", + "value": "Die Lichter sind entzündet, die Plätzchen duften, man rückt endlich wieder näher zusammen und lauscht den Geschichten. Vier Schauspieler*innen unseres Theaters überraschen mit ihren weihnachtlichen Texten, die sie für uns ausgewählt haben. Dazu plaudern sie über persönliche Anekdoten und erinnern sich an ihre schönsten und verrücktesten Weihnachtsfeste. Und da der Genuss in der Vorweihnachtszeit nicht fehlen darf, wird an jedem Adventssonntag eine andere weihnachtliche Spezialität serviert.
Eintritt: 10 € (inkl. Gedeck mit weihnachtlicher Schillerlocke)
Um Voranmeldung unter 03672-486470 oder schillerhaus@rudolstadt.de wird gebeten.
Es gilt die 2G-PLUS-Regel. 
" + }, + { + "rel": "details", + "type": "text/plain", + "value": "Die Lichter sind entzündet, die Plätzchen duften, man rückt endlich wieder näher zusammen und lauscht den Geschichten. Vier Schauspieler*innen unseres Theaters überraschen mit ihren weihnachtlichen Texten, die sie für uns ausgewählt haben. Dazu plaudern sie über persönliche Anekdoten und erinnern sich an ihre schönsten und verrücktesten Weihnachtsfeste. Und da der Genuss in der Vorweihnachtszeit nicht fehlen darf, wird an jedem Adventssonntag eine andere weihnachtliche Spezialität serviert.\nEintritt: 10 € (inkl. Gedeck mit weihnachtlicher Schillerlocke)\nUm Voranmeldung unter 03672-486470 oder schillerhaus@rudolstadt.de wird gebeten.\nEs gilt die 2G-PLUS-Regel." + }, + { + "rel": "teaser", + "type": "text/html" + }, + { + "rel": "teaser", + "type": "text/plain" + } + ], + "country": "Deutschland", + "areas": [ + "Rudolstadt und Umgebung" + ], + "city": "Rudolstadt", + "zip": "07407", + "street": "Schillerstraße 25", + "phone": "+ 49 3672 / 486470", + "fax": "+ 49 3672 / 486475", + "web": "http://www.schillerhaus.rudolstadt.de/", + "email": "schillerhaus@rudolstadt.de", + "author": "support@hubermedia.de", + "geo": { + "main": { + "latitude": 50.720971023258805, + "longitude": 11.335229873657227 + }, + "entry": [], + "attributes": [] + }, + "ratings": [ + { + "type": "eT4", + "value": 40.0 + }, + { + "type": "order", + "value": 99.0001 + } + ], + "cuisine_types": [], + "payment": [], + "media_objects": [ + { + "rel": "PRICE_KARTENLINK", + "url": "https://www.ticketshop-thueringen.de/veranstaltungen/comedy/sonstiges/bodo-wartke-24230", + "latitude": null, + "longitude": null, + "value": "Link zum Kartenverkauf" + } + ], + "keywords": [], + "timeIntervals": [ + { + "weekdays": [], + "start": "2099-12-19T15:00:00+01:00", + "end": "2099-12-19T16:30:00+01:00", + "tz": "Europe/Berlin", + "interval": 1 + } + ], + "kitchenTimeIntervals": [], + "deliveryTimeIntervals": [], + "numbers": [], + "name": "Schillerhaus Rudolstadt", + "attributes": [ + { + "key": "VO_Id", + "value": "100050775" + }, + { + "key": "VO_CategoryName", + "value": "POI" + }, + { + "key": "VA_Id", + "value": "100050775" + }, + { + "key": "VA_CategoryName", + "value": "POI" + }, + { + "key": "interval_first_match_start", + "value": "2099-12-19T15:00:00+01" + }, + { + "key": "interval_first_match_end", + "value": "2099-12-19T16:30:00+01" + }, + { + "key": "interval_match_count", + "value": "1" + } + ], + "features": [], + "addresses": [ + { + "name": "Städtetourismus in Thüringen e.V.", + "city": "Weimar", + "zip": "99423", + "street": "UNESCO-Platz 1", + "phone": "+49 (3643) 745 314", + "web": "http://www.thueringer-staedte.de", + "email": "verein@thueringer-staedte.de", + "rel": "author" + }, + { + "name": "Städtetourismus in Thüringen\" e.V.", + "web": "http://www.thueringer-staedte.de", + "email": "verein@thueringer-staedte.de", + "rel": "organisation" + }, + { + "name": "Schillerhaus Rudolstadt", + "city": "Rudolstadt", + "zip": "07407", + "street": "Schillerstraße 25", + "phone": "+ 49 3672 / 486470", + "fax": "+ 49 3672 / 486475", + "web": "http://schillerhaus.rudolstadt.de", + "email": "schillerhaus@rudolstadt.de", + "rel": "organizer" + } + ], + "created": "2099-10-31T12:29:00+00:00", + "changed": "2099-12-14T08:29:00+00:00", + "source": { + "url": "http://destination.one/", + "value": "destination.one" + }, + "company": "", + "district": "", + "postoffice": "", + "phone2": "", + "seasons": [], + "subitems": [], + "hyperObjects": [] + }, + { + "global_id": "e_100354481", + "id": "100354481", + "title": "Booking", + "type": "Event", + "categories": [ + "Kinder" + ], + "texts": [ + { + "rel": "details", + "type": "text/html", + "value": "Die Tüftlerzeit wird dieses Mal ein weihnachtliches Angebot bereithalten. Alle kleinen Tüftler dürfen gespannt sein.
Voranmeldung über: kinderbibliothek@rudolstadt.de oder 03672-486420

Bitte beachten Sie die derzeit geltenden Zugangsregeln." + }, + { + "rel": "details", + "type": "text/plain", + "value": "Die Tüftlerzeit wird dieses Mal ein weihnachtliches Angebot bereithalten. Alle kleinen Tüftler dürfen gespannt sein.\nVoranmeldung über: kinderbibliothek@rudolstadt.de oder 03672-486420\n\nBitte beachten Sie die derzeit geltenden Zugangsregeln." + }, + { + "rel": "teaser", + "type": "text/html" + }, + { + "rel": "teaser", + "type": "text/plain" + } + ], + "country": "Deutschland", + "areas": [ + "Rudolstadt und Umgebung" + ], + "city": "Rudolstadt", + "zip": "07407", + "street": "Schulplatz 13", + "phone": "0 36 72 - 48 64 20", + "fax": "0 36 72 - 48 64 30", + "web": "http://www.stadtbibliothek-rudolstadt.de/", + "email": "stadtbibliothek@rudolstadt.de", + "author": "support@hubermedia.de", + "geo": { + "main": { + "latitude": 50.720835175055917, + "longitude": 11.342568397521973 + }, + "entry": [], + "attributes": [] + }, + "ratings": [ + { + "type": "eT4", + "value": 40.0 + }, + { + "type": "order", + "value": 99.0001 + } + ], + "cuisine_types": [], + "payment": [], + "media_objects": [ + { + "rel": "booking", + "url": "https://www.erfurt-tourismus.de/stadtfuehrung/individuell/altstadtfuehrung/onlinebuchung-altstadtfuehrung", + "latitude": null, + "longitude": null, + "value": "InfoNetworking" + } + ], + "keywords": [], + "timeIntervals": [ + { + "weekdays": [], + "start": "2099-12-16T15:00:00+01:00", + "end": "2099-12-16T16:30:00+01:00", + "tz": "Europe/Berlin", + "interval": 1 + }, + { + "weekdays": [], + "start": "2099-04-01T11:00:00+02:00", + "end": "2099-04-01T13:00:00+02:00", + "repeatUntil": "2099-04-03T00:00+02:00", + "tz": "Europe/Berlin", + "freq": "Daily", + "interval": 1 + }, + { + "weekdays": [], + "start": "2099-02-17T15:00:00+01:00", + "end": "2099-02-17T17:00:00+01:00", + "tz": "Europe/Berlin", + "interval": 1 + } + ], + "kitchenTimeIntervals": [], + "deliveryTimeIntervals": [], + "numbers": [], + "name": "Stadtbibliothek Rudolstadt", + "attributes": [ + { + "key": "VO_Id", + "value": "100042570" + }, + { + "key": "VO_CategoryName", + "value": "POI" + }, + { + "key": "VA_Id", + "value": "100042570" + }, + { + "key": "VA_CategoryName", + "value": "POI" + }, + { + "key": "interval_first_match_start", + "value": "2099-12-16T15:00:00+01" + }, + { + "key": "interval_first_match_end", + "value": "2099-12-16T16:30:00+01" + }, + { + "key": "interval_match_count", + "value": "3" + }, + { + "key": "interval_last_match_start", + "value": "2022-02-17T15:00:00+01" + }, + { + "key": "interval_last_match_end", + "value": "2022-02-17T17:00:00+01" + } + ], + "features": [], + "addresses": [ + { + "name": "Städtetourismus in Thüringen e.V.", + "city": "Weimar", + "zip": "99423", + "street": "UNESCO-Platz 1", + "phone": "+49 (3643) 745 314", + "web": "http://www.thueringer-staedte.de", + "email": "verein@thueringer-staedte.de", + "rel": "author" + }, + { + "name": "Städtetourismus in Thüringen\" e.V.", + "web": "http://www.thueringer-staedte.de", + "email": "verein@thueringer-staedte.de", + "rel": "organisation" + }, + { + "name": "Stadtbibliothek Rudolstadt", + "city": "Rudolstadt", + "zip": "07407", + "street": "Schulplatz 13", + "phone": "0 36 72 - 48 64 20", + "fax": "0 36 72 - 48 64 30", + "web": "http://www.stadtbibliothek-rudolstadt.de ", + "email": "stadtbibliothek@rudolstadt.de", + "rel": "organizer" + } + ], + "created": "2099-11-10T23:02:00+00:00", + "changed": "2099-12-14T08:28:00+00:00", + "source": { + "url": "http://destination.one/", + "value": "destination.one" + }, + "company": "", + "district": "", + "postoffice": "", + "phone2": "", + "seasons": [], + "subitems": [], + "hyperObjects": [] + } + ] +} diff --git a/Tests/Functional/Import/DestinationDataTest/ImportsTicketsTest.php b/Tests/Functional/Import/DestinationDataTest/ImportsTicketsTest.php new file mode 100644 index 0000000..f5202f6 --- /dev/null +++ b/Tests/Functional/Import/DestinationDataTest/ImportsTicketsTest.php @@ -0,0 +1,61 @@ +getInstancePath() . '/fileadmin/' . $fileImportPathConfiguration; + GeneralUtility::mkdir_deep($fileImportPath); + + $this->importDataSet('EXT:events/Tests/Functional/Import/DestinationDataTest/Fixtures/SingleRegion.xml'); + $this->importDataSet('EXT:events/Tests/Functional/Import/DestinationDataTest/Fixtures/SingleCategory.xml'); + $this->setUpConfiguration([ + 'restUrl = https://example.com/some-path/', + 'license = example-license', + 'restType = Event', + 'restLimit = 3', + 'restMode = next_months,12', + 'restTemplate = ET2014A.json', + 'categoriesPid = 2', + 'categoryParentUid = 2', + ]); + + $requests = &$this->setUpResponses([ + new Response(200, [], file_get_contents(__DIR__ . '/Fixtures/ResponseWithTickets.json') ?: ''), + ]); + + $tester = $this->executeCommand([ + 'storage-pid' => '2', + 'rest-experience' => 'beispielstadt', + 'files-folder' => $fileImportPathConfiguration, + 'region-uid' => '1', + ]); + + self::assertSame(0, $tester->getStatusCode()); + + self::assertCount(1, $requests, 'Unexpected number of requests were made.'); + self::assertSame('https://example.com/some-path/?experience=beispielstadt&licensekey=example-license&type=Event&mode=next_months%2C12&limit=3&template=ET2014A.json', (string)$requests[0]['request']->getUri()); + + $this->assertCSVDataSet('EXT:events/Tests/Functional/Import/DestinationDataTest/Assertions/ImportsTickets.csv'); + + self::assertFileEquals( + __DIR__ . '/Assertions/EmptyLogFile.txt', + $this->getInstancePath() . '/typo3temp/var/log/typo3_0493d91d8e.log', + 'Logfile was not empty.' + ); + } +} diff --git a/ext_emconf.php b/ext_emconf.php index 6660c4d..47da7c2 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -9,7 +9,7 @@ $EM_CONF['events'] = [ 'state' => 'alpha', 'createDirs' => '', 'clearCacheOnLoad' => 0, - 'version' => '2.4.1', + 'version' => '2.4.2', 'constraints' => [ 'depends' => [ 'typo3' => '10.4.00-11.5.99',