-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pkp/pkp-lib#7286 Refactor remaining mailables
- Loading branch information
Showing
129 changed files
with
3,340 additions
and
5,147 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
/** | ||
* @file Jobs/Notifications/IssuePublishedMailUsers.php | ||
* | ||
* Copyright (c) 2014-2022 Simon Fraser University | ||
* Copyright (c) 2000-2022 John Willinsky | ||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. | ||
* | ||
* @class IssuePublishedMailUsers | ||
* @ingroup jobs | ||
* | ||
* @brief Class to send emails when a new issue is published | ||
*/ | ||
|
||
namespace APP\Jobs\Notifications; | ||
|
||
use APP\core\Application; | ||
use APP\facades\Repo; | ||
use APP\mail\mailables\IssuePublishedNotify; | ||
use Illuminate\Bus\Batchable; | ||
use Illuminate\Support\Collection; | ||
use Illuminate\Support\Facades\Mail; | ||
use PKP\context\Context; | ||
use PKP\emailTemplate\EmailTemplate; | ||
use PKP\Support\Jobs\BaseJob; | ||
use PKP\user\User; | ||
|
||
class IssuePublishedMailUsers extends BaseJob | ||
{ | ||
use Batchable; | ||
|
||
protected Collection $recipientIds; | ||
protected int $contextId; | ||
protected User $sender; | ||
protected string $locale; | ||
|
||
public function __construct(Collection $recipientIds, int $contextId, User $sender, string $locale) | ||
{ | ||
parent::__construct(); | ||
|
||
$this->recipientIds = $recipientIds; | ||
$this->contextId = $contextId; | ||
$this->sender = $sender; | ||
$this->locale = $locale; | ||
} | ||
|
||
public function handle() | ||
{ | ||
$context = Application::getContextDAO()->getById($this->contextId); | ||
$template = Repo::emailTemplate()->getByKey($this->contextId, IssuePublishedNotify::getEmailTemplateKey()); | ||
foreach ($this->recipientIds as $recipientId) { | ||
$recipient = Repo::user()->get($recipientId); | ||
if (!$recipient) { | ||
continue; | ||
} | ||
$mailable = $this->createMailable($context, $recipient, $template); | ||
$mailable->setData($this->locale); | ||
Mail::send($mailable); | ||
} | ||
} | ||
|
||
/** | ||
* Creates new issue published notification email | ||
*/ | ||
protected function createMailable(Context $context, User $recipient, EmailTemplate $template): IssuePublishedNotify | ||
{ | ||
$mailable = new IssuePublishedNotify($context); | ||
$mailable | ||
->recipients([$recipient]) | ||
->sender($this->sender) | ||
->body($template->getData('body', $this->locale)) | ||
->subject($template->getData('subject', $this->locale)); | ||
|
||
return $mailable; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
<?php | ||
|
||
/** | ||
* @file Jobs/Notifications/OpenAccessMailUsers.php | ||
* | ||
* Copyright (c) 2014-2022 Simon Fraser University | ||
* Copyright (c) 2000-2022 John Willinsky | ||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. | ||
* | ||
* @class OpenAccessMailUsers | ||
* @ingroup jobs | ||
* | ||
* @brief Class to send issue open access notification to users | ||
*/ | ||
|
||
namespace APP\Jobs\Notifications; | ||
|
||
use APP\core\Application; | ||
use APP\facades\Repo; | ||
use APP\journal\Journal; | ||
use APP\mail\mailables\OpenAccessNotify; | ||
use APP\template\TemplateManager; | ||
use Illuminate\Bus\Batchable; | ||
use Illuminate\Support\Facades\Mail; | ||
use Illuminate\Support\LazyCollection; | ||
use PKP\Support\Jobs\BaseJob; | ||
use Symfony\Component\Mime\Message; | ||
|
||
class OpenAccessMailUsers extends BaseJob | ||
{ | ||
use Batchable; | ||
|
||
protected LazyCollection $users; | ||
protected int $contextId; | ||
protected int $issueId; | ||
|
||
public function __construct(LazyCollection $users, int $contextId, int $issueId) | ||
{ | ||
parent::__construct(); | ||
|
||
$this->users = $users; | ||
$this->contextId = $contextId; | ||
$this->issueId = $issueId; | ||
} | ||
|
||
public function handle() | ||
{ | ||
$contextDao = Application::getContextDAO(); | ||
$context = $contextDao->getById($this->contextId); /** @var Journal $context */ | ||
$issue = Repo::issue()->get($this->issueId); | ||
$locale = $context->getPrimaryLocale(); | ||
$template = Repo::emailTemplate()->getByKey($this->contextId, OpenAccessNotify::getEmailTemplateKey()); | ||
|
||
foreach ($this->users as $user) { | ||
$mailable = new OpenAccessNotify($context, $issue); | ||
$mailable | ||
->from($context->getData('contactEmail'), $context->getData('contactName')) | ||
->recipients([$user]); | ||
|
||
$templateMgr = TemplateManager::getManager(Application::get()->getRequest()); | ||
$templateMgr->assign($mailable->getSmartyTemplateVariables()); | ||
|
||
$mailable | ||
->subject($template->getData('subject', $locale)) | ||
->body($templateMgr->fetch('payments/openAccessNotifyEmail.tpl')); | ||
|
||
$mailable->withSymfonyMessage(function (Message $message) use ($templateMgr) { | ||
$message->getHeaders()->addHeader( | ||
'Content-Type', | ||
'multipart/alternative; boundary="' . $templateMgr->getTemplateVars('mimeBoundary') . '"' | ||
); | ||
}); | ||
|
||
Mail::send($mailable); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
/** | ||
* @file classes/mail/mailables/IssuePublishedNotify.php | ||
* | ||
* Copyright (c) 2014-2022 Simon Fraser University | ||
* Copyright (c) 2000-2022 John Willinsky | ||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. | ||
* | ||
* @class IssuePublishedNotify | ||
* @ingroup mail_mailables | ||
* | ||
* @brief Email is sent automatically to all registered users to notify about new published issue | ||
*/ | ||
|
||
namespace APP\mail\mailables; | ||
|
||
use APP\facades\Repo; | ||
use PKP\context\Context; | ||
use PKP\mail\Mailable; | ||
use PKP\mail\traits\Configurable; | ||
use PKP\mail\traits\Recipient; | ||
use PKP\mail\traits\Sender; | ||
use PKP\security\Role; | ||
|
||
class IssuePublishedNotify extends Mailable | ||
{ | ||
use Configurable; | ||
use Recipient; | ||
use Sender; | ||
|
||
protected static ?string $name = 'mailable.issuePublishNotify.name'; | ||
protected static ?string $description = 'mailable.issuePublishNotify.description'; | ||
protected static ?string $emailTemplateKey = 'ISSUE_PUBLISH_NOTIFY'; | ||
protected static array $groupIds = [self::GROUP_OTHER]; | ||
protected static array $fromRoleIds = [Role::ROLE_ID_MANAGER]; | ||
protected static array $toRoleIds = [Role::ROLE_ID_READER]; | ||
|
||
protected static string $issueIdentification = 'issueIdentification'; | ||
|
||
public function __construct(Context $context) | ||
{ | ||
parent::__construct(func_get_args()); | ||
$this->setupIssueIdentificationVariable($context); | ||
} | ||
|
||
/** | ||
* Adds description to the issueIdentification email template variable | ||
*/ | ||
public static function getDataDescriptions(): array | ||
{ | ||
$variables = parent::getDataDescriptions(); | ||
$variables[static::$issueIdentification] = __('emailTemplate.variable.issue.issueIdentification'); | ||
return $variables; | ||
} | ||
|
||
/** | ||
* Include current issue identification to be used as an email template variable | ||
*/ | ||
protected function setupIssueIdentificationVariable(Context $context) | ||
{ | ||
$issue = Repo::issue()->get($context->getData('currentIssueId')); | ||
$this->addData([ | ||
static::$issueIdentification => $issue->getData('identification') | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
/** | ||
* @file classes/mail/mailables/OpenAccessNotify.php | ||
* | ||
* Copyright (c) 2014-2022 Simon Fraser University | ||
* Copyright (c) 2000-2022 John Willinsky | ||
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING. | ||
* | ||
* @class OpenAccessNotify | ||
* | ||
* @brief Email sent to notify user about issue open access | ||
*/ | ||
|
||
namespace APP\mail\mailables; | ||
|
||
use APP\facades\Repo; | ||
use APP\issue\Issue; | ||
use APP\journal\Journal; | ||
use PKP\mail\Mailable; | ||
use PKP\mail\traits\Configurable; | ||
use PKP\mail\traits\Recipient; | ||
use PKP\security\Role; | ||
|
||
class OpenAccessNotify extends Mailable | ||
{ | ||
use Configurable; | ||
use Recipient; | ||
|
||
protected static ?string $name = 'mailable.openAccessNotify.name'; | ||
protected static ?string $description = 'mailable.openAccessNotify.description'; | ||
protected static ?string $emailTemplateKey = 'OPEN_ACCESS_NOTIFY'; | ||
protected static array $groupIds = [self::GROUP_OTHER]; | ||
protected static array $toRoleIds = [Role::ROLE_ID_READER]; | ||
|
||
protected Journal $context; | ||
protected Issue $issue; | ||
|
||
public function __construct(Journal $context, Issue $issue) | ||
{ | ||
parent::__construct([$context]); | ||
$this->context = $context; | ||
$this->issue = $issue; | ||
} | ||
|
||
/** | ||
* Setup Smarty variables for the message template | ||
*/ | ||
public function getSmartyTemplateVariables(): array | ||
{ | ||
$template = Repo::emailTemplate()->getByKey($this->context->getId(), static::$emailTemplateKey); | ||
return [ | ||
'body' => $template->getData('body', $this->context->getPrimaryLocale()), | ||
'mimeBoundary' => '==boundary_' . md5(microtime()), | ||
'issue' => $this->issue, | ||
'publishedSubmissions' => Repo::submission()->getInSections($this->issue->getId(), $this->issue->getJournalId()), | ||
]; | ||
} | ||
} |
Oops, something went wrong.