Skip to content

Commit 27e7463

Browse files
Merge pull request #40 from lepidus/main
Feature/fix plugin issues (OMP 3.4.0)
2 parents 39faf7c + 5ec80df commit 27e7463

8 files changed

Lines changed: 42 additions & 12 deletions

File tree

classes/api/ThothEndpoint.inc.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,12 @@ public function register($slimRequest, $response, $args)
9797

9898
$disableNotification = $params['disableNotification'] ?? false;
9999
try {
100-
$thothBookId = ThothService::book()->register($publication, $thothImprintId);
100+
$thothBookService = ThothService::book();
101+
$thothBookId = $thothBookService->register($publication, $thothImprintId);
101102
Repo::submission()->edit($submission, ['thothWorkId' => $thothBookId]);
102103
$this->handleNotification($request, $submission, true, $disableNotification);
103104
} catch (QueryException $e) {
105+
$thothBookService->deleteRegisteredEntry();
104106
$this->handleNotification($request, $submission, false, $disableNotification, $e->getMessage());
105107
$failure['errors'][] = __('plugins.generic.thoth.register.error.log', ['reason' => $e->getMessage()]);
106108
return $response->withStatus(403)->withJson($failure);

classes/factories/ThothContributionFactory.inc.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,14 @@
2020

2121
class ThothContributionFactory
2222
{
23-
public function createFromAuthor($author, $primaryContactId = null)
23+
public function createFromAuthor($author, $seq, $primaryContactId = null)
2424
{
2525
$userGroupLocaleKey = $author->getUserGroup()->getData('nameLocaleKey');
2626

2727
return new ThothContribution([
2828
'contributionType' => $this->getContributionTypeByUserGroupLocaleKey($userGroupLocaleKey),
2929
'mainContribution' => $this->isMainContribution($author, $primaryContactId),
30-
'contributionOrdinal' => $author->getSequence() + 1,
30+
'contributionOrdinal' => $seq + 1,
3131
'firstName' => $author->getLocalizedGivenName(),
3232
'lastName' => $author->getLocalizedFamilyName(),
3333
'fullName' => $author->getFullName(false),

classes/listeners/PublicationPublishListener.inc.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,10 +57,12 @@ public function registerThothBook($hookName, $args)
5757
$thothImprintId = $request->getUserVar('thothImprintId');
5858
$thothNotification = new ThothNotification();
5959
try {
60-
$thothBookId = ThothService::book()->register($publication, $thothImprintId);
60+
$thothBookService = ThothService::book();
61+
$thothBookId = $thothBookService->register($publication, $thothImprintId);
6162
Repo::submission()->edit($submission, ['thothWorkId' => $thothBookId]);
6263
$thothNotification->notifySuccess($request, $submission);
6364
} catch (QueryException $e) {
65+
$thothBookService->deleteRegisteredEntry();
6466
$thothNotification->notifyError($request, $submission, $e->getMessage());
6567
}
6668

classes/services/ThothBookService.inc.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,20 +23,32 @@ class ThothBookService
2323
{
2424
public $factory;
2525
public $repository;
26+
private $registeredEntryId;
2627

2728
public function __construct($factory, $repository)
2829
{
2930
$this->factory = $factory;
3031
$this->repository = $repository;
3132
}
3233

34+
public function getRegisteredEntryId()
35+
{
36+
return $this->registeredEntryId;
37+
}
38+
39+
public function setRegisteredEntryId($registeredEntryId)
40+
{
41+
$this->registeredEntryId = $registeredEntryId;
42+
}
43+
3344
public function register($publication, $thothImprintId)
3445
{
3546
$thothBook = $this->factory->createFromPublication($publication);
3647
$thothBook->setImprintId($thothImprintId);
3748

3849
$thothBookId = $this->repository->add($thothBook);
3950
$publication->setData('thothBookId', $thothBookId);
51+
$this->setRegisteredEntryId($thothBookId);
4052

4153
ThothService::contribution()->registerByPublication($publication);
4254
ThothService::publication()->registerByPublication($publication);
@@ -100,4 +112,14 @@ public function validate($publication)
100112

101113
return $errors;
102114
}
115+
116+
public function deleteRegisteredEntry()
117+
{
118+
if ($this->getRegisteredEntryId() === null) {
119+
return;
120+
}
121+
122+
$this->repository->delete($this->getRegisteredEntryId());
123+
$this->setRegisteredEntryId(null);
124+
}
103125
}

classes/services/ThothContributionService.inc.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ public function __construct($factory, $repository)
3131
$this->repository = $repository;
3232
}
3333

34-
public function register($author, $thothWorkId, $primaryContactId = null)
34+
public function register($author, $seq, $thothWorkId, $primaryContactId = null)
3535
{
36-
$thothContribution = $this->factory->createFromAuthor($author, $primaryContactId);
36+
$thothContribution = $this->factory->createFromAuthor($author, $seq, $primaryContactId);
3737
$thothContribution->setWorkId($thothWorkId);
3838

3939
$filter = empty($author->getOrcid()) ? $author->getFullName(false) : $author->getOrcid();
@@ -80,18 +80,22 @@ public function registerByPublication($publication)
8080
return $author->getId() === $primaryContactId || !in_array($author->getId(), $chapterAuthorIds);
8181
});
8282

83+
$seq = 0;
8384
$thothBookId = $publication->getData('thothBookId');
8485
foreach ($authors as $author) {
85-
$this->register($author, $thothBookId, $primaryContactId);
86+
$this->register($author, $seq, $thothBookId, $primaryContactId);
87+
$seq++;
8688
}
8789
}
8890

8991
public function registerByChapter($chapter)
9092
{
93+
$seq = 0;
9194
$thothChapterId = $chapter->getData('thothChapterId');
9295
$authors = $chapter->getAuthors()->toArray();
9396
foreach ($authors as $author) {
94-
$this->register($author, $thothChapterId);
97+
$this->register($author, $seq, $thothChapterId);
98+
$seq++;
9599
}
96100
}
97101
}

tests/classes/factories/ThothContributionFactoryTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public function testCreateThothContributionFromAuthor()
8080
$primaryContactId = 1;
8181

8282
$factory = new ThothContributionFactory();
83-
$thothContribution = $factory->createFromAuthor($mockAuthor, $primaryContactId);
83+
$thothContribution = $factory->createFromAuthor($mockAuthor, 0, $primaryContactId);
8484

8585
$this->assertEquals(new ThothContribution([
8686
'contributionType' => ThothContribution::CONTRIBUTION_TYPE_AUTHOR,

tests/classes/services/ThothContributionServiceTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function testRegisterContribution()
6060
$thothWorkId = '97fcc25c-361b-46f9-8c4b-016bfa36fb6d';
6161

6262
$service = new ThothContributionService($mockFactory, $mockRepository);
63-
$thothContributionId = $service->register($mockAuthor, $thothWorkId);
63+
$thothContributionId = $service->register($mockAuthor, 0, $thothWorkId);
6464

6565
$this->assertSame('e2d8dc3b-a5d9-4941-8ebd-52f0a70515bd', $thothContributionId);
6666
}

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

0 commit comments

Comments
 (0)