Skip to content

Commit

Permalink
Merge pull request #27304 from eileenmcnaughton/split
Browse files Browse the repository at this point in the history
Make splitjob function static & private, Remove a couple of unused variables
  • Loading branch information
eileenmcnaughton authored Sep 5, 2023
2 parents 7dde58d + 835103a commit f2500c4
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions CRM/Mailing/BAO/MailingJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ public static function runJobs_pre($offset = 200, $mode = NULL) {

$transaction = new CRM_Core_Transaction();

$job->split_job($offset);
$job->split_job((int) $offset, (int) $job->id, (int) $job->mailing_id, $job->scheduled_date);

// Update the status of the parent job
self::create(['id' => $job->id, 'start_date' => date('YmdHis'), 'status' => 'Running']);
Expand All @@ -365,26 +365,27 @@ public static function runJobs_pre($offset = 200, $mode = NULL) {
/**
* 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
* @param int $jobID
* @param int $mailingID
* @param string $scheduledDate
*
* @throws \Civi\Core\Exception\DBQueryException
*/
public function split_job($offset = 200) {
$recipient_count = CRM_Mailing_BAO_MailingRecipients::mailingSize($this->mailing_id);

$jobTable = CRM_Mailing_DAO_MailingJob::getTableName();

$dao = new CRM_Core_DAO();

$sql = "
private static function split_job(int $offset, int $jobID, int $mailingID, string $scheduledDate): void {
$recipient_count = CRM_Mailing_BAO_MailingRecipients::mailingSize($mailingID);
$sql = '
INSERT INTO civicrm_mailing_job
(`mailing_id`, `scheduled_date`, `status`, `job_type`, `parent_id`, `job_offset`, `job_limit`)
VALUES (%1, %2, %3, %4, %5, %6, %7)
";
';
$params = [
1 => [$this->mailing_id, 'Integer'],
2 => [$this->scheduled_date, 'String'],
1 => [$mailingID, 'Integer'],
2 => [$scheduledDate, 'String'],
3 => ['Scheduled', 'String'],
4 => ['child', 'String'],
5 => [$this->id, 'Integer'],
5 => [$jobID, 'Integer'],
6 => [0, 'Integer'],
7 => [$recipient_count, 'Integer'],
];
Expand All @@ -398,9 +399,9 @@ public function split_job($offset = 200) {
}
else {
// Creating 'child jobs'
$scheduled_unixtime = strtotime($this->scheduled_date);
for ($i = 0, $s = 0; $i < $recipient_count; $i = $i + $offset, $s++) {
$params[2][0] = date('Y-m-d H:i:s', $scheduled_unixtime + $s);
$scheduled_unix_time = strtotime($scheduledDate);
for ($i = 0, $s = 0; $i < $recipient_count; $i += $offset, $s++) {
$params[2][0] = date('Y-m-d H:i:s', $scheduled_unix_time + $s);
$params[6][0] = $i;
$params[7][0] = $offset;
CRM_Core_DAO::executeQuery($sql, $params);
Expand Down

0 comments on commit f2500c4

Please sign in to comment.