/** * @param array $testParams */ public function queue($testParams = NULL) { $mailing = new CRM_Mailing_BAO_Mailing(); $mailing->id = $this->mailing_id; if (!empty($testParams)) { $mailing->getTestRecipients($testParams); } else { // We are still getting all the recipients from the parent job // so we don't mess with the include/exclude logic. $recipients = CRM_Mailing_BAO_Recipients::mailingQuery($this->mailing_id, $this->job_offset, $this->job_limit); // FIXME: this is not very smart, we should move this to one DB call // INSERT INTO ... SELECT FROM .. // the thing we need to figure out is how to generate the hash automatically $now = time(); $params = array(); $count = 0; while ($recipients->fetch()) { if ($recipients->phone_id) { $recipients->email_id = "null"; } else { $recipients->phone_id = "null"; } $params[] = array($this->id, $recipients->email_id, $recipients->contact_id, $recipients->phone_id); $count++; if ($count % CRM_Core_DAO::BULK_MAIL_INSERT_COUNT == 0) { CRM_Mailing_Event_BAO_Queue::bulkCreate($params, $now); $count = 0; $params = array(); } } if (!empty($params)) { CRM_Mailing_Event_BAO_Queue::bulkCreate($params, $now); } } }