Skip to content

Commit ea9c1d8

Browse files
Merge pull request #43 from lepidus/main
fix/prevents registration of publications without related files (OMP 3.4.0)
2 parents 27e7463 + d7a7900 commit ea9c1d8

6 files changed

Lines changed: 62 additions & 2 deletions

File tree

classes/api/ThothEndpoint.inc.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ public function register($slimRequest, $response, $args)
9999
try {
100100
$thothBookService = ThothService::book();
101101
$thothBookId = $thothBookService->register($publication, $thothImprintId);
102+
$thothBookService->setActive();
102103
Repo::submission()->edit($submission, ['thothWorkId' => $thothBookId]);
103104
$this->handleNotification($request, $submission, true, $disableNotification);
104105
} catch (QueryException $e) {

classes/listeners/PublicationPublishListener.inc.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ public function registerThothBook($hookName, $args)
5959
try {
6060
$thothBookService = ThothService::book();
6161
$thothBookId = $thothBookService->register($publication, $thothImprintId);
62+
$thothBookService->setActive();
6263
Repo::submission()->edit($submission, ['thothWorkId' => $thothBookId]);
6364
$thothNotification->notifySuccess($request, $submission);
6465
} catch (QueryException $e) {

classes/services/ThothBookService.inc.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616

1717
use PKP\db\DAORegistry;
18+
use ThothApi\GraphQL\Models\Work as ThothWork;
1819

1920
import('plugins.generic.thoth.classes.facades.ThothService');
2021
import('lib.pkp.classes.services.PKPSchemaService');
@@ -23,6 +24,8 @@ class ThothBookService
2324
{
2425
public $factory;
2526
public $repository;
27+
28+
private $originalThothBook;
2629
private $registeredEntryId;
2730

2831
public function __construct($factory, $repository)
@@ -31,6 +34,16 @@ public function __construct($factory, $repository)
3134
$this->repository = $repository;
3235
}
3336

37+
public function getOriginalThothBook()
38+
{
39+
return $this->originalThothBook;
40+
}
41+
42+
public function setOriginalThothBook($originalThothBook)
43+
{
44+
$this->originalThothBook = $originalThothBook;
45+
}
46+
3447
public function getRegisteredEntryId()
3548
{
3649
return $this->registeredEntryId;
@@ -46,6 +59,11 @@ public function register($publication, $thothImprintId)
4659
$thothBook = $this->factory->createFromPublication($publication);
4760
$thothBook->setImprintId($thothImprintId);
4861

62+
if ($thothBook->getWorkStatus() === ThothWork::WORK_STATUS_ACTIVE) {
63+
$this->setOriginalThothBook($thothBook);
64+
$thothBook->setWorkStatus(ThothWork::WORK_STATUS_FORTHCOMING);
65+
}
66+
4967
$thothBookId = $this->repository->add($thothBook);
5068
$publication->setData('thothBookId', $thothBookId);
5169
$this->setRegisteredEntryId($thothBookId);
@@ -122,4 +140,16 @@ public function deleteRegisteredEntry()
122140
$this->repository->delete($this->getRegisteredEntryId());
123141
$this->setRegisteredEntryId(null);
124142
}
143+
144+
public function setActive()
145+
{
146+
if ($this->getOriginalThothBook() === null) {
147+
return;
148+
}
149+
150+
$thothBook = $this->getOriginalThothBook();
151+
$thothBook->setWorkId($this->getRegisteredEntryId());
152+
$thothBook->setWorkStatus(ThothWork::WORK_STATUS_ACTIVE);
153+
$this->repository->edit($thothBook);
154+
}
125155
}

classes/services/ThothLocationService.inc.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* @brief Helper class that encapsulates business logic for Thoth locations
1515
*/
1616

17+
use APP\core\Application;
1718
use APP\facades\Repo;
1819

1920
class ThothLocationService

classes/services/ThothPublicationService.inc.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
* @brief Helper class that encapsulates business logic for Thoth publications
1515
*/
1616

17+
use APP\core\Application;
1718
use APP\facades\Repo;
1819
use Biblys\Isbn\Isbn;
1920
use Biblys\Isbn\IsbnParsingException;
@@ -54,6 +55,10 @@ public function registerByPublication($publication)
5455
$publicationFormats = DAORegistry::getDAO('PublicationFormatDAO')
5556
->getByPublicationId($publication->getId());
5657
foreach ($publicationFormats as $publicationFormat) {
58+
if (!$this->canRegister($publicationFormat)) {
59+
continue;
60+
}
61+
5762
$this->register($publicationFormat, $thothBookId);
5863
}
5964
}
@@ -108,4 +113,26 @@ public function validate($publicationFormat)
108113

109114
return $errors;
110115
}
116+
117+
public function canRegister($publicationFormat)
118+
{
119+
if ($publicationFormat->getPhysicalFormat()) {
120+
return true;
121+
}
122+
123+
$submissionFiles = array_filter(
124+
iterator_to_array(Repo::submissionFile()
125+
->getCollector()
126+
->filterByAssoc(
127+
Application::ASSOC_TYPE_PUBLICATION_FORMAT,
128+
[$publicationFormat->getId()]
129+
)
130+
->getMany()),
131+
function ($submissionFile) {
132+
return $submissionFile->getData('chapterId') == null;
133+
}
134+
);
135+
136+
return count($submissionFiles) > 0 || !empty($publicationFormat->getRemoteUrl());
137+
}
111138
}

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.2.8.2</release>
7-
<date>2025-06-16</date>
6+
<release>0.2.8.3</release>
7+
<date>2025-08-05</date>
88
<lazy-load>1</lazy-load>
99
<class>ThothPlugin</class>
1010
</version>

0 commit comments

Comments
 (0)