BUG 9597 "cron.php sending old emails need to be configured" SOLVED
- cron.php it forwards all the emails without importing if they are or not very old - Problem solved, is taken into account the parameter "+d" as the starting date for the forwarding of mail, if not define this parameter will be forwarded emails from 7 days ago, forward
This commit is contained in:
@@ -68,8 +68,9 @@ else {
|
||||
$WS = '';
|
||||
$argsx = '';
|
||||
$sDate = '';
|
||||
for($i=1; $i<count($argv); $i++){
|
||||
$dateSystem = date("Y-m-d H:i:s");
|
||||
|
||||
for ($i = 1; $i <= count($argv) - 1; $i++) {
|
||||
if( strpos($argv[$i], '+d') !== false){
|
||||
$sDate = substr($argv[$i],2);
|
||||
} else if( strpos($argv[$i], '+w') !== false){
|
||||
@@ -79,12 +80,11 @@ for($i=1; $i<count($argv); $i++){
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//if $sDate is not set, so take the system time
|
||||
if($sDate!=''){
|
||||
eprintln("[Applying date filter: $sDate]");
|
||||
if ($sDate != "") {
|
||||
eprintln("[Applying date filter: $sDate]");
|
||||
} else {
|
||||
$sDate = date('Y-m-d H:i:s');
|
||||
$sDate = $dateSystem;
|
||||
}
|
||||
|
||||
|
||||
@@ -97,14 +97,14 @@ if( $WS=='' ){
|
||||
|
||||
if (file_exists(PATH_DB . $sObject . PATH_SEP . 'db.php')) {
|
||||
$cws++;
|
||||
system("php -f \"".dirname(__FILE__).PATH_SEP."cron_single.php\" $sObject \"$sDate\" $argsx", $retval);
|
||||
system("php -f \"".dirname(__FILE__).PATH_SEP."cron_single.php\" $sObject \"$sDate\" \"$dateSystem\" $argsx", $retval);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$cws = 1;
|
||||
system("php -f \"".dirname(__FILE__).PATH_SEP."cron_single.php\" $WS \"$sDate\" $argsx", $retval);
|
||||
system("php -f \"".dirname(__FILE__).PATH_SEP."cron_single.php\" $WS \"$sDate\" \"$dateSystem\" $argsx", $retval);
|
||||
}
|
||||
eprintln("Finished $cws workspaces processed.");
|
||||
|
||||
|
||||
@@ -115,9 +115,10 @@ if (file_exists(PATH_DATA . 'cron')) {
|
||||
if (!defined('SYS_SYS')) {
|
||||
$sObject = $argv[1];
|
||||
$sNow = $argv[2];
|
||||
$dateSystem = $argv[3];
|
||||
$sFilter = '';
|
||||
|
||||
for ($i = 3; $i < count($argv); $i++) {
|
||||
for ($i = 4; $i <= count($argv) - 1; $i++) {
|
||||
$sFilter .= ' ' . $argv[$i];
|
||||
}
|
||||
|
||||
@@ -244,35 +245,54 @@ function processWorkspace()
|
||||
function resendEmails()
|
||||
{
|
||||
global $sFilter;
|
||||
global $sNow;
|
||||
global $dateSystem;
|
||||
|
||||
if ($sFilter != '' && strpos($sFilter, 'emails') === false) {
|
||||
if ($sFilter != "" && strpos($sFilter, "emails") === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
setExecutionMessage("Resending emails");
|
||||
|
||||
try {
|
||||
G::LoadClass('spool');
|
||||
G::LoadClass("spool");
|
||||
|
||||
$dateResend = $sNow;
|
||||
|
||||
if ($sNow == $dateSystem) {
|
||||
$arrayDateSystem = getdate(strtotime($dateSystem));
|
||||
|
||||
$mktDateSystem = mktime(
|
||||
$arrayDateSystem["hours"],
|
||||
$arrayDateSystem["minutes"],
|
||||
$arrayDateSystem["seconds"],
|
||||
$arrayDateSystem["mon"],
|
||||
$arrayDateSystem["mday"],
|
||||
$arrayDateSystem["year"]
|
||||
);
|
||||
|
||||
$dateResend = date("Y-m-d H:i:s", $mktDateSystem - (7 * 24 * 60 * 60));
|
||||
}
|
||||
|
||||
$oSpool = new spoolRun();
|
||||
$oSpool->resendEmails();
|
||||
$oSpool->resendEmails($dateResend);
|
||||
|
||||
saveLog('resendEmails', 'action', 'Resending Emails', "c");
|
||||
saveLog("resendEmails", "action", "Resending Emails", "c");
|
||||
|
||||
$aSpoolWarnings = $oSpool->getWarnings();
|
||||
|
||||
if ( $aSpoolWarnings !== false ) {
|
||||
if ($aSpoolWarnings !== false) {
|
||||
foreach ($aSpoolWarnings as $sWarning) {
|
||||
print('MAIL SPOOL WARNING: ' . $sWarning."\n");
|
||||
saveLog('resendEmails', 'warning', 'MAIL SPOOL WARNING: ' . $sWarning);
|
||||
print("MAIL SPOOL WARNING: " . $sWarning."\n");
|
||||
saveLog("resendEmails", "warning", "MAIL SPOOL WARNING: " . $sWarning);
|
||||
}
|
||||
}
|
||||
|
||||
setExecutionResultMessage('DONE');
|
||||
} catch (Exception $oError) {
|
||||
setExecutionResultMessage('WITH ERRORS', 'error');
|
||||
eprintln(" '-".$oError->getMessage(), 'red');
|
||||
saveLog('resendEmails', 'error', 'Error Resending Emails: ' . $oError->getMessage());
|
||||
setExecutionResultMessage("DONE");
|
||||
} catch (Exception $e) {
|
||||
setExecutionResultMessage("WITH ERRORS", "error");
|
||||
eprintln(" '-" . $e->getMessage(), "red");
|
||||
saveLog("resendEmails", "error", "Error Resending Emails: " . $e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -426,6 +446,12 @@ function executeScheduledCases($sNow=null)
|
||||
|
||||
function executeUpdateAppTitle()
|
||||
{
|
||||
global $sFilter;
|
||||
|
||||
if ($sFilter != "" && strpos($sFilter, "update-case-labels") === false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
$criteriaConf = new Criteria("workflow");
|
||||
|
||||
|
||||
@@ -488,124 +488,150 @@ class spoolRun {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* try resend the emails from spool
|
||||
* @param none
|
||||
* @return none or exception
|
||||
*/
|
||||
function resendEmails() {
|
||||
require_once ("classes/model/Configuration.php");
|
||||
/**
|
||||
* try resend the emails from spool
|
||||
* @param string $dateResend
|
||||
* @return none or exception
|
||||
*/
|
||||
public function resendEmails($dateResend=null)
|
||||
{
|
||||
require_once ("classes/model/Configuration.php");
|
||||
|
||||
$oConfiguration = new Configuration();
|
||||
$oConfiguration = new Configuration();
|
||||
|
||||
$aConfiguration = $oConfiguration->load("Emails", "", "", "", "");
|
||||
$aConfiguration = $oConfiguration->load("Emails", "", "", "", "");
|
||||
|
||||
$aConfiguration = unserialize($aConfiguration["CFG_VALUE"]);
|
||||
$passwd = $aConfiguration["MESS_PASSWORD"];
|
||||
$passwdDec = G::decrypt($passwd,"EMAILENCRYPT");
|
||||
$auxPass = explode('hash:', $passwdDec);
|
||||
$aConfiguration = unserialize($aConfiguration["CFG_VALUE"]);
|
||||
$passwd = $aConfiguration["MESS_PASSWORD"];
|
||||
$passwdDec = G::decrypt($passwd,"EMAILENCRYPT");
|
||||
$auxPass = explode("hash:", $passwdDec);
|
||||
|
||||
if (count($auxPass) > 1) {
|
||||
if (count($auxPass) == 2) {
|
||||
$passwd = $auxPass[1];
|
||||
} else {
|
||||
array_shift($auxPass);
|
||||
$passwd = implode('', $auxPass);
|
||||
if (count($auxPass) > 1) {
|
||||
if (count($auxPass) == 2) {
|
||||
$passwd = $auxPass[1];
|
||||
} else {
|
||||
array_shift($auxPass);
|
||||
$passwd = implode("", $auxPass);
|
||||
}
|
||||
}
|
||||
|
||||
$aConfiguration["MESS_PASSWORD"] = $passwd;
|
||||
|
||||
if ($aConfiguration["MESS_ENABLED"] == "1") {
|
||||
require_once ("classes/model/AppMessage.php");
|
||||
|
||||
$this->setConfig(array(
|
||||
"MESS_ENGINE" => $aConfiguration["MESS_ENGINE"],
|
||||
"MESS_SERVER" => $aConfiguration["MESS_SERVER"],
|
||||
"MESS_PORT" => $aConfiguration["MESS_PORT"],
|
||||
"MESS_ACCOUNT" => $aConfiguration["MESS_ACCOUNT"],
|
||||
"MESS_PASSWORD" => $aConfiguration["MESS_PASSWORD"],
|
||||
"SMTPAuth" => $aConfiguration["MESS_RAUTH"],
|
||||
"SMTPSecure" => $aConfiguration["SMTPSecure"]
|
||||
));
|
||||
|
||||
$criteria = new Criteria("workflow");
|
||||
$criteria->add(AppMessagePeer::APP_MSG_STATUS, "sent", Criteria::NOT_EQUAL);
|
||||
|
||||
if ($dateResend != null) {
|
||||
$criteria->add(AppMessagePeer::APP_MSG_DATE, $dateResend, Criteria::GREATER_EQUAL);
|
||||
}
|
||||
|
||||
$rsCriteria = AppMessagePeer::doSelectRS($criteria);
|
||||
$rsCriteria->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
||||
|
||||
while ($rsCriteria->next()) {
|
||||
$row = $rsCriteria->getRow();
|
||||
|
||||
try {
|
||||
$this->setData(
|
||||
$row["APP_MSG_UID"],
|
||||
$row["APP_MSG_SUBJECT"],
|
||||
$row["APP_MSG_FROM"],
|
||||
$row["APP_MSG_TO"],
|
||||
$row["APP_MSG_BODY"],
|
||||
date("Y-m-d H:i:s"),
|
||||
$row["APP_MSG_CC"],
|
||||
$row["APP_MSG_BCC"],
|
||||
$row["APP_MSG_TEMPLATE"],
|
||||
$row["APP_MSG_ATTACH"]
|
||||
);
|
||||
|
||||
$this->sendMail();
|
||||
} catch (Exception $e) {
|
||||
$strAux = "Spool::resendEmails(): Using " .
|
||||
$aConfiguration["MESS_ENGINE"] .
|
||||
" for APP_MGS_UID=" .
|
||||
$row["APP_MSG_UID"] .
|
||||
" -> With message: " .
|
||||
$e->getMessage();
|
||||
|
||||
if ($e->getCode() == $this->ExceptionCode["WARNING"]) {
|
||||
array_push($this->aWarnings, $strAux);
|
||||
continue;
|
||||
} else {
|
||||
throw $e;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$aConfiguration["MESS_PASSWORD"] = $passwd;
|
||||
|
||||
if ($aConfiguration["MESS_ENABLED"] == "1") {
|
||||
$this->setConfig(array(
|
||||
"MESS_ENGINE" => $aConfiguration["MESS_ENGINE"],
|
||||
"MESS_SERVER" => $aConfiguration["MESS_SERVER"],
|
||||
"MESS_PORT" => $aConfiguration["MESS_PORT"],
|
||||
"MESS_ACCOUNT" => $aConfiguration["MESS_ACCOUNT"],
|
||||
"MESS_PASSWORD" => $aConfiguration["MESS_PASSWORD"],
|
||||
"SMTPAuth" => $aConfiguration["MESS_RAUTH"],
|
||||
"SMTPSecure" => $aConfiguration["SMTPSecure"]
|
||||
));
|
||||
|
||||
///////
|
||||
require_once ("classes/model/AppMessage.php");
|
||||
|
||||
$oCriteria = new Criteria('workflow');
|
||||
$oCriteria->add(AppMessagePeer::APP_MSG_STATUS, 'sent', Criteria::NOT_EQUAL);
|
||||
$oDataset = AppMessagePeer::doSelectRS($oCriteria);
|
||||
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
||||
|
||||
while( $oDataset->next() ) {
|
||||
$aRow = $oDataset->getRow();
|
||||
try {
|
||||
$this->setData($aRow['APP_MSG_UID'], $aRow['APP_MSG_SUBJECT'], $aRow['APP_MSG_FROM'], $aRow['APP_MSG_TO'], $aRow['APP_MSG_BODY'], date('Y-m-d H:i:s'), $aRow['APP_MSG_CC'], $aRow['APP_MSG_BCC'], $aRow['APP_MSG_TEMPLATE'], $aRow['APP_MSG_ATTACH']);
|
||||
$this->sendMail();
|
||||
} catch( Exception $oException ) {
|
||||
if( $oException->getCode() == $this->ExceptionCode['WARNING'] ) {
|
||||
array_push($this->aWarnings, 'Spool::resendEmails(): Using ' . $aConfiguration['MESS_ENGINE'] . ' for APP_MGS_UID=' . $aRow['APP_MSG_UID'] . ' -> With message: ' . $oException->getMessage());
|
||||
continue;
|
||||
} else {
|
||||
throw $oException;
|
||||
}
|
||||
/**
|
||||
* gets all warnings
|
||||
* @param none
|
||||
* @return string $this->aWarnings
|
||||
*/
|
||||
public function getWarnings()
|
||||
{
|
||||
if (sizeof($this->aWarnings) != 0) {
|
||||
return $this->aWarnings;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gets all warnings
|
||||
* @param none
|
||||
* @return string $this->aWarnings
|
||||
*/
|
||||
function getWarnings() {
|
||||
if( sizeof($this->aWarnings) != 0 ) {
|
||||
return $this->aWarnings;
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* db_insert
|
||||
*
|
||||
* @param array $db_spool
|
||||
* @return string $sUID;
|
||||
*/
|
||||
/**
|
||||
* db_insert
|
||||
*
|
||||
* @param array $db_spool
|
||||
* @return string $sUID;
|
||||
*/
|
||||
public function db_insert($db_spool)
|
||||
{
|
||||
$sUID = G::generateUniqueID();
|
||||
$spool = new AppMessage();
|
||||
$spool->setAppMsgUid($sUID);
|
||||
$spool->setMsgUid($db_spool['msg_uid']);
|
||||
$spool->setAppUid($db_spool['app_uid']);
|
||||
$spool->setDelIndex($db_spool['del_index']);
|
||||
$spool->setAppMsgType($db_spool['app_msg_type']);
|
||||
$spool->setAppMsgSubject($db_spool['app_msg_subject']);
|
||||
$spool->setAppMsgFrom($db_spool['app_msg_from']);
|
||||
$spool->setAppMsgTo($db_spool['app_msg_to']);
|
||||
$spool->setAppMsgBody($db_spool['app_msg_body']);
|
||||
$spool->setAppMsgDate(date('Y-m-d H:i:s'));
|
||||
$spool->setAppMsgCc($db_spool['app_msg_cc']);
|
||||
$spool->setAppMsgBcc($db_spool['app_msg_bcc']);
|
||||
$spool->setappMsgAttach($db_spool['app_msg_attach']);
|
||||
$spool->setAppMsgTemplate($db_spool['app_msg_template']);
|
||||
$spool->setAppMsgStatus($db_spool['app_msg_status']);
|
||||
$spool->setAppMsgSendDate(date('Y-m-d H:i:s')); // Add by Ankit
|
||||
$sUID = G::generateUniqueID();
|
||||
$spool = new AppMessage();
|
||||
$spool->setAppMsgUid($sUID);
|
||||
$spool->setMsgUid($db_spool['msg_uid']);
|
||||
$spool->setAppUid($db_spool['app_uid']);
|
||||
$spool->setDelIndex($db_spool['del_index']);
|
||||
$spool->setAppMsgType($db_spool['app_msg_type']);
|
||||
$spool->setAppMsgSubject($db_spool['app_msg_subject']);
|
||||
$spool->setAppMsgFrom($db_spool['app_msg_from']);
|
||||
$spool->setAppMsgTo($db_spool['app_msg_to']);
|
||||
$spool->setAppMsgBody($db_spool['app_msg_body']);
|
||||
$spool->setAppMsgDate(date('Y-m-d H:i:s'));
|
||||
$spool->setAppMsgCc($db_spool['app_msg_cc']);
|
||||
$spool->setAppMsgBcc($db_spool['app_msg_bcc']);
|
||||
$spool->setappMsgAttach($db_spool['app_msg_attach']);
|
||||
$spool->setAppMsgTemplate($db_spool['app_msg_template']);
|
||||
$spool->setAppMsgStatus($db_spool['app_msg_status']);
|
||||
$spool->setAppMsgSendDate(date('Y-m-d H:i:s')); // Add by Ankit
|
||||
|
||||
if(!$spool->validate()) {
|
||||
$errors = $spool->getValidationFailures();
|
||||
$this->status = 'error';
|
||||
if (!$spool->validate()) {
|
||||
$errors = $spool->getValidationFailures();
|
||||
$this->status = 'error';
|
||||
|
||||
foreach($errors as $key => $value) {
|
||||
echo "Validation error - " . $value->getMessage($key) . "\n";
|
||||
foreach ($errors as $key => $value) {
|
||||
echo "Validation error - " . $value->getMessage($key) . "\n";
|
||||
}
|
||||
} else {
|
||||
//echo "Saving - validation ok\n";
|
||||
$this->status = 'success';
|
||||
$spool->save();
|
||||
}
|
||||
}
|
||||
else {
|
||||
//echo "Saving - validation ok\n";
|
||||
$this->status = 'success';
|
||||
$spool->save();
|
||||
}
|
||||
return $sUID;
|
||||
|
||||
return $sUID;
|
||||
}
|
||||
}
|
||||
?>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user