CIVIPLMMSR-568: Ensure scheduled_date is always set when submitting a mailing#205
CIVIPLMMSR-568: Ensure scheduled_date is always set when submitting a mailing#205erawat wants to merge 1 commit into6.4.1-patchesfrom
Conversation
Summary of ChangesHello, 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 introduces critical defensive programming to the CiviCRM mailing submission process. It addresses a potential issue where scheduled mailings could silently fail to be sent because their scheduled_date was inadvertently lost during the submission pipeline, even when a scheduled_id indicated they were meant to be scheduled. By ensuring scheduled_date is always populated when a mailing is scheduled, this change significantly improves the reliability and robustness of the mailing system, preventing mailings from disappearing from the scheduled list. Highlights
Changelog
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
Code Review
This pull request adds defensive guards to ensure scheduled_date is set when a mailing is submitted with a scheduled_id, preventing mailings from being lost in the pipeline. The changes are implemented in both the Mailing BAO and the v3 Mailing API, which is a good approach to cover different submission pathways. My review includes suggestions to improve consistency between these two new checks, particularly regarding the validation condition, logging, and the method for obtaining the current timestamp.
| if (!empty($updateParams['scheduled_id']) && empty($updateParams['scheduled_date'])) { | ||
| $updateParams['scheduled_date'] = date('YmdHis'); | ||
| } |
There was a problem hiding this comment.
This defensive check is a good addition. However, for consistency and robustness, it should be aligned with the similar check added in CRM_Mailing_BAO_Mailing::doSubmitActions.
- The condition should also check for the string
'null', which is a common pattern in CiviCRM for representing null values from forms/APIs. - A warning should be logged when this condition is met, to help with debugging potential issues in the submission pipeline.
CRM_Utils_Date::currentDBDate()should be used for getting the current timestamp to maintain consistency across the codebase.
if (!empty($updateParams['scheduled_id']) && (empty($updateParams['scheduled_date']) || $updateParams['scheduled_date'] === 'null')) {
Civi::log()->warning('civicrm_api3_mailing_submit: scheduled_id is set but scheduled_date is missing for mailing {id}. Defaulting to now.', [
'id' => $params['id'],
]);
$updateParams['scheduled_date'] = CRM_Utils_Date::currentDBDate();
}| Civi::log()->warning('doSubmitActions: scheduled_id is set but scheduled_date is missing for mailing {id}. Defaulting to now.', [ | ||
| 'id' => $params['id'] ?? $mailing->id, | ||
| ]); | ||
| $params['scheduled_date'] = date('YmdHis'); |
There was a problem hiding this comment.
For consistency with CiviCRM's coding standards, it's better to use the framework's utility functions for date operations. CRM_Utils_Date::currentDBDate() should be used instead of the native PHP date() function. This ensures that any future changes to date handling in the framework are automatically applied here.
$params['scheduled_date'] = CRM_Utils_Date::currentDBDate();cf714ef to
cb9f9d2
Compare
| * @param \CRM_Mailing_DAO_Mailing $mailing | ||
| */ | ||
| protected static function doSubmitActions(array $params, CRM_Mailing_DAO_Mailing $mailing): void { | ||
| // If scheduled_id is present but scheduled_date is not, this is an invalid |
There was a problem hiding this comment.
@erawat I think it would be better to do this on add function as well just before
$result = static::writeRecord($params);
cb9f9d2 to
e23b7e3
Compare
Summary
Patch for CIVIPLMMSR-568: Adds
ensureScheduledDate()private method inCRM_Mailing_BAO_Mailingto prevent mailings from silently disappearing whenscheduled_dateis lost during the submit pipeline. Called from bothadd()anddoSubmitActions().Core PR: civicrm#35126
Patch commit