From: Eileen McNaughton Date: Fri, 18 Feb 2022 00:05:24 +0000 (+1300) Subject: Block crud for v4 api X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=cbbddb895c0486d464a7c214b391ed0105aa9d9d;p=civicrm-core.git Block crud for v4 api --- diff --git a/CRM/Mailing/BAO/Mailing.php b/CRM/Mailing/BAO/Mailing.php index b099f6beb6..93592c8e01 100644 --- a/CRM/Mailing/BAO/Mailing.php +++ b/CRM/Mailing/BAO/Mailing.php @@ -456,6 +456,47 @@ class CRM_Mailing_BAO_Mailing extends CRM_Mailing_DAO_Mailing { 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. * @@ -1613,29 +1654,12 @@ ORDER BY civicrm_email.is_bulkmail DESC $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;