Skip to content

Commit

Permalink
refs #39633, gh-111, exclude remote groups when sync
Browse files Browse the repository at this point in the history
  • Loading branch information
jimyhuang committed Jan 22, 2024
1 parent ec42f71 commit 26d24f9
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
26 changes: 25 additions & 1 deletion CRM/Group/Form/Edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ class CRM_Group_Form_Edit extends CRM_Core_Form {
*/
protected $_smartMarketingTypeId;

/**
* the smart marketing freezed groups
*
* @var array
*/
protected $_smartMarketingFreezed = array();

/**
* set up variables to build the form
*
Expand Down Expand Up @@ -161,6 +168,22 @@ function preProcess() {

// smart marketing
$this->initSmartMarketingGroup();

if ($this->_smartMarketingTypeId) {
// check freezed remote group to prevent many local to 1 remote group issue
if ($this->_id) {
$syncData = CRM_Core_DAO::executeQuery("SELECT id, sync_data FROM civicrm_group WHERE NULLIF(sync_data, '') IS NOT NULL AND id != %1", array(1 => array($this->_id, 'Integer')));
}
else {
$syncData = CRM_Core_DAO::executeQuery("SELECT id, sync_data FROM civicrm_group NULLIF(sync_data, '') IS NOT NULL");
}
while($syncData->fetch()) {
$data = json_decode($syncData->sync_data, TRUE);
if (!empty($data['remote_group_id'])) {
$this->_smartMarketingFreezed[$data['remote_group_id']] = 1;
}
}
}
}

/*
Expand Down Expand Up @@ -281,7 +304,7 @@ public function buildQuickForm() {
$ele->_attributes['data-filter'] = $filterGroupTypes[$gtId];
if (strstr($filterGroupTypes[$gtId], 'Smart-Marketing')) {
// freeze when remote_group_id has value
if (!empty($this->_groupValues['is_sync'])) {
if (!empty($this->_groupValues['is_sync']) || !empty($this->_groupValues['sync_data'])) {
$ele->freeze();
}
}
Expand All @@ -297,6 +320,7 @@ public function buildQuickForm() {
}
// flydove doesn't support create group
// $remoteGroups = array('-1' => '-- '.ts('Create New Group').' --') + $remoteGroups;
$remoteGroups = array_diff_key($remoteGroups, $this->_smartMarketingFreezed);
$eleSmGroup = $this->addSelect('remote_group_id', ts('Smart Marketing Group'), $remoteGroups);
if (!empty($this->_groupValues['is_sync'])) {
$eleSmGroup->freeze();
Expand Down
2 changes: 1 addition & 1 deletion templates/CRM/Group/Form/Edit.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
<script>{literal}
cj(function($){
$('.crm-group-form-block-remote_group_id').hide();
if ($('.crm-group-form-block-remote_group_id input[type=hidden][name=remote_group_id]')) {
if ($('.crm-group-form-block-remote_group_id input[type=hidden][name=remote_group_id]').length) {
$('.crm-group-form-block-remote_group_id').show();
}
$('input[name*=group_type]').each(function(){
Expand Down

0 comments on commit 26d24f9

Please sign in to comment.