/**
 * A PHP cron script to run the outstanding and scheduled CiviMail jobs
 * initiated by Owen Barton from a mailing sent by Lobo to crm-mail
 *
 * The structure of the file is set to mimiic soap.php which is a stand-alone
 * script and hence does not have any UF issues. You should be able to run
 * this script using a web url or from the command line
 */
function processQueue($batch_size)
{
    require_once 'CRM/Mailing/BAO/Job.php';
    // Split up the parent jobs into multiple child jobs
    CRM_Mailing_BAO_Job::runJobs_pre($batch_size);
    CRM_Mailing_BAO_Job::runJobs();
    CRM_Mailing_BAO_Job::runJobs_post();
}
Beispiel #2
0
 /** 
  * run this page (figure out the action needed and perform it). 
  * 
  * @return void 
  */
 function run($newArgs)
 {
     $this->preProcess();
     if (isset($_GET['runJobs']) || CRM_Utils_Array::value('2', $newArgs) == 'queue') {
         require_once 'CRM/Mailing/BAO/Job.php';
         $config =& CRM_Core_Config::singleton();
         CRM_Mailing_BAO_Job::runJobs_pre($config->mailerJobSize);
         CRM_Mailing_BAO_Job::runJobs();
         CRM_Mailing_BAO_Job::runJobs_post();
     }
     $this->_sortByCharacter = CRM_Utils_Request::retrieve('sortByCharacter', 'String', $this);
     if ($this->_sortByCharacter == 1 || !empty($_POST)) {
         $this->_sortByCharacter = '';
         $this->set('sortByCharacter', '');
     }
     if (CRM_Utils_Array::value(3, $newArgs) == 'unscheduled') {
         $this->_unscheduled = true;
     }
     $this->set('unscheduled', $this->_unscheduled);
     if (CRM_Utils_Array::value(3, $newArgs) == 'archived') {
         $this->_archived = true;
     }
     $this->set('archived', $this->_archived);
     if (CRM_Utils_Array::value(3, $newArgs) == 'scheduled') {
         $this->_scheduled = true;
     }
     $this->set('scheduled', $this->_scheduled);
     $this->_createdId = CRM_Utils_Request::retrieve('cid', 'Positive', $this, false, 0);
     if ($this->_createdId) {
         $this->set('createdId', $this->_createdId);
     }
     $session = CRM_Core_Session::singleton();
     $context = $session->readUserContext();
     if ($this->_action & CRM_Core_Action::DISABLE) {
         if (CRM_Utils_Request::retrieve('confirmed', 'Boolean', $this)) {
             require_once 'CRM/Mailing/BAO/Job.php';
             CRM_Mailing_BAO_Job::cancel($this->_mailingId);
             CRM_Utils_System::redirect($context);
         } else {
             $controller = new CRM_Core_Controller_Simple('CRM_Mailing_Form_Browse', ts('Cancel Mailing'), $this->_action);
             $controller->setEmbedded(true);
             $controller->run();
         }
     } else {
         if ($this->_action & CRM_Core_Action::DELETE) {
             if (CRM_Utils_Request::retrieve('confirmed', 'Boolean', $this)) {
                 // check for action permissions.
                 if (!CRM_Core_Permission::checkActionPermission('CiviMail', $this->_action)) {
                     CRM_Core_Error::fatal(ts('You do not have permission to access this page'));
                 }
                 require_once 'CRM/Mailing/BAO/Mailing.php';
                 CRM_Mailing_BAO_Mailing::del($this->_mailingId);
                 CRM_Utils_System::redirect($context);
             } else {
                 $controller = new CRM_Core_Controller_Simple('CRM_Mailing_Form_Browse', ts('Delete Mailing'), $this->_action);
                 $controller->setEmbedded(true);
                 $controller->run();
             }
         } else {
             if ($this->_action & CRM_Core_Action::RENEW) {
                 //archive this mailing, CRM-3752.
                 if (CRM_Utils_Request::retrieve('confirmed', 'Boolean', $this)) {
                     //set is_archived to 1
                     CRM_Core_DAO::setFieldValue('CRM_Mailing_DAO_Mailing', $this->_mailingId, 'is_archived', true);
                     CRM_Utils_System::redirect($context);
                 } else {
                     $controller = new CRM_Core_Controller_Simple('CRM_Mailing_Form_Browse', ts('Archive Mailing'), $this->_action);
                     $controller->setEmbedded(true);
                     $controller->run();
                 }
             }
         }
     }
     $selector = new CRM_Mailing_Selector_Browse();
     $selector->setParent($this);
     $controller = new CRM_Core_Selector_Controller($selector, $this->get(CRM_Utils_Pager::PAGE_ID), $this->get(CRM_Utils_Sort::SORT_ID) . $this->get(CRM_Utils_Sort::SORT_DIRECTION), CRM_Core_Action::VIEW, $this, CRM_Core_Selector_Controller::TEMPLATE);
     $controller->setEmbedded(true);
     $controller->run();
     //hack to display results as per search
     $rows = $controller->getRows($controller);
     $this->assign('rows', $rows);
     $urlParams = 'reset=1';
     $urlString = 'civicrm/mailing/browse';
     if (CRM_Utils_Array::value(3, $newArgs) == 'unscheduled') {
         $urlString .= '/unscheduled';
         $urlParams .= '&scheduled=false';
         $this->assign('unscheduled', true);
         CRM_Utils_System::setTitle(ts('Draft and Unscheduled Mailings'));
     } else {
         if (CRM_Utils_Array::value(3, $newArgs) == 'archived') {
             $urlString .= '/archived';
             $this->assign('archived', true);
             CRM_Utils_System::setTitle(ts('Archived Mailings'));
         } else {
             if (CRM_Utils_Array::value(3, $newArgs) == 'scheduled') {
                 $urlString .= '/scheduled';
                 $urlParams .= '&scheduled=true';
                 CRM_Utils_System::setTitle(ts('Scheduled and Sent Mailings'));
             } else {
                 CRM_Utils_System::setTitle(ts('Find Mailings'));
             }
         }
     }
     $crmRowCount = CRM_Utils_Request::retrieve('crmRowCount', 'Integer', CRM_Core_DAO::$_nullObject);
     $crmPID = CRM_Utils_Request::retrieve('crmPID', 'Integer', CRM_Core_DAO::$_nullObject);
     if ($crmRowCount || $crmPID) {
         $urlParams .= '&force=1';
         $urlParams .= $crmRowCount ? '&crmRowCount=' . $crmRowCount : '';
         $urlParams .= $crmPID ? '&crmPID=' . $crmPID : '';
     }
     $crmSID = CRM_Utils_Request::retrieve('crmSID', 'Integer', CRM_Core_DAO::$_nullObject);
     if ($crmSID) {
         $urlParams .= '&crmSID=' . $crmSID;
     }
     $session = CRM_Core_Session::singleton();
     $url = CRM_Utils_System::url($urlString, $urlParams);
     $session->pushUserContext($url);
     //CRM-6862 -run form cotroller after
     //selector, since it erase $_POST
     $this->search();
     return parent::run();
 }
 | CiviCRM is distributed in the hope that it will be useful, but     |
 | WITHOUT ANY WARRANTY; without even the implied warranty of         |
 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.               |
 | See the Affero General Public License for more details.            |
 |                                                                    |
 | You should have received a copy of the Affero General Public       |
 | License along with this program; if not, contact the Social Source |
 | Foundation at info[AT]socialsourcefoundation[DOT]org.  If you have |
 | questions about the Affero General Public License or the licensing |
 | of CiviCRM, see the Social Source Foundation CiviCRM license FAQ   |
 | at http://www.openngo.org/faqs/licensing.html                       |
 +--------------------------------------------------------------------+
