private function scheduleNotification($subject, $message, $recipients) { if (empty($recipients)) { $this->logger->warn("No recipients could be determined for email notification: skip operation"); return; } $addressesUsed = array(); foreach ($recipients as $recipient) { if (!in_array($recipient['address'], $addressesUsed)) { $job = new Opus_Job(); $job->setLabel(Opus_Job_Worker_MailNotification::LABEL); $job->setData(array('subject' => $subject, 'message' => $message, 'users' => array($recipient))); if (isset($this->config->runjobs->asynchronous) && $this->config->runjobs->asynchronous) { // Queue job (execute asynchronously) // skip creating job if equal job already exists if (true === $job->isUniqueInQueue()) { $job->store(); } } else { // Execute job immediately (synchronously) try { $mail = new Opus_Job_Worker_MailNotification($this->logger, false); $mail->work($job); } catch (Exception $exc) { $this->logger->err("Email notification failed: " . $exc); } } array_push($addressesUsed, $recipient['address']); } } }
* * LICENCE * OPUS is free software; you can redistribute it and/or modify it under the * terms of the GNU General Public License as published by the Free Software * Foundation; either version 2 of the Licence, or any later version. * OPUS is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. You should have received a copy of the GNU General Public License * along with OPUS; if not, write to the Free Software Foundation, Inc., 51 * Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * * @category Script * @author Jens Schwidder <*****@*****.**> * @copyright Copyright (c) 2008-2012, OPUS 4 development team * @license http://www.gnu.org/licenses/gpl.html General Public License * @version $Id: cron-send-notification.php 12554 2013-09-02 15:08:20Z schwidder $ */ // Define application environment (use 'production' by default) defined('APPLICATION_ENV') || define('APPLICATION_ENV', getenv('APPLICATION_ENV') ? getenv('APPLICATION_ENV') : 'production'); require_once dirname(__FILE__) . '/../common/bootstrap.php'; $jobrunner = new Opus_Job_Runner(); $jobrunner->setLogger(Zend_Registry::get('Zend_Log')); // no waiting between jobs $jobrunner->setDelay(0); // set a limit of 100 index jobs per run $jobrunner->setLimit(100); $mailWorker = new Opus_Job_Worker_MailNotification(null, false); $mailWorker->setLogger(Zend_Registry::get('Zend_Log')); $jobrunner->registerWorker($mailWorker); $jobrunner->run();
/** * * @param Matheon_Model_Document $document * @param array $recipient * @return void */ private function __sendPublishNotification($document, $recipient) { $config = $this->getConfig(); $baseUrlFiles = $this->view->serverUrl() . '/opus4-matheon/files'; $job = new Opus_Job(); $job->setLabel(Opus_Job_Worker_MailNotification::LABEL); $job->setData(array('subject' => $document->renderPublishMailSubject(), 'message' => $document->renderPublishMailBody($this->view->fullUrl(), $baseUrlFiles), 'users' => $recipient)); //throw new Exception(var_export($job, true)); if (isset($config->runjobs->asynchronous) && $config->runjobs->asynchronous) { // Queue job (execute asynchronously) // skip creating job if equal job already exists if (true === $job->isUniqueInQueue()) { $job->store(); } return true; } // Execute job immediately (synchronously) try { $mail = new Opus_Job_Worker_MailNotification($this->getLogger()); $mail->work($job); } catch (Exception $exc) { $this->getLogger()->err($exc); } return true; }