Skip to content

Commit

Permalink
Merge pull request #18 from lepidus/stable-3_3_0
Browse files Browse the repository at this point in the history
Feature/added contribution biography updating (OMP 3.3.0)
  • Loading branch information
thiagolepidus authored Nov 25, 2024
2 parents 6f5177b + ce669cd commit c84176e
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
1 change: 1 addition & 0 deletions classes/components/forms/RegisterForm.inc.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

/**
* @file plugins/generic/thoth/classes/components/form/RegisterForm.inc.php
*
Expand Down
16 changes: 12 additions & 4 deletions classes/services/ThothContributionService.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class ThothContributionService
public function new($params)
{
$contribution = new ThothContribution();
$contribution->setId($params['contributionId'] ?? null);
$contribution->setWorkId($params['workId'] ?? null);
$contribution->setContributorId($params['contributorId'] ?? null);
$contribution->setContributionType($params['contributionType']);
$contribution->setMainContribution($params['mainContribution']);
$contribution->setContributionOrdinal($params['contributionOrdinal']);
Expand All @@ -48,7 +51,7 @@ public function getDataByAuthor($author)
$data['firstName'] = $author->getLocalizedGivenName();
$data['lastName'] = $author->getLocalizedData('familyName');
$data['fullName'] = $author->getFullName(false);
$data['biography'] = $author->getLocalizedBiography();
$data['biography'] = strip_tags($author->getLocalizedBiography());
return $data;
}

Expand Down Expand Up @@ -99,8 +102,13 @@ public function updateContributions($thothClient, $thothContributions, $publicat

foreach ($authors as $author) {
$publicationContribution = $this->getDataByAuthor($author);
if (!$this->contributionInList($publicationContribution, $thothContributions)) {
if (!$thothContribution = $this->contributionInList($publicationContribution, $thothContributions)) {
$this->register($thothClient, $author, $thothWorkId);
continue;
}
if ($thothContribution['biography'] !== $publicationContribution['biography']) {
$thothContribution['biography'] = $publicationContribution['biography'];
$thothClient->updateContribution($this->new($thothContribution));
}
}
}
Expand All @@ -112,10 +120,10 @@ private function contributionInList($targetContribution, $contributions)
$contribution['firstName'] === $targetContribution['firstName']
&& $contribution['lastName'] === $targetContribution['lastName']
) {
return true;
return $contribution;
}
}
return false;
return null;
}

private function isMainContribution($author)
Expand Down
5 changes: 5 additions & 0 deletions lib/thothAPI/ThothClient.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ public function updatePublication($publication)
return $this->mutation('updatePublication', $publication);
}

public function updateContribution($contribution)
{
return $this->mutation('updateContribution', $contribution);
}

public function deleteWork($workId)
{
$data = ['workId' => $workId];
Expand Down
4 changes: 2 additions & 2 deletions version.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
<version>
<application>thoth</application>
<type>plugins.generic</type>
<release>0.1.3.2</release>
<date>2024-10-25</date>
<release>0.1.3.3</release>
<date>2024-11-25</date>
<lazy-load>1</lazy-load>
<class>ThothPlugin</class>
</version>

0 comments on commit c84176e

Please sign in to comment.