*/
/**
 * A PHP cron script to run the outstanding and scheduled CiviMail jobs
 * initiated by Owen Barton from a mailing sent by Lobo to crm-mail
 *
 * The structure of the file is set to mimiic soap.php which is a stand-alone
 * script and hence does not have any UF issues. You should be able to run
 * this script using a web url or from the command line
 */
session_start();
require_once '../civicrm.config.php';
require_once 'CRM/Core/Config.php';
$config =& CRM_Core_Config::singleton();
$config->userFramework = 'Soap';
$config->userFrameworkClass = 'CRM_Utils_System_Soap';
$config->userHookClass = 'CRM_Utils_Hook_Soap';
require_once 'CRM/Mailing/BAO/Job.php';
CRM_Mailing_BAO_Job::runJobs();
 static function processQueue($mode = NULL)
 {
     $config =& CRM_Core_Config::singleton();
     CRM_Core_Error::debug_log_message("Beginning processQueue run: {$config->mailerJobsMax}, {$config->mailerJobSize}");
     if ($mode == NULL && CRM_Core_BAO_MailSettings::defaultDomain() == "FIXME.ORG") {
         CRM_Core_Error::fatal(ts('The <a href="%1">default mailbox</a> has not been configured. You will find <a href="%2">more info in the online user and administrator guide</a>', array(1 => CRM_Utils_System::url('civicrm/admin/mailSettings', 'reset=1'), 2 => "http://book.civicrm.org/user/initial-set-up/email-system-configuration")));
     }
     // check if we are enforcing number of parallel cron jobs
     // CRM-8460
     $gotCronLock = FALSE;
     if ($config->mailerJobsMax && $config->mailerJobsMax > 1) {
         $lockArray = range(1, $config->mailerJobsMax);
         shuffle($lockArray);
         // check if we are using global locks
         $serverWideLock = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'civimail_server_wide_lock');
         foreach ($lockArray as $lockID) {
             $cronLock = new CRM_Core_Lock("civimail.cronjob.{$lockID}", NULL, $serverWideLock);
             if ($cronLock->isAcquired()) {
                 $gotCronLock = TRUE;
                 break;
             }
         }
         // exit here since we have enuf cronjobs running
         if (!$gotCronLock) {
             CRM_Core_Error::debug_log_message('Returning early, since max number of cronjobs running');
             return TRUE;
         }
     }
     // load bootstrap to call hooks
     // Split up the parent jobs into multiple child jobs
     CRM_Mailing_BAO_Job::runJobs_pre($config->mailerJobSize, $mode);
     CRM_Mailing_BAO_Job::runJobs(NULL, $mode);
     CRM_Mailing_BAO_Job::runJobs_post($mode);
     // lets release the global cron lock if we do have one
     if ($gotCronLock) {
         $cronLock->release();
     }
     CRM_Core_Error::debug_log_message('Ending processQueue run');
     return TRUE;
 }
