2222use Kitodo \Dlf \Domain \Model \Collection ;
2323use Kitodo \Dlf \Domain \Model \Document ;
2424use Kitodo \Dlf \Domain \Model \Library ;
25+ use Kitodo \Dlf \Validation \DocumentValidator ;
2526use Symfony \Component \Console \Command \Command ;
2627use TYPO3 \CMS \Core \Configuration \ExtensionConfiguration ;
2728use TYPO3 \CMS \Core \Utility \GeneralUtility ;
@@ -123,25 +124,16 @@ public function __construct(
123124 *
124125 * @param int $storagePid The storage pid
125126 *
126- * @return bool
127+ * @return void
127128 */
128- protected function initializeRepositories (int $ storagePid ): bool
129+ protected function initializeRepositories (int $ storagePid ): void
129130 {
130- if (MathUtility::canBeInterpretedAsInteger ($ storagePid )) {
131- $ frameworkConfiguration = $ this ->configurationManager ->getConfiguration (ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK );
132-
133- $ frameworkConfiguration ['persistence ' ]['storagePid ' ] = MathUtility::forceIntegerInRange ((int ) $ storagePid , 0 );
134- $ this ->configurationManager ->setConfiguration ($ frameworkConfiguration );
135-
136- // Get extension configuration.
137- $ this ->extConf = GeneralUtility::makeInstance (ExtensionConfiguration::class)->get ('dlf ' );
138- } else {
139- return false ;
140- }
141- $ this ->storagePid = MathUtility::forceIntegerInRange ((int ) $ storagePid , 0 );
131+ $ frameworkConfiguration = $ this ->configurationManager ->getConfiguration (ConfigurationManagerInterface::CONFIGURATION_TYPE_FRAMEWORK );
132+ $ frameworkConfiguration ['persistence ' ]['storagePid ' ] = MathUtility::forceIntegerInRange ($ storagePid , 0 );
133+ $ this ->configurationManager ->setConfiguration ($ frameworkConfiguration );
134+ $ this ->extConf = GeneralUtility::makeInstance (ExtensionConfiguration::class)->get ('dlf ' );
135+ $ this ->storagePid = MathUtility::forceIntegerInRange ($ storagePid , 0 );
142136 $ this ->persistenceManager = GeneralUtility::makeInstance (PersistenceManager::class);
143-
144- return true ;
145137 }
146138
147139 /**
@@ -216,71 +208,70 @@ protected function saveToDatabase(Document $document): bool
216208 $ doc ->cPid = $ this ->storagePid ;
217209
218210 $ metadata = $ doc ->getToplevelMetadata ($ this ->storagePid );
211+ $ validator = new DocumentValidator ($ metadata , explode (', ' , $ this ->extConf ['general ' ]['requiredMetadataFields ' ]));
212+
213+ if ($ validator ->hasAllMandatoryMetadataFields ()) {
214+ // set title data
215+ $ document ->setTitle ($ metadata ['title ' ][0 ] ? : '' );
216+ $ document ->setTitleSorting ($ metadata ['title_sorting ' ][0 ] ? : '' );
217+ $ document ->setPlace (implode ('; ' , $ metadata ['place ' ]));
218+ $ document ->setYear (implode ('; ' , $ metadata ['year ' ]));
219+ $ document ->setAuthor ($ this ->getAuthors ($ metadata ['author ' ]));
220+ $ document ->setThumbnail ($ doc ->thumbnail ? : '' );
221+ $ document ->setMetsLabel ($ metadata ['mets_label ' ][0 ] ? : '' );
222+ $ document ->setMetsOrderlabel ($ metadata ['mets_orderlabel ' ][0 ] ? : '' );
223+
224+ $ structure = $ this ->structureRepository ->findOneByIndexName ($ metadata ['type ' ][0 ]);
225+ $ document ->setStructure ($ structure );
226+
227+ if (is_array ($ metadata ['collection ' ])) {
228+ $ this ->addCollections ($ document , $ metadata ['collection ' ]);
229+ }
219230
220- // set title data
221- $ document ->setTitle ($ metadata ['title ' ][0 ] ? : '' );
222- $ document ->setTitleSorting ($ metadata ['title_sorting ' ][0 ] ? : '' );
223- $ document ->setPlace (implode ('; ' , $ metadata ['place ' ]));
224- $ document ->setYear (implode ('; ' , $ metadata ['year ' ]));
225-
226- // Remove appended "valueURI" from authors' names for storing in database.
227- foreach ($ metadata ['author ' ] as $ i => $ author ) {
228- $ splitName = explode (pack ('C ' , 31 ), $ author );
229- $ metadata ['author ' ][$ i ] = $ splitName [0 ];
230- }
231- $ document ->setAuthor ($ this ->getAuthors ($ metadata ['author ' ]));
232- $ document ->setThumbnail ($ doc ->thumbnail ? : '' );
233- $ document ->setMetsLabel ($ metadata ['mets_label ' ][0 ] ? : '' );
234- $ document ->setMetsOrderlabel ($ metadata ['mets_orderlabel ' ][0 ] ? : '' );
235-
236- $ structure = $ this ->structureRepository ->findOneByIndexName ($ metadata ['type ' ][0 ]);
237- $ document ->setStructure ($ structure );
231+ // set identifiers
232+ $ document ->setProdId ($ metadata ['prod_id ' ][0 ] ? : '' );
233+ $ document ->setOpacId ($ metadata ['opac_id ' ][0 ] ? : '' );
234+ $ document ->setUnionId ($ metadata ['union_id ' ][0 ] ? : '' );
235+
236+ $ document ->setRecordId ($ metadata ['record_id ' ][0 ]);
237+ $ document ->setUrn ($ metadata ['urn ' ][0 ] ? : '' );
238+ $ document ->setPurl ($ metadata ['purl ' ][0 ] ? : '' );
239+ $ document ->setDocumentFormat ($ metadata ['document_format ' ][0 ] ? : '' );
240+
241+ // set access
242+ $ document ->setLicense ($ metadata ['license ' ][0 ] ? : '' );
243+ $ document ->setTerms ($ metadata ['terms ' ][0 ] ? : '' );
244+ $ document ->setRestrictions ($ metadata ['restrictions ' ][0 ] ? : '' );
245+ $ document ->setOutOfPrint ($ metadata ['out_of_print ' ][0 ] ? : '' );
246+ $ document ->setRightsInfo ($ metadata ['rights_info ' ][0 ] ? : '' );
247+ $ document ->setStatus (0 );
248+
249+ $ this ->setOwner ($ metadata ['owner ' ][0 ]);
250+ $ document ->setOwner ($ this ->owner );
251+
252+ // set volume data
253+ $ document ->setVolume ($ metadata ['volume ' ][0 ] ? : '' );
254+ $ document ->setVolumeSorting ($ metadata ['volume_sorting ' ][0 ] ? : $ metadata ['mets_order ' ][0 ] ? : '' );
255+
256+ // Get UID of parent document.
257+ if ($ document ->getDocumentFormat () === 'METS ' ) {
258+ $ document ->setPartof ($ this ->getParentDocumentUidForSaving ($ document ));
259+ }
238260
239- if (is_array ($ metadata ['collection ' ])) {
240- $ this ->addCollections ($ document , $ metadata ['collection ' ]);
241- }
261+ if ($ document ->getUid () === null ) {
262+ // new document
263+ $ this ->documentRepository ->add ($ document );
264+ } else {
265+ // update of existing document
266+ $ this ->documentRepository ->update ($ document );
267+ }
242268
243- // set identifiers
244- $ document ->setProdId ($ metadata ['prod_id ' ][0 ] ? : '' );
245- $ document ->setOpacId ($ metadata ['opac_id ' ][0 ] ? : '' );
246- $ document ->setUnionId ($ metadata ['union_id ' ][0 ] ? : '' );
247-
248- $ document ->setRecordId ($ metadata ['record_id ' ][0 ] ? : '' ); // (?) $doc->recordId
249- $ document ->setUrn ($ metadata ['urn ' ][0 ] ? : '' );
250- $ document ->setPurl ($ metadata ['purl ' ][0 ] ? : '' );
251- $ document ->setDocumentFormat ($ metadata ['document_format ' ][0 ] ? : '' );
252-
253- // set access
254- $ document ->setLicense ($ metadata ['license ' ][0 ] ? : '' );
255- $ document ->setTerms ($ metadata ['terms ' ][0 ] ? : '' );
256- $ document ->setRestrictions ($ metadata ['restrictions ' ][0 ] ? : '' );
257- $ document ->setOutOfPrint ($ metadata ['out_of_print ' ][0 ] ? : '' );
258- $ document ->setRightsInfo ($ metadata ['rights_info ' ][0 ] ? : '' );
259- $ document ->setStatus (0 );
260-
261- $ this ->setOwner ($ metadata ['owner ' ][0 ]);
262- $ document ->setOwner ($ this ->owner );
263-
264- // set volume data
265- $ document ->setVolume ($ metadata ['volume ' ][0 ] ? : '' );
266- $ document ->setVolumeSorting ($ metadata ['volume_sorting ' ][0 ] ? : $ metadata ['mets_order ' ][0 ] ? : '' );
267-
268- // Get UID of parent document.
269- if ($ document ->getDocumentFormat () === 'METS ' ) {
270- $ document ->setPartof ($ this ->getParentDocumentUidForSaving ($ document ));
271- }
269+ $ this ->persistenceManager ->persistAll ();
272270
273- if ($ document ->getUid () === null ) {
274- // new document
275- $ this ->documentRepository ->add ($ document );
276- } else {
277- // update of existing document
278- $ this ->documentRepository ->update ($ document );
271+ return true ;
279272 }
280273
281- $ this ->persistenceManager ->persistAll ();
282-
283- return true ;
274+ return false ;
284275 }
285276
286277 /**
@@ -346,7 +337,7 @@ private function addCollections(Document &$document, array $collections): void
346337 $ documentCollection = GeneralUtility::makeInstance (Collection::class);
347338 $ documentCollection ->setIndexName ($ collection );
348339 $ documentCollection ->setLabel ($ collection );
349- $ documentCollection ->setOaiName ((!empty ($ this ->extConf ['publishNewCollections ' ]) ? Helper::getCleanString ($ collection ) : '' ));
340+ $ documentCollection ->setOaiName ((!empty ($ this ->extConf ['general ' ][ ' publishNewCollections ' ]) ? Helper::getCleanString ($ collection ) : '' ));
350341 $ documentCollection ->setIndexSearch ('' );
351342 $ documentCollection ->setDescription ('' );
352343 // add to CollectionRepository
@@ -371,6 +362,12 @@ private function addCollections(Document &$document, array $collections): void
371362 */
372363 private function getAuthors (array $ metadataAuthor ): string
373364 {
365+ // Remove appended "valueURI" from authors' names for storing in database.
366+ foreach ($ metadataAuthor as $ i => $ author ) {
367+ $ splitName = explode (pack ('C ' , 31 ), $ author );
368+ $ metadataAuthor [$ i ] = $ splitName [0 ];
369+ }
370+
374371 $ authors = '' ;
375372 $ delimiter = '; ' ;
376373 $ ellipsis = 'et al. ' ;
0 commit comments