Skip to content

Commit 8c98a73

Browse files
Merge pull request #42 from lepidus/stable-3_3_0
fix/prevents registration of publications without related files (OMP 3.3.0)
2 parents 8ae67d8 + 34b1e88 commit 8c98a73

6 files changed

Lines changed: 60 additions & 3 deletions

File tree

.gitlab-ci.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ include:
1414
- git submodule update --init --depth 1
1515
- composer install
1616

17-
unit_test_php_7_3:
17+
plugin_unit_test_php_7_3:
1818
rules:
1919
- when: never
20+
21+
application_unit_test_php_7_3:
22+
rules:
23+
- when: never

classes/api/ThothEndpoint.inc.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public function register($slimRequest, $response, $args)
9393
try {
9494
$thothBookService = ThothService::book();
9595
$thothBookId = $thothBookService->register($publication, $thothImprintId);
96+
$thothBookService->setActive();
9697
$submission = Services::get('submission')->edit($submission, ['thothWorkId' => $thothBookId], $request);
9798
$this->handleNotification($request, $submission, true, $disableNotification);
9899
} catch (QueryException $e) {

classes/listeners/PublicationPublishListener.inc.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public function registerThothBook($hookName, $args)
5555
try {
5656
$thothBookService = ThothService::book();
5757
$thothBookId = $thothBookService->register($publication, $thothImprintId);
58+
$thothBookService->setActive();
5859
$submission = Services::get('submission')->edit($submission, ['thothWorkId' => $thothBookId], $request);
5960
$thothNotification->notifySuccess($request, $submission);
6061
} catch (QueryException $e) {

classes/services/ThothBookService.inc.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class ThothBookService
2222
{
2323
public $factory;
2424
public $repository;
25+
26+
private $originalThothBook;
2527
private $registeredEntryId;
2628

2729
public function __construct($factory, $repository)
@@ -30,6 +32,16 @@ public function __construct($factory, $repository)
3032
$this->repository = $repository;
3133
}
3234

35+
public function getOriginalThothBook()
36+
{
37+
return $this->originalThothBook;
38+
}
39+
40+
public function setOriginalThothBook($originalThothBook)
41+
{
42+
$this->originalThothBook = $originalThothBook;
43+
}
44+
3345
public function getRegisteredEntryId()
3446
{
3547
return $this->registeredEntryId;
@@ -45,6 +57,11 @@ public function register($publication, $thothImprintId)
4557
$thothBook = $this->factory->createFromPublication($publication);
4658
$thothBook->setImprintId($thothImprintId);
4759

60+
if ($thothBook->getWorkStatus() === ThothWork::WORK_STATUS_ACTIVE) {
61+
$this->setOriginalThothBook($thothBook);
62+
$thothBook->setWorkStatus(ThothWork::WORK_STATUS_FORTHCOMING);
63+
}
64+
4865
$thothBookId = $this->repository->add($thothBook);
4966
$publication->setData('thothBookId', $thothBookId);
5067
$this->setRegisteredEntryId($thothBookId);
@@ -122,4 +139,15 @@ public function deleteRegisteredEntry()
122139
$this->repository->delete($this->getRegisteredEntryId());
123140
$this->setRegisteredEntryId(null);
124141
}
142+
143+
public function setActive()
144+
{
145+
if ($this->getOriginalThothBook() === null) {
146+
return;
147+
}
148+
149+
$originalThothBook = $this->getOriginalThothBook();
150+
$originalThothBook->setWorkStatus(ThothWork::WORK_STATUS_ACTIVE);
151+
$this->repository->edit($originalThothBook);
152+
}
125153
}

classes/services/ThothPublicationService.inc.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ public function registerByPublication($publication)
5353
->getByPublicationId($publication->getId())
5454
->toArray();
5555
foreach ($publicationFormats as $publicationFormat) {
56+
if (!$this->canRegister($publicationFormat)) {
57+
continue;
58+
}
59+
5660
$this->register($publicationFormat, $thothBookId);
5761
}
5862
}
@@ -107,4 +111,23 @@ public function validate($publicationFormat)
107111

108112
return $errors;
109113
}
114+
115+
private function canRegister($publicationFormat)
116+
{
117+
if ($publicationFormat->getPhysicalFormat()) {
118+
return true;
119+
}
120+
121+
$submissionFiles = array_filter(
122+
iterator_to_array(Services::get('submissionFile')->getMany([
123+
'assocTypes' => [ASSOC_TYPE_PUBLICATION_FORMAT],
124+
'assocIds' => [$publicationFormat->getId()],
125+
])),
126+
function ($submissionFile) {
127+
return $submissionFile->getData('chapterId') == null;
128+
}
129+
);
130+
131+
return count($submissionFiles) > 0 || !empty($publicationFormat->getRemoteUrl());
132+
}
110133
}

version.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
<version>
44
<application>thoth</application>
55
<type>plugins.generic</type>
6-
<release>0.1.10.2</release>
7-
<date>2025-06-16</date>
6+
<release>0.1.10.3</release>
7+
<date>2025-08-04</date>
88
<lazy-load>1</lazy-load>
99
<class>ThothPlugin</class>
1010
</version>

0 commit comments

Comments
 (0)