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:
Victor Saisa Lopez
2012-08-20 12:33:18 -04:00
parent 16ff818d68
commit 92e24c3e78
3 changed files with 174 additions and 122 deletions

View File

@@ -68,8 +68,9 @@ else {
$WS = ''; $WS = '';
$argsx = ''; $argsx = '';
$sDate = ''; $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){ if( strpos($argv[$i], '+d') !== false){
$sDate = substr($argv[$i],2); $sDate = substr($argv[$i],2);
} else if( strpos($argv[$i], '+w') !== false){ } 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 is not set, so take the system time
if($sDate!=''){ if ($sDate != "") {
eprintln("[Applying date filter: $sDate]"); eprintln("[Applying date filter: $sDate]");
} else { } 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')) { if (file_exists(PATH_DB . $sObject . PATH_SEP . 'db.php')) {
$cws++; $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 { } else {
$cws = 1; $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."); eprintln("Finished $cws workspaces processed.");

View File

@@ -115,9 +115,10 @@ if (file_exists(PATH_DATA . 'cron')) {
if (!defined('SYS_SYS')) { if (!defined('SYS_SYS')) {
$sObject = $argv[1]; $sObject = $argv[1];
$sNow = $argv[2]; $sNow = $argv[2];
$dateSystem = $argv[3];
$sFilter = ''; $sFilter = '';
for ($i = 3; $i < count($argv); $i++) { for ($i = 4; $i <= count($argv) - 1; $i++) {
$sFilter .= ' ' . $argv[$i]; $sFilter .= ' ' . $argv[$i];
} }
@@ -244,35 +245,54 @@ function processWorkspace()
function resendEmails() function resendEmails()
{ {
global $sFilter; global $sFilter;
global $sNow;
global $dateSystem;
if ($sFilter != '' && strpos($sFilter, 'emails') === false) { if ($sFilter != "" && strpos($sFilter, "emails") === false) {
return false; return false;
} }
setExecutionMessage("Resending emails"); setExecutionMessage("Resending emails");
try { 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 = new spoolRun();
$oSpool->resendEmails(); $oSpool->resendEmails($dateResend);
saveLog('resendEmails', 'action', 'Resending Emails', "c"); saveLog("resendEmails", "action", "Resending Emails", "c");
$aSpoolWarnings = $oSpool->getWarnings(); $aSpoolWarnings = $oSpool->getWarnings();
if ( $aSpoolWarnings !== false ) { if ($aSpoolWarnings !== false) {
foreach ($aSpoolWarnings as $sWarning) { foreach ($aSpoolWarnings as $sWarning) {
print('MAIL SPOOL WARNING: ' . $sWarning."\n"); print("MAIL SPOOL WARNING: " . $sWarning."\n");
saveLog('resendEmails', 'warning', 'MAIL SPOOL WARNING: ' . $sWarning); saveLog("resendEmails", "warning", "MAIL SPOOL WARNING: " . $sWarning);
} }
} }
setExecutionResultMessage('DONE'); setExecutionResultMessage("DONE");
} catch (Exception $oError) { } catch (Exception $e) {
setExecutionResultMessage('WITH ERRORS', 'error'); setExecutionResultMessage("WITH ERRORS", "error");
eprintln(" '-".$oError->getMessage(), 'red'); eprintln(" '-" . $e->getMessage(), "red");
saveLog('resendEmails', 'error', 'Error Resending Emails: ' . $oError->getMessage()); saveLog("resendEmails", "error", "Error Resending Emails: " . $e->getMessage());
} }
} }
@@ -426,6 +446,12 @@ function executeScheduledCases($sNow=null)
function executeUpdateAppTitle() function executeUpdateAppTitle()
{ {
global $sFilter;
if ($sFilter != "" && strpos($sFilter, "update-case-labels") === false) {
return false;
}
try { try {
$criteriaConf = new Criteria("workflow"); $criteriaConf = new Criteria("workflow");

View File

@@ -488,124 +488,150 @@ class spoolRun {
} }
} }
/** /**
* try resend the emails from spool * try resend the emails from spool
* @param none * @param string $dateResend
* @return none or exception * @return none or exception
*/ */
function resendEmails() { public function resendEmails($dateResend=null)
require_once ("classes/model/Configuration.php"); {
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"]); $aConfiguration = unserialize($aConfiguration["CFG_VALUE"]);
$passwd = $aConfiguration["MESS_PASSWORD"]; $passwd = $aConfiguration["MESS_PASSWORD"];
$passwdDec = G::decrypt($passwd,"EMAILENCRYPT"); $passwdDec = G::decrypt($passwd,"EMAILENCRYPT");
$auxPass = explode('hash:', $passwdDec); $auxPass = explode("hash:", $passwdDec);
if (count($auxPass) > 1) { if (count($auxPass) > 1) {
if (count($auxPass) == 2) { if (count($auxPass) == 2) {
$passwd = $auxPass[1]; $passwd = $auxPass[1];
} else { } else {
array_shift($auxPass); array_shift($auxPass);
$passwd = implode('', $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; /**
* gets all warnings
if ($aConfiguration["MESS_ENABLED"] == "1") { * @param none
$this->setConfig(array( * @return string $this->aWarnings
"MESS_ENGINE" => $aConfiguration["MESS_ENGINE"], */
"MESS_SERVER" => $aConfiguration["MESS_SERVER"], public function getWarnings()
"MESS_PORT" => $aConfiguration["MESS_PORT"], {
"MESS_ACCOUNT" => $aConfiguration["MESS_ACCOUNT"], if (sizeof($this->aWarnings) != 0) {
"MESS_PASSWORD" => $aConfiguration["MESS_PASSWORD"], return $this->aWarnings;
"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;
}
} }
}
}
}
/** return false;
* gets all warnings
* @param none
* @return string $this->aWarnings
*/
function getWarnings() {
if( sizeof($this->aWarnings) != 0 ) {
return $this->aWarnings;
} }
return false;
}
/** /**
* db_insert * db_insert
* *
* @param array $db_spool * @param array $db_spool
* @return string $sUID; * @return string $sUID;
*/ */
public function db_insert($db_spool) public function db_insert($db_spool)
{ {
$sUID = G::generateUniqueID(); $sUID = G::generateUniqueID();
$spool = new AppMessage(); $spool = new AppMessage();
$spool->setAppMsgUid($sUID); $spool->setAppMsgUid($sUID);
$spool->setMsgUid($db_spool['msg_uid']); $spool->setMsgUid($db_spool['msg_uid']);
$spool->setAppUid($db_spool['app_uid']); $spool->setAppUid($db_spool['app_uid']);
$spool->setDelIndex($db_spool['del_index']); $spool->setDelIndex($db_spool['del_index']);
$spool->setAppMsgType($db_spool['app_msg_type']); $spool->setAppMsgType($db_spool['app_msg_type']);
$spool->setAppMsgSubject($db_spool['app_msg_subject']); $spool->setAppMsgSubject($db_spool['app_msg_subject']);
$spool->setAppMsgFrom($db_spool['app_msg_from']); $spool->setAppMsgFrom($db_spool['app_msg_from']);
$spool->setAppMsgTo($db_spool['app_msg_to']); $spool->setAppMsgTo($db_spool['app_msg_to']);
$spool->setAppMsgBody($db_spool['app_msg_body']); $spool->setAppMsgBody($db_spool['app_msg_body']);
$spool->setAppMsgDate(date('Y-m-d H:i:s')); $spool->setAppMsgDate(date('Y-m-d H:i:s'));
$spool->setAppMsgCc($db_spool['app_msg_cc']); $spool->setAppMsgCc($db_spool['app_msg_cc']);
$spool->setAppMsgBcc($db_spool['app_msg_bcc']); $spool->setAppMsgBcc($db_spool['app_msg_bcc']);
$spool->setappMsgAttach($db_spool['app_msg_attach']); $spool->setappMsgAttach($db_spool['app_msg_attach']);
$spool->setAppMsgTemplate($db_spool['app_msg_template']); $spool->setAppMsgTemplate($db_spool['app_msg_template']);
$spool->setAppMsgStatus($db_spool['app_msg_status']); $spool->setAppMsgStatus($db_spool['app_msg_status']);
$spool->setAppMsgSendDate(date('Y-m-d H:i:s')); // Add by Ankit $spool->setAppMsgSendDate(date('Y-m-d H:i:s')); // Add by Ankit
if(!$spool->validate()) { if (!$spool->validate()) {
$errors = $spool->getValidationFailures(); $errors = $spool->getValidationFailures();
$this->status = 'error'; $this->status = 'error';
foreach($errors as $key => $value) { foreach ($errors as $key => $value) {
echo "Validation error - " . $value->getMessage($key) . "\n"; 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;
} }
} }
?>