Skip to content

Commit

Permalink
Merge pull request #5 from thoth-pub/stable-3_4_0
Browse files Browse the repository at this point in the history
Release/v.2.1.0.0
  • Loading branch information
thiagolepidus authored Oct 18, 2024
2 parents 5df816b + ce73041 commit d492f78
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 9 deletions.
16 changes: 15 additions & 1 deletion classes/ThothNotification.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,10 @@
*/

use APP\core\Application;
use APP\facades\Repo;
use APP\notification\NotificationManager;
use PKP\core\JSONMessage;
use PKP\log\event\PKPSubmissionEventLogEntry;

class ThothNotification
{
Expand All @@ -27,7 +29,7 @@ public function __construct($plugin)
$this->plugin = $plugin;
}

public static function notify($request, $notificationType, $message)
public static function notify($request, $submission, $notificationType, $message, $logMessage)
{
$currentUser = $request->getUser();
$notificationMgr = new NotificationManager();
Expand All @@ -36,6 +38,18 @@ public static function notify($request, $notificationType, $message)
$notificationType,
['contents' => $message]
);

$eventLog = Repo::eventLog()->newDataObject([
'assocType' => Application::ASSOC_TYPE_SUBMISSION,
'assocId' => $submission->getId(),
'eventType' => PKPSubmissionEventLogEntry::SUBMISSION_LOG_CREATE_VERSION,
'userId' => $currentUser->getId(),
'message' => $logMessage,
'isTranslated' => true,
'dateLogged' => Core::getCurrentDate(),
]);
Repo::eventLog()->add($eventLog);

return new JSONMessage(false);
}

Expand Down
11 changes: 7 additions & 4 deletions classes/ThothRegister.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,19 +179,22 @@ public function registerWork($submission, $imprint)
try {
$thothClient = $this->plugin->getThothClient($submissionContext->getId());
$thothBook = ThothService::work()->registerBook($thothClient, $submission, $imprint);
$submission = Repo::submission()->edit($submission, ['thothWorkId' => $thothBook->getId()]);

Repo::submission()->edit($submission, ['thothWorkId' => $thothBook->getId()]);
ThothNotification::notify(
$request,
$submission,
Notification::NOTIFICATION_TYPE_SUCCESS,
__('plugins.generic.thoth.register.success')
__('plugins.generic.thoth.register.success'),
__('plugins.generic.thoth.log.register.success')
);
} catch (ThothException $e) {
error_log($e->getMessage());
ThothNotification::notify(
$request,
$submission,
Notification::NOTIFICATION_TYPE_ERROR,
__('plugins.generic.thoth.register.error')
__('plugins.generic.thoth.register.error'),
__('plugins.generic.thoth.log.register.error', ['reason' => $e->getError()])
);
}
}
Expand Down
9 changes: 6 additions & 3 deletions classes/ThothUpdater.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,21 @@ public function updateWork($hookName, $args)
try {
$thothClient = $this->plugin->getThothClient($submission->getData('contextId'));
ThothService::work()->updateBook($thothClient, $thothWorkId, $submission, $publication);

ThothNotification::notify(
$request,
$submission,
Notification::NOTIFICATION_TYPE_SUCCESS,
__('plugins.generic.thoth.update.success')
__('plugins.generic.thoth.update.success'),
__('plugins.generic.thoth.log.update.success')
);
} catch (ThothException $e) {
error_log($e->getMessage());
ThothNotification::notify(
$request,
$submission,
Notification::NOTIFICATION_TYPE_ERROR,
__('plugins.generic.thoth.update.error')
__('plugins.generic.thoth.update.error'),
__('plugins.generic.thoth.log.update.error', ['reason' => $e->getError()])
);
}

Expand Down
8 changes: 8 additions & 0 deletions lib/thothAPI/exceptions/ThothException.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,16 @@

class ThothException extends \RuntimeException
{
private $error;

public function __construct($error, $code)
{
$this->error = $error;
parent::__construct('Failed to send the request to Thoth: ' . $error, $code);
}

public function getError()
{
return $this->error;
}
}
12 changes: 12 additions & 0 deletions locale/en/locale.po
Original file line number Diff line number Diff line change
Expand Up @@ -70,5 +70,17 @@ msgstr ""
"There was a problem updating metadata in Thoth. Please try again later, or "
"contact your system administrator."

msgid "plugins.generic.thoth.log.register.success"
msgstr "Submission metadata registered in Thoth."

msgid "plugins.generic.thoth.log.register.error"
msgstr "Error registering metadata in Thoth. Reason: {$reason}"

msgid "plugins.generic.thoth.log.update.success"
msgstr "Submission metadata updated in Thoth."

msgid "plugins.generic.thoth.log.update.error"
msgstr "Error updating metadata in Thoth. Reason: {$reason}"

msgid "plugins.generic.thoth.api.403.alreadyRegistered"
msgstr "The submission is already registered in Thoth."
2 changes: 1 addition & 1 deletion version.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<version>
<application>thoth</application>
<type>plugins.generic</type>
<release>0.2.0.0</release>
<release>0.2.1.0</release>
<date>2024-10-18</date>
<lazy-load>1</lazy-load>
<class>ThothPlugin</class>
Expand Down

0 comments on commit d492f78

Please sign in to comment.