Ensure title of sys_file_metadata is not exceeded

The columns is limited by length.
We ensure we do crop incoming file names before adding them to the
database.
We would run into exception otherwise.
This commit is contained in:
Daniel Siepmann 2022-06-27 14:37:00 +02:00
parent fc8c2b3046
commit 96f07fd501
4 changed files with 266 additions and 1 deletions

View file

@ -498,7 +498,7 @@ class DestinationDataImportService
$this->metaDataRepository->update( $this->metaDataRepository->update(
$file->getUid(), $file->getUid(),
[ [
'title' => $media_object['value'], 'title' => $this->getShortenedString($media_object['value'], 100),
'description' => $media_object['description'] ?? '', 'description' => $media_object['description'] ?? '',
'alternative' => 'DD Import' 'alternative' => 'DD Import'
] ]
@ -651,4 +651,13 @@ class DestinationDataImportService
return (bool) $value; return (bool) $value;
} }
private function getShortenedString(string $string, int $lenght): string
{
if ($string === mb_substr($string, 0, $lenght)) {
return $string;
}
return mb_substr($string, 0, $lenght - 3) . ' …';
}
} }

View file

@ -0,0 +1,26 @@
"tx_events_domain_model_organizer",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
,"uid","pid","cruser_id","deleted","hidden","starttime","endtime","sys_language_uid","l10n_parent","t3ver_oid","t3ver_wsid","t3ver_state","t3ver_stage","name","street","district","city","zip","phone","web","email",,,,,,,,,,,,,,,,,,,,,,
,"1","2","0","0","0","0","0","-1","0","0","0","0","0","Schillerhaus Rudolstadt","Schillerstraße 25",,"Rudolstadt","07407","+ 49 3672 / 486470","http://schillerhaus.rudolstadt.de","schillerhaus@rudolstadt.de",,,,,,,,,,,,,,,,,,,,,,
"tx_events_domain_model_event",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
,"uid","pid","cruser_id","deleted","hidden","starttime","endtime","sys_language_uid","l10n_parent","t3ver_oid","t3ver_wsid","t3ver_state","t3ver_stage","title","subtitle","global_id","slug","highlight","teaser","details","price_info","name","street","district","city","zip","country","web","phone","ticket","facebook","youtube","instagram","latitude","longitude","images","categories","pages","dates","organizer","partner","region","references_events"
,"1","2","0","0","0","0","0","-1","0","0","0","0","0","Allerlei Weihnachtliches (Heute mit Johannes Geißer)",,"e_100347853","e-100347853","0",,"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.",,"Schillerhaus Rudolstadt","Schillerstraße 25",,"Rudolstadt","07407","Deutschland","http://www.schillerhaus.rudolstadt.de/","+ 49 3672 / 486470",,,,,"50.720971023259","11.335229873657","1","1",,"1","1",,"1",
"tx_events_domain_model_date",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
,"uid","pid","cruser_id","hidden","starttime","endtime","sys_language_uid","l10n_parent","t3ver_oid","t3ver_wsid","t3ver_state","event","start","end","canceled","postponed_date","canceled_link",,,,,,,,,,,,,,,,,,,,,,,,,,
,"1","2","0","0","0","0",-1,0,"0","0","0","1","4101372000","4101377400","no","0",,,,,,,,,,,,,,,,,,,,,,,,,,,
"sys_category",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
,"uid","pid","cruser_id","hidden","starttime","endtime","sys_language_uid","l10n_parent","title","items","parent",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
,1,2,0,0,0,0,0,0,"Top Category",0,0,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
,2,2,0,0,0,0,0,0,"Event Category Parent",0,1,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
,3,2,0,0,0,0,0,0,"Weihnachten",0,2,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
"sys_category_record_mm",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
,"uid_local","uid_foreign","tablenames","fieldname",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
,3,1,"tx_events_domain_model_event","categories",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
"sys_file_metadata",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
,"uid","pid","title","description","alternative",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
,1,0,"This title is longer then the supported 255 chars as limited by default by TYPO3 database. Also c …","This is a supported description","DD Import",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
"sys_file_reference",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
,"uid","uid_local","uid_foreign","tablenames","fieldname","title","description",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
,1,1,1,"tx_events_domain_model_event","images",,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,
1 tx_events_domain_model_organizer
2 uid pid cruser_id deleted hidden starttime endtime sys_language_uid l10n_parent t3ver_oid t3ver_wsid t3ver_state t3ver_stage name street district city zip phone web email
3 1 2 0 0 0 0 0 -1 0 0 0 0 0 Schillerhaus Rudolstadt Schillerstraße 25 Rudolstadt 07407 + 49 3672 / 486470 http://schillerhaus.rudolstadt.de schillerhaus@rudolstadt.de
4 tx_events_domain_model_event
5 uid pid cruser_id deleted hidden starttime endtime sys_language_uid l10n_parent t3ver_oid t3ver_wsid t3ver_state t3ver_stage title subtitle global_id slug highlight teaser details price_info name street district city zip country web phone ticket facebook youtube instagram latitude longitude images categories pages dates organizer partner region references_events
6 1 2 0 0 0 0 0 -1 0 0 0 0 0 Allerlei Weihnachtliches (Heute mit Johannes Geißer) e_100347853 e-100347853 0 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. Schillerhaus Rudolstadt Schillerstraße 25 Rudolstadt 07407 Deutschland http://www.schillerhaus.rudolstadt.de/ + 49 3672 / 486470 50.720971023259 11.335229873657 1 1 1 1 1
7 tx_events_domain_model_date
8 uid pid cruser_id hidden starttime endtime sys_language_uid l10n_parent t3ver_oid t3ver_wsid t3ver_state event start end canceled postponed_date canceled_link
9 1 2 0 0 0 0 -1 0 0 0 0 1 4101372000 4101377400 no 0
10 sys_category
11 uid pid cruser_id hidden starttime endtime sys_language_uid l10n_parent title items parent
12 1 2 0 0 0 0 0 0 Top Category 0 0
13 2 2 0 0 0 0 0 0 Event Category Parent 0 1
14 3 2 0 0 0 0 0 0 Weihnachten 0 2
15 sys_category_record_mm
16 uid_local uid_foreign tablenames fieldname
17 3 1 tx_events_domain_model_event categories
18 sys_file_metadata
19 uid pid title description alternative
20 1 0 This title is longer then the supported 255 chars as limited by default by TYPO3 database. Also c … This is a supported description DD Import
21 sys_file_reference
22 uid uid_local uid_foreign tablenames fieldname title description
23 1 1 1 tx_events_domain_model_event images

