return $safeParams;
}
+ /**
+ * Do Submit actions.
+ *
+ * When submitting (as opposed to creating or updating) a mailing it should
+ * be scheduled.
+ *
+ * This function creates the initial job and the recipient list.
+ *
+ * @param array $params
+ * @param \CRM_Mailing_DAO_Mailing $mailing
+ *
+ * @return array
+ */
+ protected static function doSubmitActions(array $params, CRM_Mailing_DAO_Mailing $mailing): array {
+ // 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_'])) {
+ $job = new CRM_Mailing_BAO_MailingJob();
+ $job->mailing_id = $mailing->id;
+ // If we are creating a new Completed mailing (e.g. import from another system) set the job to completed.
+ // Keeping former behaviour when an id is present is precautionary and may warrant reconsideration later.
+ $job->status = ((empty($params['is_completed']) || !empty($params['id'])) ? 'Scheduled' : 'Complete');
+ $job->is_test = 0;
+
+ if (!$job->find(TRUE)) {
+ // Don't schedule job until we populate the recipients.
+ $job->scheduled_date = NULL;
+ $job->save();
+ }
+ // Schedule the job now that it has recipients.
+ $job->scheduled_date = $params['scheduled_date'];
+ $job->save();
+ }
+
+ // Populate the recipients.
+ if (empty($params['_skip_evil_bao_auto_recipients_'])) {
+ self::getRecipients($mailing->id);
+ }
+ return $params;
+ }
+
/**
* Returns the regex patterns that are used for preparing the text and html templates.
*
$transaction->commit();
- // 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_'])) {
- $job = new CRM_Mailing_BAO_MailingJob();
- $job->mailing_id = $mailing->id;
- // If we are creating a new Completed mailing (e.g. import from another system) set the job to completed.
- // Keeping former behaviour when an id is present is precautionary and may warrant reconsideration later.
- $job->status = ((empty($params['is_completed']) || !empty($params['id'])) ? 'Scheduled' : 'Complete');
- $job->is_test = 0;
-
- if (!$job->find(TRUE)) {
- // Don't schedule job until we populate the recipients.
- $job->scheduled_date = NULL;
- $job->save();
- }
- // Schedule the job now that it has recipients.
- $job->scheduled_date = $params['scheduled_date'];
- $job->save();
- }
-
- // Populate the recipients.
- if (empty($params['_skip_evil_bao_auto_recipients_'])) {
- self::getRecipients($mailing->id);
+ // These actions are really 'submit' not create actions.
+ // In v4 of the api they are not available via CRUD. At some
+ // point we will create a 'submit' function which will do the crud+submit
+ // but for now only CRUD is available via v4 api.
+ if (($params['version'] ?? '') !== 4) {
+ $params = self::doSubmitActions($params, $mailing);
}
return $mailing;