From 92e24c3e78b8c8e162c779f459ec06e9196fe1e7 Mon Sep 17 00:00:00 2001 From: Victor Saisa Lopez Date: Mon, 20 Aug 2012 12:33:18 -0400 Subject: [PATCH] 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 --- workflow/engine/bin/cron.php | 14 +- workflow/engine/bin/cron_single.php | 52 ++++-- workflow/engine/classes/class.spool.php | 230 +++++++++++++----------- 3 files changed, 174 insertions(+), 122 deletions(-) diff --git a/workflow/engine/bin/cron.php b/workflow/engine/bin/cron.php index fa115bdfd..6e326af4c 100755 --- a/workflow/engine/bin/cron.php +++ b/workflow/engine/bin/cron.php @@ -68,8 +68,9 @@ else { $WS = ''; $argsx = ''; $sDate = ''; -for($i=1; $iresendEmails(); + $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"); diff --git a/workflow/engine/classes/class.spool.php b/workflow/engine/classes/class.spool.php index 1e68ed482..2496e7082 100755 --- a/workflow/engine/classes/class.spool.php +++ b/workflow/engine/classes/class.spool.php @@ -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; } } -?> \ No newline at end of file +