Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CRM-21140 extend support for custom data to Mailing api #11608

Merged
merged 1 commit into from
Feb 17, 2018
Merged
Show file tree
Hide file tree
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
19 changes: 12 additions & 7 deletions CRM/Mailing/BAO/Mailing.php
Original file line number Diff line number Diff line change
Expand Up @@ -1409,7 +1409,11 @@ public function &getGroupNames() {
* @return CRM_Mailing_DAO_Mailing
*/
public static function add(&$params, $ids = array()) {
$id = CRM_Utils_Array::value('mailing_id', $ids, CRM_Utils_Array::value('id', $params));
$id = CRM_Utils_Array::value('id', $params, CRM_Utils_Array::value('mailing_id', $ids));

if (empty($params['id']) && !empty($ids)) {
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this condition just be if (!empty($ids))?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

$ids actually won't be empty coming from the api - it will hold ['Mailing' => $params['id']] - but the goal is to make the $ids array first meaningless & then to remove it - as long as they are correctly setting the $params array they can pass anything or nothing in $ids

\Civi::log('Parameter $ids is no longer used by Mailing::add. Use the api or just pass $params', ['civi.tag' => 'deprecated']);
}

if ($id) {
CRM_Utils_Hook::pre('edit', 'Mailing', $id, $params);
Expand Down Expand Up @@ -1443,7 +1447,7 @@ public static function add(&$params, $ids = array()) {
$result->modified_date = $mailing->modified_date;
}

if (!empty($ids['mailing'])) {
if ($id) {
CRM_Utils_Hook::post('edit', 'Mailing', $mailing->id, $mailing);
}
else {
Expand Down Expand Up @@ -1482,15 +1486,16 @@ public static function add(&$params, $ids = array()) {
* @throws \Exception
*/
public static function create(&$params, $ids = array()) {
// WTH $ids
if (empty($ids) && isset($params['id'])) {
$ids['mailing_id'] = $ids['id'] = $params['id'];

if (empty($params['id']) && (array_filter($ids) !== [])) {
$params['id'] = isset($ids['mailing_id']) ? $ids['mailing_id'] : $ids['id'];
\Civi::log('Parameter $ids is no longer used by Mailing::create. Use the api or just pass $params', ['civi.tag' => 'deprecated']);
}

// CRM-12430
// Do the below only for an insert
// for an update, we should not set the defaults
if (!isset($ids['id']) && !isset($ids['mailing_id'])) {
if (!isset($params['id'])) {
// Retrieve domain email and name for default sender
$domain = civicrm_api(
'Domain',
Expand Down Expand Up @@ -1559,7 +1564,7 @@ public static function create(&$params, $ids = array()) {

$transaction = new CRM_Core_Transaction();

$mailing = self::add($params, $ids);
$mailing = self::add($params);

if (is_a($mailing, 'CRM_Core_Error')) {
$transaction->rollback();
Expand Down
2 changes: 1 addition & 1 deletion api/v3/Mailing.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function civicrm_api3_mailing_create($params) {

// FlexMailer is a refactoring of CiviMail which provides new hooks/APIs/docs. If the sysadmin has opted to enable it, then use that instead of CiviMail.
$safeParams['_evil_bao_validator_'] = \CRM_Utils_Constant::value('CIVICRM_FLEXMAILER_HACK_SENDABLE', 'CRM_Mailing_BAO_Mailing::checkSendable');
$result = _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $safeParams);
$result = _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $safeParams, 'Mailing');
return _civicrm_api3_mailing_get_formatResult($result);
}

Expand Down
1 change: 1 addition & 0 deletions tests/phpunit/api/v3/SyntaxConformanceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ public static function custom_data_incl_non_std_entities_get() {
$customDataEntities[] = ['UFGroup'];
$customDataEntities[] = ['PriceSet'];
$customDataEntities[] = ['PaymentToken'];
$customDataEntities[] = ['Mailing'];
return $customDataEntities;
}

Expand Down