View file

@ -0,0 +1,177 @@
{
"status": "OK",
"count": 3,
"overallcount": 50,
"channels": [],
"facetGroups": [],
"items": [
{
"global_id": "e_100347853",
"id": "100347853",
"title": "Allerlei Weihnachtliches (Heute mit Johannes Geißer)",
"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.<br>Eintritt: 10 € (inkl. Gedeck mit weihnachtlicher Schillerlocke)<br>Um Voranmeldung unter 03672-486470 oder&nbsp;<a data-cke-saved-href=\"mailto:schillerhaus@rudolstadt.de\" href=\"mailto:schillerhaus@rudolstadt.de\">schillerhaus@rudolstadt.de</a>&nbsp;wird gebeten. <br><strong>Es gilt die 2G-PLUS-Regel.</strong>&nbsp;<br>"
},
{
"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": "venuewebsite",
"url": "http://schillerhaus.rudolstadt.de/",
"latitude": null,
"longitude": null,
"value": ""
},
{
"rel": "default",
"url": "https://dam.destination.one/849917/279ac45b3fc701a7197131f627164fffd9f8cc77bc75165e2fc2b864ed606920/theater-rudolstadt_johannes-gei-er_photo-by-lisa-stern_web_-jpg.jpg",
"type": "image/jpeg",
"latitude": null,
"longitude": null,
"width": 1920,
"height": 1080,
"value": "This title is longer then the supported 255 chars as limited by default by TYPO3 database. Also contains umläuts. Some more characters to reach the expected limit. This is still not enough, keep on going. Do not know who creates such long file names. We will truncate this long string. Doesn't have to be a valid file name. Theater-Rudolstadt_Johannes-Geißer_photo-by-Lisa-Stern_web_.jpg",
"description": "This is a supported description"
}
],
"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": []
}
]
}

View file

@ -0,0 +1,53 @@
<?php
namespace Wrm\Events\Tests\Functional\Import\DestinationDataTest;
use GuzzleHttp\Psr7\Response;
use TYPO3\CMS\Core\Utility\GeneralUtility;
class ImportDoesntBreakWithLongFileTitleTest extends AbstractTest
{
/**
* @test
*/
public function importsExampleAsExpected(): void
{
$fileImportPathConfiguration = 'staedte/beispielstadt/events/';
$fileImportPath = $this->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/ResponseWithVeryLongFileName.json') ?: ''),
new Response(200, [], file_get_contents(__DIR__ . '/Fixtures/ExampleImage.jpg') ?: ''),
]);
$tester = $this->executeCommand([
'storage-pid' => '2',
'rest-experience' => 'beispielstadt',
'files-folder' => $fileImportPathConfiguration,
'region-uid' => '1',
]);
self::assertSame(0, $tester->getStatusCode());
$this->assertCSVDataSet('EXT:events/Tests/Functional/Import/DestinationDataTest/Assertions/ImportDoesntBreakWithLongFileTitle.csv');
self::assertFileEquals(
__DIR__ . '/Assertions/EmptyLogFile.txt',
$this->getInstancePath() . '/typo3temp/var/log/typo3_0493d91d8e.log',
'Logfile was not empty.'
);
}
}