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 = '';
|
$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.");
|
||||||
|
|
||||||
|
|||||||
@@ -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");
|
||||||
|
|
||||||
|
|||||||
@@ -490,10 +490,11 @@ 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();
|
||||||
@@ -503,20 +504,22 @@ class spoolRun {
|
|||||||
$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;
|
$aConfiguration["MESS_PASSWORD"] = $passwd;
|
||||||
|
|
||||||
if ($aConfiguration["MESS_ENABLED"] == "1") {
|
if ($aConfiguration["MESS_ENABLED"] == "1") {
|
||||||
|
require_once ("classes/model/AppMessage.php");
|
||||||
|
|
||||||
$this->setConfig(array(
|
$this->setConfig(array(
|
||||||
"MESS_ENGINE" => $aConfiguration["MESS_ENGINE"],
|
"MESS_ENGINE" => $aConfiguration["MESS_ENGINE"],
|
||||||
"MESS_SERVER" => $aConfiguration["MESS_SERVER"],
|
"MESS_SERVER" => $aConfiguration["MESS_SERVER"],
|
||||||
@@ -527,25 +530,47 @@ class spoolRun {
|
|||||||
"SMTPSecure" => $aConfiguration["SMTPSecure"]
|
"SMTPSecure" => $aConfiguration["SMTPSecure"]
|
||||||
));
|
));
|
||||||
|
|
||||||
///////
|
$criteria = new Criteria("workflow");
|
||||||
require_once ("classes/model/AppMessage.php");
|
$criteria->add(AppMessagePeer::APP_MSG_STATUS, "sent", Criteria::NOT_EQUAL);
|
||||||
|
|
||||||
$oCriteria = new Criteria('workflow');
|
if ($dateResend != null) {
|
||||||
$oCriteria->add(AppMessagePeer::APP_MSG_STATUS, 'sent', Criteria::NOT_EQUAL);
|
$criteria->add(AppMessagePeer::APP_MSG_DATE, $dateResend, Criteria::GREATER_EQUAL);
|
||||||
$oDataset = AppMessagePeer::doSelectRS($oCriteria);
|
}
|
||||||
$oDataset->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
|
||||||
|
$rsCriteria = AppMessagePeer::doSelectRS($criteria);
|
||||||
|
$rsCriteria->setFetchmode(ResultSet::FETCHMODE_ASSOC);
|
||||||
|
|
||||||
|
while ($rsCriteria->next()) {
|
||||||
|
$row = $rsCriteria->getRow();
|
||||||
|
|
||||||
while( $oDataset->next() ) {
|
|
||||||
$aRow = $oDataset->getRow();
|
|
||||||
try {
|
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->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();
|
$this->sendMail();
|
||||||
} catch( Exception $oException ) {
|
} catch (Exception $e) {
|
||||||
if( $oException->getCode() == $this->ExceptionCode['WARNING'] ) {
|
$strAux = "Spool::resendEmails(): Using " .
|
||||||
array_push($this->aWarnings, 'Spool::resendEmails(): Using ' . $aConfiguration['MESS_ENGINE'] . ' for APP_MGS_UID=' . $aRow['APP_MSG_UID'] . ' -> With message: ' . $oException->getMessage());
|
$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;
|
continue;
|
||||||
} else {
|
} else {
|
||||||
throw $oException;
|
throw $e;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -557,10 +582,12 @@ class spoolRun {
|
|||||||
* @param none
|
* @param none
|
||||||
* @return string $this->aWarnings
|
* @return string $this->aWarnings
|
||||||
*/
|
*/
|
||||||
function getWarnings() {
|
public function getWarnings()
|
||||||
if( sizeof($this->aWarnings) != 0 ) {
|
{
|
||||||
|
if (sizeof($this->aWarnings) != 0) {
|
||||||
return $this->aWarnings;
|
return $this->aWarnings;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -591,21 +618,20 @@ class spoolRun {
|
|||||||
$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 {
|
||||||
else {
|
|
||||||
//echo "Saving - validation ok\n";
|
//echo "Saving - validation ok\n";
|
||||||
$this->status = 'success';
|
$this->status = 'success';
|
||||||
$spool->save();
|
$spool->save();
|
||||||
}
|
}
|
||||||
return $sUID;
|
|
||||||
|
|
||||||
|
return $sUID;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
?>
|
|
||||||
|
|||||||
Reference in New Issue
Block a user