protected function _registerCallbacks() { $this->_registerClockworkCallbacks('10 seconds', array('CM_Model_User::offlineDelayed' => function () { CM_Model_User::offlineDelayed(); })); $this->_registerClockworkCallbacks('1 minute', array('CM_Model_User::offlineOld' => function () { CM_Model_User::offlineOld(); }, 'CM_ModelAsset_User_Roles::deleteOld' => function () { CM_ModelAsset_User_Roles::deleteOld(); }, 'CM_Paging_Useragent_Abstract::deleteOlder' => function () { CM_Paging_Useragent_Abstract::deleteOlder(100 * 86400); }, 'CM_File_UserContent_Temp::deleteOlder' => function () { CM_File_UserContent_Temp::deleteOlder(86400); }, 'CM_SVM_Model::deleteOldTrainings' => function () { CM_SVM_Model::deleteOldTrainings(3000); }, 'CM_Paging_Ip_Blocked::deleteOlder' => function () { CM_Paging_Ip_Blocked::deleteOld(); }, 'CM_Captcha::deleteOlder' => function () { CM_Captcha::deleteOlder(3600); }, 'CM_Session::deleteExpired' => function () { CM_Session::deleteExpired(); }, 'CM_Stream_Video::synchronize' => function () { CM_Stream_Video::getInstance()->synchronize(); }, 'CM_Stream_Video::checkStreams' => function () { CM_Stream_Video::getInstance()->checkStreams(); }, 'CM_MessageStream_Service::synchronize' => function () { CM_Service_Manager::getInstance()->getStreamMessage()->synchronize(); })); $this->_registerClockworkCallbacks('15 minutes', array('CM_Mail::processQueue' => function () { CM_Mail::processQueue(500); }, 'CM_Action_Abstract::aggregate' => function () { CM_Action_Abstract::aggregate(); }, 'CM_Action_Abstract::deleteTransgressionsOlder' => function () { CM_Action_Abstract::deleteTransgressionsOlder(3 * 31 * 86400); }, 'CM_Paging_Log_Abstract::cleanup' => function () { foreach (CM_Paging_Log_Abstract::getClassChildren() as $logClass) { /** @var CM_Paging_Log_Abstract $log */ $log = new $logClass(); $log->cleanUp(); } })); $this->_registerClockworkCallbacks('8 days', array('CMService_MaxMind::upgrade' => function () { try { $maxMind = new CMService_MaxMind(); $maxMind->upgrade(); } catch (Exception $exception) { if (!is_a($exception, 'CM_Exception')) { $exception = new CM_Exception($exception->getMessage(), ['file' => $exception->getFile(), 'line' => $exception->getLine(), 'trace' => $exception->getTraceAsString()]); } $exception->setSeverity(CM_Exception::FATAL); throw $exception; } })); }
/** * @param string $verbName * @param CM_Model_User|int $actor * @param int $typeEmail */ public function __construct($verbName, $actor, $typeEmail) { parent::__construct($verbName, $actor); $typeEmail = (int) $typeEmail; try { $className = CM_Mail::_getClassName($typeEmail); $this->_nameEmail = ucwords(CM_Util::uncamelize(str_replace('_', '', preg_replace('#\\A[^_]++_[^_]++_#', '', $className)), ' ')); } catch (CM_Class_Exception_TypeNotConfiguredException $exception) { $exception->setSeverity(CM_Exception::WARN); CM_Bootloader::getInstance()->getExceptionHandler()->handleException($exception); $this->_nameEmail = (string) $typeEmail; } }
public function testCustomHeadersQueue() { $mail = new CM_Mail(); $subject = uniqid(); $mail->setSubject($subject); $mail->addCustomHeader('X-Foo', 'bar'); $mail->addCustomHeader('X-Bar', 'foo'); $mail->addCustomHeader('X-Foo', 'baz'); $mail->addTo('test'); $mail->setText('bla'); $mail->send(true); $result = CM_Db_Db::select('cm_mail', 'customHeaders', array('subject' => $subject)); $row = $result->fetch(); $this->assertEquals(unserialize($row['customHeaders']), array('X-Foo' => ['bar', 'baz'], 'X-Bar' => ['foo'])); }
/** * @param CM_Mail $mail * @return string * @throws CM_Exception_Invalid */ public function getUrlEmailTracking(CM_Mail $mail) { if (!$mail->getRecipient()) { throw new CM_Exception_Invalid('Needs user'); } $params = array('user' => $mail->getRecipient()->getId(), 'mailType' => $mail->getType()); return CM_Util::link($this->getSite()->getUrl() . '/emailtracking/' . $this->getSite()->getId(), $params); }
/** * @param int $limit */ public static function processQueue($limit) { $limit = (int) $limit; $result = CM_Db_Db::execRead('SELECT * FROM `cm_mail` ORDER BY `createStamp` LIMIT ' . $limit); while ($row = $result->fetch()) { $mail = new CM_Mail(); foreach (unserialize($row['to']) as $to) { $mail->addTo($to['address'], $to['name']); } foreach (unserialize($row['replyTo']) as $replyTo) { $mail->addReplyTo($replyTo['address'], $replyTo['name']); } foreach (unserialize($row['cc']) as $cc) { $mail->addCc($cc['address'], $cc['name']); } foreach (unserialize($row['bcc']) as $bcc) { $mail->addBcc($bcc['address'], $bcc['name']); } if ($headerList = unserialize($row['customHeaders'])) { foreach ($headerList as $label => $valueList) { foreach ($valueList as $value) { $mail->addCustomHeader($label, $value); } } } $sender = unserialize($row['sender']); $mail->setSender($sender['address'], $sender['name']); $mail->_send($row['subject'], $row['text'], $row['html']); CM_Db_Db::delete('cm_mail', array('id' => $row['id'])); } }
/** * @param CM_Mail $mail * @param string $msg */ public function addMail(CM_Mail $mail, $msg) { $this->_add($msg, array('sender' => $mail->getSender(), 'replyTo' => $mail->getReplyTo(), 'to' => $mail->getTo(), 'cc' => $mail->getCc(), 'bcc' => $mail->getBcc())); }