| Server IP : 172.67.178.83 / Your IP : 216.73.217.141 Web Server : Apache System : Linux hosting01.arsenalhost.com 4.18.0-425.13.1.lve.el8.x86_64 #1 SMP Mon Feb 27 15:23:24 EST 2023 x86_64 User : corbizre ( 1013) PHP Version : 7.4.33 Disable Function : exec,passthru,shell_exec,system MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /home/corbizre/gotofindhomes.com3/components/LiteMail/Controllers/ |
Upload File : |
<?php
/**
* Documentation
* @author keeper
* @category
* @package
* @subpackage
* @copyright Copyright (c) 2005-2009 ITCrimea Ukraine Inc. (http://www.itcrimea.com)
* @license
*/
class LiteMail_QueueController extends System_Controller_Db_Table
{
/**
* Logged in User_ID. Value setuped by init() function
*
* @var int
*/
private $UserID = null;
/**
* Documentation
* @author keeper
* @return mixed
*/
function init()
{
parent::init();
$this->UserID = $this->getRequest()->getParam('User_ID');
$this->_select->setIntegrityCheck(false);
$this->_selectCount->setIntegrityCheck(false);
}
/**
* Mail queues. Now redirects to getlist action
* @author
* @return mixed
*/
function indexAction()
{
$this->_forward('getlist');
}
/**
* Documentation
* @author [email protected]
* @return mixed
*/
function getAction()
{
$this->_helper->layout->disableLayout();
$this->_select->joinLeft('mails_templates', 'mails_templates.ID = mails_queues.MailTemplate_ID', array('MT_Type'=>'Type'));
parent::getAction();
}
/**
* Documentation
* @author [email protected]
* @return mixed
*/
function getlistAction()
{
$this->getRequest()->setParam('results', 50);
$Filter = new Zend_Session_Namespace('litemail_queue_getlist_filter');
$Filter->Type = $this->getRequest()->getParam('Type');
$Filter->DateFrom = $this->getRequest()->getParam('DateFrom', $Filter->DateFrom);
$Filter->DateTo = $this->getRequest()->getParam('DateTo', $Filter->DateTo);
$Filter->EmailTo = $this->getRequest()->getParam('EmailTo', $Filter->EmailTo);
if ($this->getRequest()->isPost()) {
$Filter->Page = 1;
}
if ($Filter->DateFrom) {
$date = strtotime($Filter->DateFrom . ' 12:00 AM');
$this->_select->where('UNIX_TIMESTAMP(mails_queues.DateAdded) > ?', $date);
$this->_selectCount->where('UNIX_TIMESTAMP(mails_queues.DateAdded) > ?', $date);
}
if ($Filter->DateTo) {
$date = strtotime($Filter->DateTo . ' 11:59 PM') + 1;
$this->_select->where('UNIX_TIMESTAMP(mails_queues.DateAdded) < ?', $date);
$this->_selectCount->where('UNIX_TIMESTAMP(mails_queues.DateAdded) < ?', $date);
}
if ($Filter->EmailTo) {
$this->_select->where('mails_queues.EmailTo LIKE ?', '%'.$Filter->EmailTo.'%');
$this->_selectCount->where('mails_queues.EmailTo LIKE ?', '%'.$Filter->EmailTo.'%');
}
if ($Filter->Type) {
if (is_array($Filter->Type) && count($Filter->Type)) {
$this->_select->where('mails_templates.Type IN (?) OR mails_queues_details.Type IN (?)', $Filter->Type);
$this->_selectCount->where('mails_templates.Type IN (?) OR mails_queues_details.Type IN (?)', $Filter->Type);
}
if (is_string($Filter->Type) || is_int($Filter->Type)) {
$this->_select->where('mails_templates.Type = ? OR mails_queues_details.Type = ?', $Filter->Type);
$this->_selectCount->where('mails_templates.Type = ? OR mails_queues_details.Type = ?', $Filter->Type);
}
}
$this->_select->joinLeft('mails_templates', 'mails_templates.ID = mails_queues.MailTemplate_ID', array('MT_Type'=>'Type'));
$this->_selectCount->joinLeft('mails_templates', 'mails_templates.ID = mails_queues.MailTemplate_ID', array());
//echo $this->_select;
$paramSort = $this->getRequest()->getParam('sort');
if (!$paramSort) {
$this->getRequest()->setParam('sort', 'ID');
$this->getRequest()->setParam('dir', 'desc');
}
parent::getlistAction();
$this->view->Filter = $Filter;
}
function serviceAction()
{
$config = $this->getConfig();
$intRuntime = isset($config->Queue->Service->Runtime) ? $config->Queue->Service->Runtime : 600;
$intSleepTime = isset($config->Queue->Service->SleepTime) ? $config->Queue->Service->SleepTime : 15;
//exit('$intRuntime = '.$intRuntime.'; $intSleepTime = '.$intSleepTime."\n");
set_time_limit($intRuntime + 120);
$AppFolder = Zend_Registry::get('AppFolder');
$CronFile = $AppFolder . '/logs/cron.mail.queue.service.txt';
$time = intval( file_get_contents($CronFile) );
if ($time && ( abs(mktime()-$time) < 90)) { // check is other cron script already works
//exit(date('Y-m-d H:i:s').' Can\'t start - other cron script already works'."\n");
exit();
}
$timeStart = mktime();
echo date('Y-m-d H:i:s').' Start'."\n";
$tableQueue = new LiteMail_Queue_Table();
$arrayTransports = array();
while (true) {
file_put_contents($CronFile, mktime());
$tableQueue->update(array('Status'=>LiteMail_Queue::STATUS_NEW, 'DateLockEnd'=>null),
new Zend_Db_Expr('`Status` = \''.LiteMail_Queue::STATUS_LOCK.'\' AND NOT ISNULL(`DateLockEnd`) AND `DateLockEnd` < NOW()')
);
$objectMail = $tableQueue->fetchRow(
$tableQueue->select()->
where(new Zend_Db_Expr('Status IN ('.LiteMail_Queue::STATUS_NEW.', '.LiteMail_Queue::STATUS_RESEND.')'))->
where(new Zend_Db_Expr('ISNULL(DateStart) OR (DateStart < NOW())'))->
where(new Zend_Db_Expr('ISNULL(DateLockEnd) OR (DateLockEnd < NOW())'))->
limit(1,0)
);
if (is_object($objectMail)) {
$paramPrevStatus = $objectMail->Status;
$objectMail->Status = LiteMail_Queue::STATUS_LOCK;
$objectMail->DateLockEnd = new Zend_Db_Expr('DATE_ADD(NOW(), INTERVAL 15 MINUTE)');
$objectMail->save();
// get transport options
if (isset($arrayTransports[$objectMail->EmailFrom])) {
$objectTransport = $arrayTransports[$objectMail->EmailFrom];
} else {
$objectTransport = LiteMail_Transport::find($objectMail->EmailFrom);
$arrayTransports[$objectMail->EmailFrom] = $objectTransport;
}
// send
try {
if ($objectTransport && $objectTransport->Delay > 0) {
usleep($objectTransport->Delay * 1000000); // sleep for time detected in delay (in seconds)
}
$paramStartTime = microtime(1);
$paramError = $objectMail->send($objectTransport); // send
if ($paramError) {
LogSystem::addLog(Settings::get('BrandName',''),'MailQueue','sender',$objectMail->ID,LogSystem::SEVERITY_ERR,$paramError,'');
$objectMail->Status = LiteMail_Queue::getStatusOnError($paramPrevStatus);
} else {
$objectMail->Status = LiteMail_Queue::STATUS_SENT;
$objectMail->DateSent = new Zend_Db_Expr('NOW()');
}
$objectMail->Runtime = number_format( (microtime(1)-$paramStartTime) , 2);
} catch (Exception $exception) {
// add log
LogSystem::addLog(Settings::get('BrandName',''),'MailQueue','sender',$objectMail->ID,LogSystem::SEVERITY_CRIT,'PHP FATAL ERROR: '.$exception->getMessage(),'');
$objectMail->Status = LiteMail_Queue::getStatusOnError($paramPrevStatus);
}
if ($objectMail->Status != LiteMail_Queue::STATUS_RESEND) {
$objectMail->DateLockEnd = null;
}
$objectMail->save();
unset($objectMail);
} else {
//exit();
if ($arrayTransports) {
unset($arrayTransports);
$arrayTransports = array();
}
usleep($intSleepTime * 1000000);
}
if ($timeStart+$intRuntime < mktime()) { // time to stop script
break;
}
}
exit(date('Y-m-d H:i:s').' Finish'."\n"."\n");
}
}