Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions CRM/Mailing/BAO/Mailing.php
Original file line number Diff line number Diff line change
Expand Up @@ -442,6 +442,8 @@ protected static function processWorkflowPermissions(array $params): array {
* @param \CRM_Mailing_DAO_Mailing $mailing
*/
protected static function doSubmitActions(array $params, CRM_Mailing_DAO_Mailing $mailing): void {
$params = self::ensureScheduledDate($params);

// Create parent job if not yet created.
// Condition on the existence of a scheduled date.
if (!empty($params['scheduled_date']) && $params['scheduled_date'] !== 'null' && empty($params['_skip_evil_bao_auto_schedule_'])) {
Expand Down Expand Up @@ -475,6 +477,26 @@ protected static function doSubmitActions(array $params, CRM_Mailing_DAO_Mailing
}
}

/**
* Ensure scheduled_date is set when scheduled_id is present.
*
* A mailing with scheduled_id but no scheduled_date is an invalid state
* that prevents the mail scheduler from ever sending it. This guards
* against edge cases where scheduled_date is lost in the pipeline.
*
* @param array $params
* @return array
*/
private static function ensureScheduledDate(array $params): array {
if (!empty($params['scheduled_id']) && (empty($params['scheduled_date']) || $params['scheduled_date'] === 'null')) {
Civi::log()->warning('Mailing: scheduled_id is set but scheduled_date is missing for mailing {id}. Defaulting to now.', [
'id' => $params['id'] ?? 'unknown',
]);
$params['scheduled_date'] = CRM_Utils_Date::currentDBDate();
}
return $params;
}

/**
* Refresh the group cache for groups relevant to the mailing.
*
Expand Down Expand Up @@ -988,6 +1010,7 @@ public static function add($params) {
}
// CRM-20892 Unset Modifed Date here so that MySQL can correctly set an updated modfied date.
unset($params['modified_date']);
$params = self::ensureScheduledDate($params);

$result = static::writeRecord($params);

Expand Down