Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: fix sending orcid validate email on create author action during … #321

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 15 additions & 23 deletions OrcidProfilePlugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(...));

Expand All @@ -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(...));
Expand Down Expand Up @@ -735,30 +733,26 @@ 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);
}
}

/**
* 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();
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
}
}
}
Expand Down