Skip to content

CIVIPLMMSR-568: Ensure scheduled_date is always set when submitting a mailing#206

Open
erawat wants to merge 1 commit into5.75.0-patchesfrom
CIVIPLMMSR-568-5.75.0-patch
Open

CIVIPLMMSR-568: Ensure scheduled_date is always set when submitting a mailing#206
erawat wants to merge 1 commit into5.75.0-patchesfrom
CIVIPLMMSR-568-5.75.0-patch

Conversation

@erawat
Copy link
Copy Markdown
Member

@erawat erawat commented Mar 17, 2026

Summary

Patch for CIVIPLMMSR-568: Adds ensureScheduledDate() private method in CRM_Mailing_BAO_Mailing to prevent mailings from silently disappearing when scheduled_date is lost during the submit pipeline. Called from both add() and doSubmitActions().

Core PR: civicrm#35126

Patch commit

CIVIPLMMSR-568: Ensure scheduled_date is always set when submitting a mailing
PR: https://github.com/civicrm/civicrm-core/pull/35126

@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request addresses a critical issue where scheduled mailings could silently disappear from the system if their scheduled_date was inadvertently lost during the submission pipeline. By introducing robust defensive checks, it ensures that all mailings with a scheduled_id consistently have a scheduled_date, thereby preventing data loss and ensuring reliable scheduling.

Highlights

  • Prevent silent mailing disappearance: Implemented defensive checks to ensure that scheduled mailings always have a scheduled_date set, preventing them from being lost if this crucial field goes missing during the submission process.
  • scheduled_date defaulting: When a mailing has a scheduled_id but lacks a scheduled_date, the system will now automatically default the scheduled_date to the current timestamp (now) to maintain data integrity and ensure proper scheduling.
  • Logging for missing dates: Added a warning log entry in CRM/Mailing/BAO/Mailing.php when a scheduled_id is present but scheduled_date is missing, providing visibility into potential data inconsistencies.
Changelog
  • CRM/Mailing/BAO/Mailing.php
    • Added logic within doSubmitActions to check if scheduled_id is present but scheduled_date is missing or 'null'. If so, it logs a warning and sets scheduled_date to the current timestamp.
  • api/v3/Mailing.php
    • Added a similar check in civicrm_api3_mailing_submit to ensure scheduled_date is populated with the current timestamp if scheduled_id is present but scheduled_date is empty.
Activity
  • No human activity has been recorded on this pull request yet.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces defensive guards to ensure scheduled_date is set when a mailing is submitted, preventing mailings from being lost. The core logic is added to CRM_Mailing_BAO_Mailing::doSubmitActions, which is a good central place for this safeguard. A similar check is added to api/v3/Mailing.php. My review suggests removing the redundant and less complete check from the API file to rely on the more robust implementation in the BAO layer, which also improves logging consistency.

Comment on lines +276 to +282
// Ensure scheduled_date is always set when scheduled_id is present.
// There are edge cases where scheduled_date can be lost during the create
// pipeline, resulting in mailings that have a scheduled_id but NULL
// scheduled_date — which prevents the mail scheduler from ever sending them.
if (!empty($updateParams['scheduled_id']) && empty($updateParams['scheduled_date'])) {
$updateParams['scheduled_date'] = date('YmdHis');
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

This check for scheduled_id and scheduled_date is now redundant due to the more comprehensive logic added in CRM_Mailing_BAO_Mailing::doSubmitActions. The doSubmitActions method is called within this API function's execution path, so this check is not necessary here.

The logic in doSubmitActions is also more robust because it handles cases where scheduled_date is the string 'null' and it logs a warning, which is helpful for debugging.

Removing this block will improve consistency and ensure that a warning is always logged when this fallback is triggered, relying on the single source of truth in the BAO.

@erawat erawat force-pushed the CIVIPLMMSR-568-5.75.0-patch branch from 3a5e8b1 to d2b0b32 Compare March 17, 2026 11:27
@erawat erawat force-pushed the CIVIPLMMSR-568-5.75.0-patch branch from d2b0b32 to f94c13c Compare March 17, 2026 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants