From 9498fec7557733e3f95f4dfe75154ee454bc4d68 Mon Sep 17 00:00:00 2001 From: Daniel Siepmann Date: Tue, 14 May 2024 09:52:39 +0200 Subject: [PATCH] Add support for new PRICE_INFO_EXTRA field (#55) Support new `PRICE_INFO_EXTRA` field as price info. The existing field `PRICE_INFO` is kept as fallback. Relates: #11171 --- .../Service/DestinationDataImportService.php | 7 +- Documentation/Changelog/3.7.0.rst | 27 +++ .../Fixtures/ResponseWithNewPriceInfo.json | 178 +++++++++++++++++ .../ResponseWithNewPriceInfoExtra.json | 183 ++++++++++++++++++ .../Fixtures/ResponseWithNoPriceInfo.json | 173 +++++++++++++++++ .../ImportHandlesPricesTest.php | 143 ++++++++++++++ ext_emconf.php | 2 +- 7 files changed, 711 insertions(+), 2 deletions(-) create mode 100644 Documentation/Changelog/3.7.0.rst create mode 100644 Tests/Functional/Import/DestinationDataTest/Fixtures/ResponseWithNewPriceInfo.json create mode 100644 Tests/Functional/Import/DestinationDataTest/Fixtures/ResponseWithNewPriceInfoExtra.json create mode 100644 Tests/Functional/Import/DestinationDataTest/Fixtures/ResponseWithNoPriceInfo.json create mode 100644 Tests/Functional/Import/DestinationDataTest/ImportHandlesPricesTest.php diff --git a/Classes/Service/DestinationDataImportService.php b/Classes/Service/DestinationDataImportService.php index d54305b..acf8ba8 100644 --- a/Classes/Service/DestinationDataImportService.php +++ b/Classes/Service/DestinationDataImportService.php @@ -464,6 +464,7 @@ class DestinationDataImportService private function setTexts(array $texts): void { + $shouldSetPrice = true; foreach ($texts as $text) { if (isset($text['value']) === false) { continue; @@ -475,7 +476,11 @@ class DestinationDataImportService if ($text['rel'] == 'teaser' && $text['type'] == 'text/plain') { $this->tmpCurrentEvent->setTeaser(str_replace("\n\n", "\n", $text['value'])); } - if ($text['rel'] == 'PRICE_INFO' && $text['type'] == 'text/plain') { + if ($shouldSetPrice && $text['rel'] == 'PRICE_INFO_EXTRA' && $text['type'] == 'text/plain') { + $shouldSetPrice = false; + $this->tmpCurrentEvent->setPriceInfo(str_replace("\n\n", "\n", $text['value'])); + } + if ($shouldSetPrice && $text['rel'] == 'PRICE_INFO' && $text['type'] == 'text/plain') { $this->tmpCurrentEvent->setPriceInfo(str_replace("\n\n", "\n", $text['value'])); } } diff --git a/Documentation/Changelog/3.7.0.rst b/Documentation/Changelog/3.7.0.rst new file mode 100644 index 0000000..ac2ef8d --- /dev/null +++ b/Documentation/Changelog/3.7.0.rst @@ -0,0 +1,27 @@ +3.7.0 +===== + +Breaking +-------- + +Nothing + +Features +-------- + +* Support new ``PRICE_INFO_EXTRA`` field as price info. The existing field ``PRICE_INFO`` is kept as fallback. + +Fixes +----- + +Nothing + +Tasks +----- + +Nothing + +Deprecation +----------- + +Nothing diff --git a/Tests/Functional/Import/DestinationDataTest/Fixtures/ResponseWithNewPriceInfo.json b/Tests/Functional/Import/DestinationDataTest/Fixtures/ResponseWithNewPriceInfo.json new file mode 100644 index 0000000..f79ebd7 --- /dev/null +++ b/Tests/Functional/Import/DestinationDataTest/Fixtures/ResponseWithNewPriceInfo.json @@ -0,0 +1,178 @@ +{ + "status": "OK", + "count": 3, + "overallcount": 50, + "channels": [], + "facetGroups": [], + "items": [ + { + "global_id": "e_100350503", + "id": "100350503", + "title": "Adventliche Orgelmusik (Orgel: KMD Frank Bettenhausen)", + "type": "Event", + "categories": [ + "Konzerte, Festivals, Show & Tanz", + "Weihnachten" + ], + "texts": [ + { + "rel": "details", + "type": "text/html", + "value": "Immer mittwochs in der Adventszeit spielt Frank Bettenhausen solo und zusammen mit anderen Musikern auf der Steinmeyerorgel aus dem Jahr 1906.  Bekannte Adventslieder, barocke und romantische Kompositionen stehen neben besinnlichen Texten von Pfarrer Johannes-Martin Weiss.

Es gilt die 2G-PLUS-Regel.
" + }, + { + "rel": "details", + "type": "text/plain", + "value": "Immer mittwochs in der Adventszeit spielt Frank Bettenhausen solo und zusammen mit anderen Musikern auf der Steinmeyerorgel aus dem Jahr 1906. Bekannte Adventslieder, barocke und romantische Kompositionen stehen neben besinnlichen Texten von Pfarrer Johannes-Martin Weiss.\n\nEs gilt die 2G-PLUS-Regel." + }, + { + "rel": "PRICE_INFO", + "type": "text/plain", + "value": "Preis Info" + } + ], + "country": "Deutschland", + "areas": [ + "Rudolstadt und Umgebung" + ], + "city": "Rudolstadt", + "zip": "07407", + "street": "Caspar-Schulte-Straße", + "phone": "03672 - 48 96 13", + "author": "support@hubermedia.de", + "geo": { + "main": { + "latitude": 50.718688721182531, + "longitude": 11.327333450317383 + }, + "entry": [], + "attributes": [] + }, + "ratings": [ + { + "type": "eT4", + "value": 40.0 + }, + { + "type": "order", + "value": 99.0001 + } + ], + "cuisine_types": [], + "payment": [], + "media_objects": [ + ], + "keywords": [], + "timeIntervals": [ + { + "weekdays": [], + "start": "2022-12-01T19:00:00+01:00", + "end": "2022-12-01T20:00:00+01:00", + "tz": "Europe/Berlin", + "interval": 1 + }, + { + "weekdays": [ + "Saturday", + "Sunday" + ], + "start": "2022-11-02T11:00:00+01:00", + "end": "2022-11-02T13:00:00+01:00", + "repeatUntil": "2022-11-25T13:00:00+01:00", + "tz": "Europe/Berlin", + "freq": "Weekly", + "interval": 1 + }, + { + "weekdays": [], + "start": "2022-12-22T19:00:00+01:00", + "end": "2022-12-22T20:00:00+01:00", + "tz": "Europe/Berlin", + "interval": 1 + } + ], + "kitchenTimeIntervals": [], + "deliveryTimeIntervals": [], + "numbers": [], + "name": "Lutherkirche", + "attributes": [ + { + "key": "VO_Id", + "value": "100118350" + }, + { + "key": "VO_CategoryName", + "value": "POI" + }, + { + "key": "VA_Id", + "value": "100118350" + }, + { + "key": "VA_CategoryName", + "value": "POI" + }, + { + "key": "interval_first_match_start", + "value": "2022-12-15T19:00:00+01" + }, + { + "key": "interval_first_match_end", + "value": "2022-12-15T20:00:00+01" + }, + { + "key": "interval_match_count", + "value": "2" + }, + { + "key": "interval_last_match_start", + "value": "2022-12-22T19:00:00+01" + }, + { + "key": "interval_last_match_end", + "value": "2022-12-22T20: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": "Lutherkirche", + "city": "Rudolstadt", + "zip": "07407", + "street": "Caspar-Schulte-Straße", + "phone": "03672 - 48 96 13", + "rel": "organizer" + } + ], + "created": "2022-11-08T22:15:00+00:00", + "changed": "2022-12-14T08:38: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/Fixtures/ResponseWithNewPriceInfoExtra.json b/Tests/Functional/Import/DestinationDataTest/Fixtures/ResponseWithNewPriceInfoExtra.json new file mode 100644 index 0000000..d96677a --- /dev/null +++ b/Tests/Functional/Import/DestinationDataTest/Fixtures/ResponseWithNewPriceInfoExtra.json @@ -0,0 +1,183 @@ +{ + "status": "OK", + "count": 3, + "overallcount": 50, + "channels": [], + "facetGroups": [], + "items": [ + { + "global_id": "e_100350503", + "id": "100350503", + "title": "Adventliche Orgelmusik (Orgel: KMD Frank Bettenhausen)", + "type": "Event", + "categories": [ + "Konzerte, Festivals, Show & Tanz", + "Weihnachten" + ], + "texts": [ + { + "rel": "details", + "type": "text/html", + "value": "Immer mittwochs in der Adventszeit spielt Frank Bettenhausen solo und zusammen mit anderen Musikern auf der Steinmeyerorgel aus dem Jahr 1906.  Bekannte Adventslieder, barocke und romantische Kompositionen stehen neben besinnlichen Texten von Pfarrer Johannes-Martin Weiss.

Es gilt die 2G-PLUS-Regel.
" + }, + { + "rel": "details", + "type": "text/plain", + "value": "Immer mittwochs in der Adventszeit spielt Frank Bettenhausen solo und zusammen mit anderen Musikern auf der Steinmeyerorgel aus dem Jahr 1906. Bekannte Adventslieder, barocke und romantische Kompositionen stehen neben besinnlichen Texten von Pfarrer Johannes-Martin Weiss.\n\nEs gilt die 2G-PLUS-Regel." + }, + { + "rel": "PRICE_INFO_EXTRA", + "type": "text/plain", + "value": "Preis Info Extra" + }, + { + "rel": "PRICE_INFO", + "type": "text/plain", + "value": "Preis Info" + } + ], + "country": "Deutschland", + "areas": [ + "Rudolstadt und Umgebung" + ], + "city": "Rudolstadt", + "zip": "07407", + "street": "Caspar-Schulte-Straße", + "phone": "03672 - 48 96 13", + "author": "support@hubermedia.de", + "geo": { + "main": { + "latitude": 50.718688721182531, + "longitude": 11.327333450317383 + }, + "entry": [], + "attributes": [] + }, + "ratings": [ + { + "type": "eT4", + "value": 40.0 + }, + { + "type": "order", + "value": 99.0001 + } + ], + "cuisine_types": [], + "payment": [], + "media_objects": [ + ], + "keywords": [], + "timeIntervals": [ + { + "weekdays": [], + "start": "2022-12-01T19:00:00+01:00", + "end": "2022-12-01T20:00:00+01:00", + "tz": "Europe/Berlin", + "interval": 1 + }, + { + "weekdays": [ + "Saturday", + "Sunday" + ], + "start": "2022-11-02T11:00:00+01:00", + "end": "2022-11-02T13:00:00+01:00", + "repeatUntil": "2022-11-25T13:00:00+01:00", + "tz": "Europe/Berlin", + "freq": "Weekly", + "interval": 1 + }, + { + "weekdays": [], + "start": "2022-12-22T19:00:00+01:00", + "end": "2022-12-22T20:00:00+01:00", + "tz": "Europe/Berlin", + "interval": 1 + } + ], + "kitchenTimeIntervals": [], + "deliveryTimeIntervals": [], + "numbers": [], + "name": "Lutherkirche", + "attributes": [ + { + "key": "VO_Id", + "value": "100118350" + }, + { + "key": "VO_CategoryName", + "value": "POI" + }, + { + "key": "VA_Id", + "value": "100118350" + }, + { + "key": "VA_CategoryName", + "value": "POI" + }, + { + "key": "interval_first_match_start", + "value": "2022-12-15T19:00:00+01" + }, + { + "key": "interval_first_match_end", + "value": "2022-12-15T20:00:00+01" + }, + { + "key": "interval_match_count", + "value": "2" + }, + { + "key": "interval_last_match_start", + "value": "2022-12-22T19:00:00+01" + }, + { + "key": "interval_last_match_end", + "value": "2022-12-22T20: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": "Lutherkirche", + "city": "Rudolstadt", + "zip": "07407", + "street": "Caspar-Schulte-Straße", + "phone": "03672 - 48 96 13", + "rel": "organizer" + } + ], + "created": "2022-11-08T22:15:00+00:00", + "changed": "2022-12-14T08:38: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/Fixtures/ResponseWithNoPriceInfo.json b/Tests/Functional/Import/DestinationDataTest/Fixtures/ResponseWithNoPriceInfo.json new file mode 100644 index 0000000..c970f49 --- /dev/null +++ b/Tests/Functional/Import/DestinationDataTest/Fixtures/ResponseWithNoPriceInfo.json @@ -0,0 +1,173 @@ +{ + "status": "OK", + "count": 3, + "overallcount": 50, + "channels": [], + "facetGroups": [], + "items": [ + { + "global_id": "e_100350503", + "id": "100350503", + "title": "Adventliche Orgelmusik (Orgel: KMD Frank Bettenhausen)", + "type": "Event", + "categories": [ + "Konzerte, Festivals, Show & Tanz", + "Weihnachten" + ], + "texts": [ + { + "rel": "details", + "type": "text/html", + "value": "Immer mittwochs in der Adventszeit spielt Frank Bettenhausen solo und zusammen mit anderen Musikern auf der Steinmeyerorgel aus dem Jahr 1906.  Bekannte Adventslieder, barocke und romantische Kompositionen stehen neben besinnlichen Texten von Pfarrer Johannes-Martin Weiss.

Es gilt die 2G-PLUS-Regel.
" + }, + { + "rel": "details", + "type": "text/plain", + "value": "Immer mittwochs in der Adventszeit spielt Frank Bettenhausen solo und zusammen mit anderen Musikern auf der Steinmeyerorgel aus dem Jahr 1906. Bekannte Adventslieder, barocke und romantische Kompositionen stehen neben besinnlichen Texten von Pfarrer Johannes-Martin Weiss.\n\nEs gilt die 2G-PLUS-Regel." + } + ], + "country": "Deutschland", + "areas": [ + "Rudolstadt und Umgebung" + ], + "city": "Rudolstadt", + "zip": "07407", + "street": "Caspar-Schulte-Straße", + "phone": "03672 - 48 96 13", + "author": "support@hubermedia.de", + "geo": { + "main": { + "latitude": 50.718688721182531, + "longitude": 11.327333450317383 + }, + "entry": [], + "attributes": [] + }, + "ratings": [ + { + "type": "eT4", + "value": 40.0 + }, + { + "type": "order", + "value": 99.0001 + } + ], + "cuisine_types": [], + "payment": [], + "media_objects": [ + ], + "keywords": [], + "timeIntervals": [ + { + "weekdays": [], + "start": "2022-12-01T19:00:00+01:00", + "end": "2022-12-01T20:00:00+01:00", + "tz": "Europe/Berlin", + "interval": 1 + }, + { + "weekdays": [ + "Saturday", + "Sunday" + ], + "start": "2022-11-02T11:00:00+01:00", + "end": "2022-11-02T13:00:00+01:00", + "repeatUntil": "2022-11-25T13:00:00+01:00", + "tz": "Europe/Berlin", + "freq": "Weekly", + "interval": 1 + }, + { + "weekdays": [], + "start": "2022-12-22T19:00:00+01:00", + "end": "2022-12-22T20:00:00+01:00", + "tz": "Europe/Berlin", + "interval": 1 + } + ], + "kitchenTimeIntervals": [], + "deliveryTimeIntervals": [], + "numbers": [], + "name": "Lutherkirche", + "attributes": [ + { + "key": "VO_Id", + "value": "100118350" + }, + { + "key": "VO_CategoryName", + "value": "POI" + }, + { + "key": "VA_Id", + "value": "100118350" + }, + { + "key": "VA_CategoryName", + "value": "POI" + }, + { + "key": "interval_first_match_start", + "value": "2022-12-15T19:00:00+01" + }, + { + "key": "interval_first_match_end", + "value": "2022-12-15T20:00:00+01" + }, + { + "key": "interval_match_count", + "value": "2" + }, + { + "key": "interval_last_match_start", + "value": "2022-12-22T19:00:00+01" + }, + { + "key": "interval_last_match_end", + "value": "2022-12-22T20: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": "Lutherkirche", + "city": "Rudolstadt", + "zip": "07407", + "street": "Caspar-Schulte-Straße", + "phone": "03672 - 48 96 13", + "rel": "organizer" + } + ], + "created": "2022-11-08T22:15:00+00:00", + "changed": "2022-12-14T08:38: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/ImportHandlesPricesTest.php b/Tests/Functional/Import/DestinationDataTest/ImportHandlesPricesTest.php new file mode 100644 index 0000000..bace835 --- /dev/null +++ b/Tests/Functional/Import/DestinationDataTest/ImportHandlesPricesTest.php @@ -0,0 +1,143 @@ +importPHPDataSet(__DIR__ . '/Fixtures/Database/DefaultImportConfiguration.php'); + $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 addsNewPriceFromPriceInfo(): void + { + $this->setUpResponses([ + new Response(200, [], file_get_contents(__DIR__ . '/Fixtures/ResponseWithNewPriceInfo.json') ?: ''), + ]); + + $this->executeCommand(); + + self::assertSame( + 'Preis Info', + $this->getAllRecords('tx_events_domain_model_event')[0]['price_info'] ?? '' + ); + + $this->assertEmptyLog(); + } + + /** + * @test + */ + public function addsNewPriceFromPriceInfoExtra(): void + { + $this->setUpResponses([ + new Response(200, [], file_get_contents(__DIR__ . '/Fixtures/ResponseWithNewPriceInfoExtra.json') ?: ''), + ]); + + $this->executeCommand(); + + self::assertSame( + 'Preis Info Extra', + $this->getAllRecords('tx_events_domain_model_event')[0]['price_info'] ?? '' + ); + + $this->assertEmptyLog(); + } + + /** + * @test + */ + public function keepsNoLongerExistingPrice(): void + { + (new PhpDataSet())->import(['tx_events_domain_model_event' => [0 => [ + 'uid' => 1, + 'pid' => 2, + 'global_id' => 'e_100350503', + 'price_info' => 'Existing price info', + ]]]); + + $this->setUpResponses([ + new Response(200, [], file_get_contents(__DIR__ . '/Fixtures/ResponseWithNoPriceInfo.json') ?: ''), + ]); + + $this->executeCommand(); + + self::assertSame( + 'Existing price info', + $this->getAllRecords('tx_events_domain_model_event')[0]['price_info'] ?? '' + ); + + $this->assertEmptyLog(); + } + + /** + * @test + */ + public function updatesExistingPriceFromPriceInfo(): void + { + (new PhpDataSet())->import(['tx_events_domain_model_event' => [0 => [ + 'uid' => 1, + 'pid' => 2, + 'global_id' => 'e_100350503', + 'price_info' => 'Existing price info', + ]]]); + + $this->setUpResponses([ + new Response(200, [], file_get_contents(__DIR__ . '/Fixtures/ResponseWithNewPriceInfo.json') ?: ''), + ]); + + $this->executeCommand(); + + self::assertSame( + 'Preis Info', + $this->getAllRecords('tx_events_domain_model_event')[0]['price_info'] ?? '' + ); + + $this->assertEmptyLog(); + } + + /** + * @test + */ + public function updatesExistingPriceFromPriceInfoExtra(): void + { + (new PhpDataSet())->import(['tx_events_domain_model_event' => [0 => [ + 'uid' => 1, + 'pid' => 2, + 'global_id' => 'e_100350503', + 'price_info' => 'Existing price info', + ]]]); + + $this->setUpResponses([ + new Response(200, [], file_get_contents(__DIR__ . '/Fixtures/ResponseWithNewPriceInfoExtra.json') ?: ''), + ]); + + $this->executeCommand(); + + self::assertSame( + 'Preis Info Extra', + $this->getAllRecords('tx_events_domain_model_event')[0]['price_info'] ?? '' + ); + + $this->assertEmptyLog(); + } +} diff --git a/ext_emconf.php b/ext_emconf.php index 13bc675..0ad3069 100644 --- a/ext_emconf.php +++ b/ext_emconf.php @@ -9,7 +9,7 @@ $EM_CONF['events'] = [ 'state' => 'stable', 'createDirs' => '', 'clearCacheOnLoad' => 0, - 'version' => '3.6.0', + 'version' => '3.7.0', 'constraints' => [ 'depends' => [ 'typo3' => '10.4.00-11.5.99',