Пример #1
0
 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']);
         }
     }
 }
 /**
  *
  * @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;
 }