@@ -41,7 +41,15 @@ public function register($publicationFormat, $thothWorkId, $chapterId = null)
4141 $ thothPublication ->setIsbn (null );
4242 }
4343
44- $ thothPublicationId = $ this ->repository ->add ($ thothPublication );
44+ $ thothPublicationId = $ this ->repository ->getIdByType (
45+ $ thothWorkId ,
46+ $ thothPublication ->getPublicationType ()
47+ );
48+
49+ if ($ thothPublicationId === null ) {
50+ $ thothPublicationId = $ this ->repository ->add ($ thothPublication );
51+ }
52+
4553 $ publicationFormat ->setData ('thothPublicationId ' , $ thothPublicationId );
4654
4755 ThothService::location ()->registerByPublicationFormat ($ publicationFormat , $ chapterId );
@@ -72,14 +80,27 @@ public function registerByChapter($chapter)
7280 ->filterByAssoc (Application::ASSOC_TYPE_PUBLICATION_FORMAT )
7381 ->getMany ()
7482 );
83+
7584 $ chapterSubmissionFiles = array_filter ($ submissionFiles , function ($ submissionFile ) use ($ chapter ) {
7685 return $ submissionFile ->getData ('chapterId ' ) == $ chapter ->getId ();
7786 });
7887
88+ $ publicationFormatIds = array_map (function ($ file ) {
89+ return $ file ->getData ('assocId ' );
90+ }, $ chapterSubmissionFiles );
91+
7992 $ thothChapterId = $ chapter ->getData ('thothChapterId ' );
8093 $ publicationFormatDao = DAORegistry::getDAO ('PublicationFormatDAO ' );
81- foreach ($ chapterSubmissionFiles as $ chapterSubmissionFile ) {
82- $ publicationFormat = $ publicationFormatDao ->getById ($ chapterSubmissionFile ->getData ('assocId ' ));
94+
95+ $ publicationFormats = [];
96+ foreach (array_unique ($ publicationFormatIds ) as $ publicationFormatId ) {
97+ $ publicationFormat = $ publicationFormatDao ->getById ($ publicationFormatId );
98+ if ($ publicationFormat ) {
99+ $ publicationFormats [$ publicationFormatId ] = $ publicationFormat ;
100+ }
101+ }
102+
103+ foreach ($ publicationFormats as $ publicationFormat ) {
83104 $ this ->register ($ publicationFormat , $ thothChapterId , $ chapter ->getId ());
84105 }
85106 }
0 commit comments