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-19961 Make civicrm_sms_provider able to be domain specific #9796

Merged
merged 2 commits into from
Apr 11, 2017

Conversation

seamuslee001
Copy link
Contributor

@seamuslee001 seamuslee001 commented Feb 6, 2017

@seamuslee001
Copy link
Contributor Author

@eileenmcnaughton does this look good to you?

@seamuslee001
Copy link
Contributor Author

Just tagging in @MrLavaLava to be a watcher on this PR

@eileenmcnaughton
Copy link
Contributor

I ran my eye over it & it looks good - I haven't done any in depth QA

@seamuslee001
Copy link
Contributor Author

pinging @nganivet I think you maybe interested in this as this assists with the multisite functionality in CiviCRM

@nganivet
Copy link
Contributor

nganivet commented Feb 7, 2017

thanks @seamuslee001. Have not looked at the patch but can you make sure that NULL in the column translates to 'valid for all domain'? I have enforced this on all my multi-site improvements to ensure compatibility with previous data (ie. if someone previously had defined an SMS provider and upgrades CiviCRM we want this SMS provider to be valid for all domain to keep the same behavior).

@seamuslee001
Copy link
Contributor Author

thanks @nganivet I have altered the function on the retrieve to handle that, I have also ensured that if domain_id is not set when an SMS provider is updated that the current domain id is set i think that is pretty normal

@@ -93,7 +93,9 @@ public static function getProviders($selectArr = NULL, $filter = NULL, $getActiv
public static function saveRecord($values) {
$dao = new CRM_SMS_DAO_Provider();
$dao->copyValues($values);
$dao->domain_id = CRM_Core_Config::domainID();
if (!empty($dao->domain_id)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this IF right? It's confusing me

Copy link
Contributor

Choose a reason for hiding this comment

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

  • oh it's a domain-theft pattern? I edit something on another domain & I steal the record? That seems like maybe a form-layer thing to me

@@ -92,6 +93,9 @@ public static function getProviders($selectArr = NULL, $filter = NULL, $getActiv
public static function saveRecord($values) {
$dao = new CRM_SMS_DAO_Provider();
$dao->copyValues($values);
if (empty($dao->domain_id)) {
$dao->domain_id = CRM_Core_Config::domainID();
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this correct - I thought 'NULL' was 'valid'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes but here your saving a record into the db so i guess the question is should we update NULL values = the current domain or leave them as they are?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Have now updated using the style found here

$statusPreference->domain_id = CRM_Utils_Array::value('domain_id', $params, CRM_Core_Config::domainID());

@seamuslee001 seamuslee001 force-pushed the CRM-19961 branch 2 times, most recently from cccf9ae to 55ac47c Compare April 10, 2017 21:06
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
if (is_null($current_domain_id)) {
$current_domain_id = NULL;
}
elseif (!isset($current_domain_id)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

this seems impossible

@eileenmcnaughton
Copy link
Contributor

I've added merge on pass, but have also discussed with @seamuslee001 that once this is merged he is going to work on changing it to use the api & associated clean up

@@ -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)";
Copy link
Contributor

Choose a reason for hiding this comment

The 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

Copy link
Contributor

Choose a reason for hiding this comment

The 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?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't believe the hook is invoked here

Copy link
Contributor

Choose a reason for hiding this comment

The 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

* @param $values
*/
public static function saveRecord($values) {
$values['domain_id'] = CRM_Utils_Array::value('domain_id', $values, CRM_Core_Config::domainID());
Copy link
Contributor

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

Copy link
Contributor

@nganivet nganivet Apr 11, 2017

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.

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor Author

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

remove changes to update function

Fix style
@eileenmcnaughton
Copy link
Contributor

I've merged per comments -leaving entity_domain table out of scope for this round

@seamuslee001 seamuslee001 deleted the CRM-19961 branch April 11, 2017 09:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants