Skip to content

Commit

Permalink
CRM-21140 extend support for custom data to Mailing.
Browse files Browse the repository at this point in the history
(this requires clean up of handling of ).
  • Loading branch information
eileenmcnaughton committed Jan 30, 2018
1 parent e1b9df0 commit eb6abcf
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
17 changes: 11 additions & 6 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)) {
\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 @@ -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

0 comments on commit eb6abcf

Please sign in to comment.