Beispiel #5
0
/**
 * A PHP cron script to run the outstanding and scheduled CiviMail jobs
 * initiated by Owen Barton from a mailing sent by Lobo to crm-mail
 *
 * The structure of the file is set to mimiic soap.php which is a stand-alone
 * script and hence does not have any UF issues. You should be able to run
 * this script using a web url or from the command line
 */
function processQueue()
{
    require_once 'CRM/Mailing/BAO/Job.php';
    CRM_Mailing_BAO_Job::runJobs();
}
 /**
  * Form rule to send out a test mailing.
  *
  * @param array $params     Array of the form values
  * @param array $files      Any files posted to the form
  * @param array $self       an current this object
  *
  * @return boolean          true on succesful SMTP handoff
  * @access public
  */
 static function &testMail($testParams, $files, $self)
 {
     $error = NULL;
     $urlString = 'civicrm/mailing/send';
     $urlParams = "_qf_Test_display=true&qfKey={$testParams['qfKey']}";
     $ssID = $self->get('ssID');
     if ($ssID && $self->_searchBasedMailing) {
         if ($self->_action == CRM_Core_Action::BASIC) {
             $fragment = 'search';
         } elseif ($self->_action == CRM_Core_Action::PROFILE) {
             $fragment = 'search/builder';
         } elseif ($self->_action == CRM_Core_Action::ADVANCED) {
             $fragment = 'search/advanced';
         } else {
             $fragment = 'search/custom';
         }
         $urlString = 'civicrm/contact/' . $fragment;
     }
     $emails = NULL;
     if (CRM_Utils_Array::value('sendtest', $testParams)) {
         if (!($testParams['test_group'] || $testParams['test_email'])) {
             CRM_Core_Session::setStatus(ts('Your did not provided any email address or selected any group. No test mail is sent.'));
             $error = TRUE;
         }
         if ($testParams['test_email']) {
             $emailAdd = explode(',', $testParams['test_email']);
             foreach ($emailAdd as $key => $value) {
                 $email = trim($value);
                 $testParams['emails'][] = $email;
                 $emails .= $emails ? ",'{$email}'" : "'{$email}'";
                 if (!CRM_Utils_Rule::email($email)) {
                     CRM_Core_Session::setStatus(ts('Please enter valid email addresses only.'));
                     $error = TRUE;
                 }
             }
         }
         if ($error) {
             $url = CRM_Utils_System::url($urlString, $urlParams);
             CRM_Utils_System::redirect($url);
             return $error;
         }
     }
     if (CRM_Utils_Array::value('_qf_Test_submit', $testParams)) {
         //when user perform mailing from search context
         //redirect it to search result CRM-3711.
         if ($ssID && $self->_searchBasedMailing) {
             $draftURL = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1');
             $status = ts("Your mailing has been saved. You can continue later by clicking the 'Continue' action to resume working on it.<br /> From <a href='%1'>Draft and Unscheduled Mailings</a>.", array(1 => $draftURL));
             CRM_Core_Session::setStatus($status);
             //replace user context to search.
             $context = $self->get('context');
             if (!CRM_Contact_Form_Search::isSearchContext($context)) {
                 $context = 'search';
             }
             $urlParams = "force=1&reset=1&ssID={$ssID}&context={$context}&qfKey={$testParams['qfKey']}";
             $url = CRM_Utils_System::url($urlString, $urlParams);
             CRM_Utils_System::redirect($url);
         } else {
             $status = ts("Your mailing has been saved. Click the 'Continue' action to resume working on it.");
             CRM_Core_Session::setStatus($status);
             $url = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1');
             CRM_Utils_System::redirect($url);
         }
     }
     if (CRM_Mailing_Info::workflowEnabled()) {
         if (!CRM_Core_Permission::check('schedule mailings') && CRM_Core_Permission::check('create mailings')) {
             $url = CRM_Utils_System::url('civicrm/mailing/browse/unscheduled', 'scheduled=false&reset=1');
             CRM_Utils_System::redirect($url);
         }
     }
     if (CRM_Utils_Array::value('_qf_Import_refresh', $_POST) || CRM_Utils_Array::value('_qf_Test_next', $testParams) || !CRM_Utils_Array::value('sendtest', $testParams)) {
         $error = TRUE;
         return $error;
     }
     $job = new CRM_Mailing_BAO_Job();
     $job->mailing_id = $self->get('mailing_id');
     $job->is_test = TRUE;
     $job->save();
     $newEmails = NULL;
     $session = CRM_Core_Session::singleton();
     if (!empty($testParams['emails'])) {
         $query = "\n                      SELECT id, contact_id, email  \n                      FROM civicrm_email  \n                      WHERE civicrm_email.email IN ({$emails})";
         $dao = CRM_Core_DAO::executeQuery($query);
         $emailDetail = array();
         // fetch contact_id and email id for all existing emails
         while ($dao->fetch()) {
             $emailDetail[$dao->email] = array('contact_id' => $dao->contact_id, 'email_id' => $dao->id);
         }
         $dao->free();
         foreach ($testParams['emails'] as $key => $email) {
             $email = trim($email);
             $contactId = $emailId = NULL;
             if (array_key_exists($email, $emailDetail)) {
                 $emailId = $emailDetail[$email]['email_id'];
                 $contactId = $emailDetail[$email]['contact_id'];
             }
             if (!$contactId) {
                 //create new contact.
                 $params = array('contact_type' => 'Individual', 'email' => array(1 => array('email' => $email, 'is_primary' => 1, 'location_type_id' => 1)));
                 $contact = CRM_Contact_BAO_Contact::create($params);
                 $emailId = $contact->email[0]->id;
                 $contactId = $contact->id;
                 $contact->free();
             }
             $params = array('job_id' => $job->id, 'email_id' => $emailId, 'contact_id' => $contactId);
             CRM_Mailing_Event_BAO_Queue::create($params);
         }
     }
     $testParams['job_id'] = $job->id;
     $isComplete = FALSE;
     while (!$isComplete) {
         $isComplete = CRM_Mailing_BAO_Job::runJobs($testParams);
     }
     if (CRM_Utils_Array::value('sendtest', $testParams)) {
         $status = ts('Your test message has been sent.');
         if (CRM_Mailing_Info::workflowEnabled()) {
             if (CRM_Core_Permission::check('schedule mailings') && CRM_Core_Permission::check('create mailings') || CRM_Core_Permission::check('access CiviMail')) {
                 $status .= ts(" Click 'Next' when you are ready to Schedule or Send your live mailing (you will still have a chance to confirm or cancel sending this mailing on the next page).");
             }
         } else {
             $status .= ts(" Click 'Next' when you are ready to Schedule or Send your live mailing (you will still have a chance to confirm or cancel sending this mailing on the next page).");
         }
         CRM_Core_Session::setStatus($status);
         $url = CRM_Utils_System::url($urlString, $urlParams);
         CRM_Utils_System::redirect($url);
     }
     $error = TRUE;
     return $error;
 }
