-
-
Notifications
You must be signed in to change notification settings - Fork 814
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-19961 Make civicrm_sms_provider able to be domain specific #9796
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,6 +77,7 @@ public static function getProviders($selectArr = NULL, $filter = NULL, $getActiv | |
$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,15 +88,20 @@ public static function getProviders($selectArr = NULL, $filter = NULL, $getActiv | |
} | ||
|
||
/** | ||
* 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 | ||
*/ | ||
|
@@ -131,6 +137,7 @@ public static function del($providerID) { | |
|
||
$dao = new CRM_SMS_DAO_Provider(); | ||
$dao->id = $providerID; | ||
$dao->whereAdd = "(domain_id = " . CRM_Core_Config::domainID() . "OR domain_id IS NULL)"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we don't have a precedent for this - @seamuslee001 says it provides a safety net & I think it's ok There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is there a reason we can't we use the new hook_civicrm_selectWhereClause hook to implement this? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't believe the hook is invoked here There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is the delete function - we can remove this line again if it's problematic since it's precautionary. Not sure we could move it to the extension |
||
if (!$dao->find(TRUE)) { | ||
return NULL; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<?php | ||
|
||
/* | ||
+--------------------------------------------------------------------+ | ||
| CiviCRM version 4.7 | | ||
+--------------------------------------------------------------------+ | ||
| Copyright CiviCRM LLC (c) 2004-2017 | | ||
+--------------------------------------------------------------------+ | ||
| This file is a part of CiviCRM. | | ||
| | | ||
| CiviCRM is free software; you can copy, modify, and distribute it | | ||
| under the terms of the GNU Affero General Public License | | ||
| Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | ||
| | | ||
| CiviCRM is distributed in the hope that it will be useful, but | | ||
| WITHOUT ANY WARRANTY; without even the implied warranty of | | ||
| MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | ||
| See the GNU Affero General Public License for more details. | | ||
| | | ||
| You should have received a copy of the GNU Affero General Public | | ||
| License and the CiviCRM Licensing Exception along | | ||
| with this program; if not, contact CiviCRM LLC | | ||
| at info[AT]civicrm[DOT]org. If you have questions about the | | ||
| GNU Affero General Public License or the licensing of CiviCRM, | | ||
| see the CiviCRM license FAQ at http://civicrm.org/licensing | | ||
+--------------------------------------------------------------------+ | ||
*/ | ||
/** | ||
* Test CRM_SMS_BAO_Provider functions | ||
* | ||
* @package CiviCRM_APIv3 | ||
* @subpackage API_Contribution | ||
* @group headless | ||
*/ | ||
class CRM_SMS_BAO_ProviderTest extends CiviUnitTestCase { | ||
|
||
/** | ||
* Set Up Funtion | ||
*/ | ||
public function setUp() { | ||
parent::setUp(); | ||
$option = $this->callAPISuccess('option_value', 'create', array('option_group_id' => 'sms_provider_name', 'name' => 'test_provider_name', 'label' => 'test_provider_name', 'value' => 1)); | ||
$this->option_value = $option['id']; | ||
} | ||
|
||
/** | ||
* Clean up after each test. | ||
*/ | ||
public function tearDown() { | ||
parent::tearDown(); | ||
$this->callAPISuccess('option_value', 'delete', array('id' => $this->option_value)); | ||
} | ||
|
||
/** | ||
* CRM-19961 Check that when saving and updating a SMS provider with domain as NULL that it stays null | ||
*/ | ||
public function testCreateAndUpdateProvider() { | ||
$values = array( | ||
'domain_id' => NULL, | ||
'title' => 'test SMS provider', | ||
'username' => 'test', | ||
'password' => 'dummpy password', | ||
'name' => 1, | ||
'is_active' => 1, | ||
'api_type' => 1, | ||
); | ||
CRM_SMS_BAO_Provider::saveRecord($values); | ||
$provider = $this->callAPISuccess('SmsProvider', 'getsingle', array('title' => 'test SMS provider')); | ||
$domain_id = CRM_Core_DAO::getFieldValue('CRM_SMS_DAO_Provider', $provider['id'], 'domain_id'); | ||
$this->assertNull($domain_id); | ||
$values2 = array('title' => 'Test SMS Provider2'); | ||
CRM_SMS_BAO_Provider::updateRecord($values2, $provider['id']); | ||
$provider = $this->callAPISuccess('SmsProvider', 'getsingle', array('id' => $provider['id'])); | ||
$this->assertEquals('Test SMS Provider2', $provider['title']); | ||
$domain_id = CRM_Core_DAO::getFieldValue('CRM_SMS_DAO_Provider', $provider['id'], 'domain_id'); | ||
$this->assertNull($domain_id); | ||
CRM_SMS_BAO_Provider::del($provider['id']); | ||
} | ||
|
||
/** | ||
* CRM-19961 Check that when a domain is not passed when saving it defaults to current domain when create | ||
*/ | ||
public function testCreateWithoutDomain() { | ||
$values = array( | ||
'title' => 'test SMS provider', | ||
'username' => 'test', | ||
'password' => 'dummpy password', | ||
'name' => 1, | ||
'is_active' => 1, | ||
'api_type' => 1, | ||
); | ||
CRM_SMS_BAO_Provider::saveRecord($values); | ||
$provider = $this->callAPISuccess('SmsProvider', 'getsingle', array('title' => 'test SMS provider')); | ||
$domain_id = CRM_Core_DAO::getFieldValue('CRM_SMS_DAO_Provider', $provider['id'], 'domain_id'); | ||
$this->assertEquals(CRM_Core_Config::domainID(), $domain_id); | ||
CRM_SMS_BAO_Provider::del($provider['id']); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we discussed that with the api the default can be set & overridden at the api level rather than here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to set this in the civicrm_pre hook implementation within the org.civicrm.multisite extension? This would go towards the goal of moving all multisite logic out of core.
Also Eileen suggested we might use an entity_domain table rather than adding domain_id columns in all entity tables.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I plan to have a new function to sort some of this out
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@seamuslee001 that's a good point - @nganivet is suggestion putting the default in the extension rather than the api - so the api would go back to no default when you do that part.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@nganivet this is my new PR to clean up this BAO a bit and use standard functions https://github.com/civicrm/civicrm-core/pull/10135/files i have also put in Pre n post hooks as they weren't there