From 59e0a2d4ff5f28b4b3b89ba96891c6afb8c7ec2e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Zieli=C5=84ski?= Date: Tue, 27 Aug 2024 18:57:05 +0200 Subject: [PATCH] fix: fix sending orcid validate email on create author action during submission wizzard --- OrcidProfilePlugin.php | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/OrcidProfilePlugin.php b/OrcidProfilePlugin.php index d931eed..662e2a1 100755 --- a/OrcidProfilePlugin.php +++ b/OrcidProfilePlugin.php @@ -124,9 +124,6 @@ public function register($category, $path, $mainContextId = null) // Display additional ORCID access information and checkbox to send e-mail to authors in the AuthorForm Hook::add('authorform::display', $this->handleFormDisplay(...)); - // Send email to author, if the added checkbox was ticked - Hook::add('authorform::execute', $this->handleAuthorFormExecute(...)); - // Handle ORCID on user registration Hook::add('registrationform::execute', $this->collectUserOrcidId(...)); @@ -144,6 +141,7 @@ public function register($category, $path, $mainContextId = null) Hook::add('Mailer::Mailables', $this->addMailable(...)); Hook::add('Author::edit', $this->handleAuthorFormExecute(...)); + Hook::add('Author::add', $this->handleAuthorFormExecute(...)); Hook::add('Form::config::before', $this->addOrcidFormFields(...)); Hook::add('Installer::postInstall', $this->updateSchema(...)); Hook::add('Publication::validatePublish', $this->validate(...)); @@ -735,19 +733,17 @@ public function handleUserPublicProfileDisplay($hookName, $params) */ public function handleAuthorFormExecute($hookname, $args) { - if (count($args) == 3) { - /** @var Author */ - $author = &$args[0]; - $values = $args[2]; - - if ($author && $values['requestOrcidAuthorization']) { - $this->sendAuthorMail($author); - } + $request = Application::get()->getRequest(); + /** @var Author */ + $author = &$args[0]; + + if ($author && $request->getUserVar('requestOrcidAuthorization')) { + $this->sendAuthorMail($author); + } - if ($author && $values['deleteORCID']) { - $author->setOrcid(null); - $this->removeOrcidAccessToken($author, false); - } + if ($author && $request->getUserVar('deleteORCID')) { + $author->setOrcid(null); + $this->removeOrcidAccessToken($author, false); } } @@ -755,10 +751,8 @@ public function handleAuthorFormExecute($hookname, $args) * Send mail with ORCID authorization link to the e-mail address of the supplied Author object. * * @param Author $author - * @param bool $updateAuthor If true update the author fields in the database. - * Use this only if not called from a function, which does this anyway. */ - public function sendAuthorMail($author, $updateAuthor = false) + public function sendAuthorMail($author) { $request = Application::get()->getRequest(); $context = $request->getContext(); @@ -790,10 +784,8 @@ public function sendAuthorMail($author, $updateAuthor = false) $mailable->body($emailTemplate->getLocalizedData('body')) ->subject($emailTemplate->getLocalizedData('subject')); Mail::send($mailable); - - if ($updateAuthor) { - Repo::author()->dao->update($author); - } + + Repo::author()->dao->update($author); } } @@ -1516,7 +1508,7 @@ public function handleEditorAction($hookName, $args) foreach ($authors as $author) { $orcidAccessExpiresOn = Carbon::parse($author->getData('orcidAccessExpiresOn')); if ($author->getData('orcidAccessToken') == null || $orcidAccessExpiresOn->isPast()) { - $this->sendAuthorMail($author, true); + $this->sendAuthorMail($author); } } }