Beispiel #7
0
 function main(&$args)
 {
     if ($args[1] !== 'mailing') {
         return;
     }
     require_once 'CRM/Mailing/Controller/Send.php';
     require_once 'CRM/Mailing/Page/Browse.php';
     require_once 'CRM/Mailing/BAO/Job.php';
     if ($args[2] == 'forward') {
         $session =& CRM_Core_Session::singleton();
         $session->pushUserContext(CRM_Utils_System::baseURL());
         $wrapper =& new CRM_Utils_Wrapper();
         return $wrapper->run('CRM_Profile_Form_ForwardMailing', ts('Forward Mailing'), null);
     }
     if ($args[2] == 'retry') {
         $session =& CRM_Core_Session::singleton();
         $session->pushUserContext(CRM_Utils_System::url('civicrm/mailing/browse'));
         CRM_Utils_System::appendBreadCrumb('<a href="' . CRM_Utils_System::url('civicrm/mailing/browse') . '">' . ts('Mailings') . '</a>');
         CRM_Utils_System::appendBreadCrumb('<a href="' . CRM_Utils_System::url('civicrm/mailing/report') . '">' . ts('Report') . '</a>');
         $wrapper =& new CRM_Utils_Wrapper();
         return $wrapper->run('CRM_Mailing_Form_Retry', ts('Retry Mailing'), null);
     }
     if ($args[2] == 'component') {
         require_once 'CRM/Mailing/Page/Component.php';
         $view =& new CRM_Mailing_Page_Component();
         return $view->run();
     }
     if ($args[2] == 'browse') {
         require_once 'CRM/Mailing/Page/Browse.php';
         $view =& new CRM_Mailing_Page_Browse();
         return $view->run();
     }
     if ($args[2] == 'event') {
         CRM_Utils_System::appendBreadCrumb('<a href="' . CRM_Utils_System::url('civicrm/mailing/browse') . '">' . ts('Mailings') . '</a>');
         CRM_Utils_System::appendBreadCrumb('<a href="' . CRM_Utils_System::url('civicrm/mailing/report') . '">' . ts('Report') . '</a>');
         require_once 'CRM/Mailing/Page/Event.php';
         $view =& new CRM_Mailing_Page_Event();
         return $view->run();
     }
     if ($args[2] == 'report') {
         CRM_Utils_System::appendBreadCrumb('<a href="' . CRM_Utils_System::url('civicrm/mailing/browse') . '">' . ts('Mailings') . '</a>');
         require_once 'CRM/Mailing/Page/Report.php';
         $view =& new CRM_Mailing_Page_Report();
         return $view->run();
     }
     if ($args[2] == 'send') {
         $session =& CRM_Core_Session::singleton();
         $session->pushUserContext(CRM_Utils_System::url('civicrm/mailing/browse', 'reset=1'));
         require_once 'CRM/Mailing/Controller/Send.php';
         $controller =& new CRM_Mailing_Controller_Send(ts('Send Mailing'));
         return $controller->run();
     }
     if ($args[2] == 'queue') {
         $session =& CRM_Core_Session::singleton();
         $session->pushUserContext(CRM_Utils_System::url('civicrm/mailing/browse', 'reset=1'));
         require_once 'CRM/Mailing/BAO/Job.php';
         CRM_Mailing_BAO_Job::runJobs();
         CRM_Core_Session::setStatus(ts('The mailing queue has been processed.'));
     }
     require_once 'CRM/Mailing/Page/Browse.php';
     $view =& new CRM_Mailing_Page_Browse();
     return $view->run();
 }