Skip to content

Commit 8ae67d8

Browse files
Merge pull request #41 from lepidus/stable-3_3_0
Feature/fix plugin issues (OMP 3.3.0)
2 parents f040206 + 0f1be07 commit 8ae67d8

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
@@ -91,10 +91,12 @@ public function register($slimRequest, $response, $args)
9191

9292
$disableNotification = $params['disableNotification'] ?? false;
9393
try {
94-
$thothBookId = ThothService::book()->register($publication, $thothImprintId);
94+
$thothBookService = ThothService::book();
95+
$thothBookId = $thothBookService->register($publication, $thothImprintId);
9596
$submission = Services::get('submission')->edit($submission, ['thothWorkId' => $thothBookId], $request);
9697
$this->handleNotification($request, $submission, true, $disableNotification);
9798
} catch (QueryException $e) {
99+
$thothBookService->deleteRegisteredEntry();
98100
$this->handleNotification($request, $submission, false, $disableNotification, $e->getMessage());
99101
$failure['errors'][] = __('plugins.generic.thoth.register.error.log', ['reason' => $e->getMessage()]);
100102
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->getLocalizedData('familyName'),
3333
'fullName' => $author->getFullName(false),

classes/listeners/PublicationPublishListener.inc.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,12 @@ public function registerThothBook($hookName, $args)
5353
$thothImprintId = $request->getUserVar('thothImprintId');
5454
$thothNotification = new ThothNotification();
5555
try {
56-
$thothBookId = ThothService::book()->register($publication, $thothImprintId);
56+
$thothBookService = ThothService::book();
57+
$thothBookId = $thothBookService->register($publication, $thothImprintId);
5758
$submission = Services::get('submission')->edit($submission, ['thothWorkId' => $thothBookId], $request);
5859
$thothNotification->notifySuccess($request, $submission);
5960
} catch (QueryException $e) {
61+
$thothBookService->deleteRegisteredEntry();
6062
$thothNotification->notifyError($request, $submission, $e->getMessage());
6163
}
6264

classes/services/ThothBookService.inc.php

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

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

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

3748
$thothBookId = $this->repository->add($thothBook);
3849
$publication->setData('thothBookId', $thothBookId);
50+
$this->setRegisteredEntryId($thothBookId);
3951

4052
ThothService::contribution()->registerByPublication($publication);
4153
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
@@ -27,9 +27,9 @@ public function __construct($factory, $repository)
2727
$this->repository = $repository;
2828
}
2929

30-
public function register($author, $thothWorkId, $primaryContactId = null)
30+
public function register($author, $seq, $thothWorkId, $primaryContactId = null)
3131
{
32-
$thothContribution = $this->factory->createFromAuthor($author, $primaryContactId);
32+
$thothContribution = $this->factory->createFromAuthor($author, $seq, $primaryContactId);
3333
$thothContribution->setWorkId($thothWorkId);
3434

3535
$filter = empty($author->getOrcid()) ? $author->getFullName(false) : $author->getOrcid();
@@ -64,18 +64,22 @@ public function registerByPublication($publication)
6464
return $author->getId() === $primaryContactId || !in_array($author->getId(), $chapterAuthorIds);
6565
});
6666

67+
$seq = 0;
6768
$thothBookId = $publication->getData('thothBookId');
6869
foreach ($authors as $author) {
69-
$this->register($author, $thothBookId, $primaryContactId);
70+
$this->register($author, $seq, $thothBookId, $primaryContactId);
71+
$seq++;
7072
}
7173
}
7274

7375
public function registerByChapter($chapter)
7476
{
77+
$seq = 0;
7578
$thothChapterId = $chapter->getData('thothChapterId');
7679
$authors = $chapter->getAuthors()->toArray();
7780
foreach ($authors as $author) {
78-
$this->register($author, $thothChapterId);
81+
$this->register($author, $seq, $thothChapterId);
82+
$seq++;
7983
}
8084
}
8185
}

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
@@ -59,7 +59,7 @@ public function testRegisterContribution()
5959
$thothWorkId = '97fcc25c-361b-46f9-8c4b-016bfa36fb6d';
6060

6161
$service = new ThothContributionService($mockFactory, $mockRepository);
62-
$thothContributionId = $service->register($mockAuthor, $thothWorkId);
62+
$thothContributionId = $service->register($mockAuthor, 0, $thothWorkId);
6363

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

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.1</release>
7-
<date>2025-05-16</date>
6+
<release>0.1.10.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)