From eca6c81ca247b1baae98840c64f0dfc313ee2bfe Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Fri, 3 Feb 2017 16:37:13 +1100 Subject: [PATCH] Add in Domain id handling into SMS provider BAO Add in domain id filtering to delete function CRM-19961 Treat NULL domain_id values as ok when retriving SMS providers Ensure domain id only gets set if its not already set Treat NULL domain_id as valid and also allow for any domain to delete providers that have domain_id which is NULL Add in API default for domain_id for sms provider Use value from database if provided even if null otherwise fall back to current domain as default but use the value submitted first Fix null test on update --- CRM/SMS/BAO/Provider.php | 12 ++++++++++++ CRM/Upgrade/Incremental/php/FourSeven.php | 12 +++++------- api/v3/SmsProvider.php | 12 ++++++++++++ 3 files changed, 29 insertions(+), 7 deletions(-) diff --git a/CRM/SMS/BAO/Provider.php b/CRM/SMS/BAO/Provider.php index ffae6a7867..5906419c81 100644 --- a/CRM/SMS/BAO/Provider.php +++ b/CRM/SMS/BAO/Provider.php @@ -77,6 +77,7 @@ class CRM_SMS_BAO_Provider extends CRM_SMS_DAO_Provider { $select = implode(',', $selectArr); $dao->selectAdd($select); } + $dao->whereAdd("(domain_id = " . CRM_Core_Config::domainID() . " OR domain_id IS NULL)"); $dao->orderBy($orderBy); $dao->find(); while ($dao->fetch()) { @@ -87,19 +88,29 @@ class CRM_SMS_BAO_Provider extends CRM_SMS_DAO_Provider { } /** + * Save a new record into the database + * @todo create a create function to do this work * @param $values */ public static function saveRecord($values) { + $values['domain_id'] = CRM_Utils_Array::value('domain_id', $values, CRM_Core_Config::domainID()); $dao = new CRM_SMS_DAO_Provider(); $dao->copyValues($values); $dao->save(); } /** + * Update an SMS provider in the database. + * @todo combine with saveRecord in a create function * @param $values * @param int $providerId */ public static function updateRecord($values, $providerId) { + $current_domain_id = CRM_Core_DAO::getFieldValue('CRM_SMS_DAO_Provider', $providerId, 'domain_id'); + if (isset($current_domain_id) || is_null($current_domain_id)) { + $current_domain_id = CRM_Core_Config::domainID(); + } + $values['domain_id'] = CRM_Utils_Array::value('domain_id', $values, $current_domain_id); $dao = new CRM_SMS_DAO_Provider(); $dao->id = $providerId; if ($dao->find(TRUE)) { @@ -131,6 +142,7 @@ class CRM_SMS_BAO_Provider extends CRM_SMS_DAO_Provider { $dao = new CRM_SMS_DAO_Provider(); $dao->id = $providerID; + $dao->whereAdd = "(domain_id = " . CRM_Core_Config::domainID() . "OR domain_id IS NULL)"; if (!$dao->find(TRUE)) { return NULL; } diff --git a/CRM/Upgrade/Incremental/php/FourSeven.php b/CRM/Upgrade/Incremental/php/FourSeven.php index ccc32db7f9..1ce61d1878 100644 --- a/CRM/Upgrade/Incremental/php/FourSeven.php +++ b/CRM/Upgrade/Incremental/php/FourSeven.php @@ -62,13 +62,6 @@ class CRM_Upgrade_Incremental_php_FourSeven extends CRM_Upgrade_Incremental_Base if ($rev == '4.7.13') { $preUpgradeMessage .= '

' . ts('A new permission has been added called %1 This Permission is now used to control access to the Manage Tags screen', array(1 => 'manage tags')) . '

'; } - if ($rev == '4.7.19') { - $check = CRM_Core_DAO::singleValueQuery("SELECT count(id) FROM civicrm_domain"); - $smsCheck = CRM_Core_DAO::singleValueQuery("SELECT count(id) FROM civicrm_sms_provider"); - if ($check > 1 && (bool) $smsCheck) { - $postUpgradeMessage .= '

civicrm_sms_provider ' . ts('has now had a domain id column added. As there is more than 1 domains in this install you need to manually set the domain id for the providers in this install') . '

'; - } - } } /** @@ -123,6 +116,11 @@ class CRM_Upgrade_Incremental_php_FourSeven extends CRM_Upgrade_Incremental_Base } if ($rev == '4.7.19') { $postUpgradeMessage .= '

' . ts('Default version of the following System Workflow Message Templates have been modified: If you have modified these templates, please review the new default versions and implement updates as needed to your copies (Administer > Communications > Message Templates > System Workflow Messages).'); + $check = CRM_Core_DAO::singleValueQuery("SELECT count(id) FROM civicrm_domain"); + $smsCheck = CRM_Core_DAO::singleValueQuery("SELECT count(id) FROM civicrm_sms_provider"); + if ($check > 1 && (bool) $smsCheck) { + $postUpgradeMessage .= '

civicrm_sms_provider ' . ts('has now had a domain id column added. As there is more than 1 domains in this install you need to manually set the domain id for the providers in this install') . '

'; + } } } diff --git a/api/v3/SmsProvider.php b/api/v3/SmsProvider.php index 87f7f30390..fc45ebb241 100644 --- a/api/v3/SmsProvider.php +++ b/api/v3/SmsProvider.php @@ -42,6 +42,18 @@ function civicrm_api3_sms_provider_create($params) { return _civicrm_api3_basic_create(_civicrm_api3_get_BAO(__FUNCTION__), $params); } +/** + * Adjust Metadata for Create action. + * + * The metadata is used for setting defaults, documentation & validation. + * + * @param array $params + * Array of parameters determined by getfields. + */ +function _civicrm_api3_sms_provider_create_spec(&$params) { + $params['domain_id']['api.default'] = CRM_Core_Config::domainID(); +} + /** * Get an sms_provider. * -- 2.25.1