Exemplo n.º 1
0
 /**
  * Split the parent job into n number of child job based on an offset.
  * If null or 0 , we create only one child job
  * @param int $offset
  */
 public function split_job($offset = 200)
 {
     $recipient_count = CRM_Mailing_BAO_Recipients::mailingSize($this->mailing_id);
     $jobTable = CRM_Mailing_DAO_MailingJob::getTableName();
     $dao = new CRM_Core_DAO();
     $sql = "\nINSERT INTO civicrm_mailing_job\n(`mailing_id`, `scheduled_date`, `status`, `job_type`, `parent_id`, `job_offset`, `job_limit`)\nVALUES (%1, %2, %3, %4, %5, %6, %7)\n";
     $params = array(1 => array($this->mailing_id, 'Integer'), 2 => array($this->scheduled_date, 'String'), 3 => array('Scheduled', 'String'), 4 => array('child', 'String'), 5 => array($this->id, 'Integer'), 6 => array(0, 'Integer'), 7 => array($recipient_count, 'Integer'));
     // create one child job if the mailing size is less than the offset
     // probably use a CRM_Mailing_DAO_MailingJob( );
     if (empty($offset) || $recipient_count <= $offset) {
         CRM_Core_DAO::executeQuery($sql, $params);
     } else {
         // Creating 'child jobs'
         for ($i = 0; $i < $recipient_count; $i = $i + $offset) {
             $params[6][0] = $i;
             $params[7][0] = $offset;
             CRM_Core_DAO::executeQuery($sql, $params);
         }
     }
 }