public function reSend($status, $sendingType) { $serverUrlHelper = new \Zend\View\Helper\ServerUrl(); $serverUrl = $serverUrlHelper->__invoke(); // files for errors and logs $logWorkerFilePath = $this->moduleOptions->getLogDir() . '/worker_send_mails_' . $now->format("Y-m-d_H-i-s") . '.log'; $errWorkerFilePath = $this->moduleOptions->getLogDir() . '/worker_send_mails_' . $now->format("Y-m-d_H-i-s") . '.err'; // sending action depends on sending type: bulk, individual etc. switch ($sendingType) { case 'bulk': $shell = 'php public/index.php send-bulk ' . $status->getId() . ' ' . $serverUrl . ' >' . $logWorkerFilePath . ' 2>' . $errWorkerFilePath . ' &'; break; case 'individual': $shell = 'php public/index.php send-individual ' . $status->getId() . ' >' . $logWorkerFilePath . ' 2>' . $errWorkerFilePath . ' &'; break; default: # code... break; } shell_exec($shell); /* return status for further tracking */ return $status; }
public function sendExceptionEmail(\Exception $e) { $this->setFrom('*****@*****.**'); $em = $this->getServiceLocator()->get('Doctrine\\ORM\\EntityManager'); $role = $em->getRepository("ErsBase\\Entity\\Role")->findOneBy(array('roleId' => 'supradm')); $users = $role->getUsers(); if (count($users) <= 0) { return false; } foreach ($users as $user) { $this->addTo($user); } $helper = new \Zend\View\Helper\ServerUrl(); $url = $helper->__invoke(true); $this->setSubject('An error occurred on ' . $url . ': ' . $e->getMessage()); $auth = $this->getServiceLocator()->get('zfcuser_auth_service'); if ($auth->hasIdentity()) { $email = $auth->getIdentity()->getEmail(); } else { $email = 'not logged in'; } $viewModel = new ViewModel(array('message' => 'An error occurred during execution', 'exception' => $e, 'email' => $email)); $viewModel->setTemplate('email/exception.phtml'); $viewRender = $this->getServiceLocator()->get('ViewRenderer'); $html = $viewRender->render($viewModel); $this->setHtmlMessage($html); $this->send(); return true; }