@@ -38,7 +38,15 @@ public function register($publicationFormat, $thothWorkId, $chapterId = null)
3838 $ thothPublication ->setIsbn (null );
3939 }
4040
41- $ thothPublicationId = $ this ->repository ->add ($ thothPublication );
41+ $ thothPublicationId = $ this ->repository ->getIdByType (
42+ $ thothWorkId ,
43+ $ thothPublication ->getPublicationType ()
44+ );
45+
46+ if ($ thothPublicationId === null ) {
47+ $ thothPublicationId = $ this ->repository ->add ($ thothPublication );
48+ }
49+
4250 $ publicationFormat ->setData ('thothPublicationId ' , $ thothPublicationId );
4351
4452 ThothService::location ()->registerByPublicationFormat ($ publicationFormat , $ chapterId );
@@ -74,10 +82,22 @@ public function registerByChapter($chapter)
7482 return $ submissionFile ->getData ('chapterId ' ) == $ chapter ->getId ();
7583 });
7684
85+ $ publicationFormatIds = array_map (function ($ file ) {
86+ return $ file ->getData ('assocId ' );
87+ }, $ chapterSubmissionFiles );
88+
7789 $ thothChapterId = $ chapter ->getData ('thothChapterId ' );
7890 $ publicationFormatDao = DAORegistry::getDAO ('PublicationFormatDAO ' );
79- foreach ($ chapterSubmissionFiles as $ chapterSubmissionFile ) {
80- $ publicationFormat = $ publicationFormatDao ->getById ($ chapterSubmissionFile ->getData ('assocId ' ));
91+
92+ $ publicationFormats = [];
93+ foreach (array_unique ($ publicationFormatIds ) as $ publicationFormatId ) {
94+ $ publicationFormat = $ publicationFormatDao ->getById ($ publicationFormatId );
95+ if ($ publicationFormat ) {
96+ $ publicationFormats [$ publicationFormatId ] = $ publicationFormat ;
97+ }
98+ }
99+
100+ foreach ($ publicationFormats as $ publicationFormat ) {
81101 $ this ->register ($ publicationFormat , $ thothChapterId , $ chapter ->getId ());
82102 }
83103 }
0 commit comments