unset($params['enableComponents']);
}
- // verify ssl peer option
- if (isset($params['verifySSL'])) {
- Civi::settings()->set('verifySSL', $params['verifySSL']);
- unset($params['verifySSL']);
- }
-
- // force secure URLs
- if (isset($params['enableSSL'])) {
- Civi::settings()->set('enableSSL', $params['enableSSL']);
- unset($params['enableSSL']);
+ foreach (array('verifySSL', 'enableSSL') as $name) {
+ if (isset($params[$name])) {
+ Civi::settings()->set($name, $params[$name]);
+ unset($params[$name]);
+ }
}
$settings = array_intersect_key($params, $this->_settings);
$result = civicrm_api('setting', 'create', $settings + array('version' => 3));
public function buildQuickForm() {
$config = CRM_Core_Config::singleton();
$this->_uf = $config->userFramework;
+ $this->_settings['syncCMSEmail'] = CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME;
if ($this->_uf == 'WordPress') {
$this->_settings['wpBasePage'] = CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME;
if (!$found) {
// Not sure why we're testing for this. Is there ever a case
// in which $user is not an object?
- if (is_object($user)) {
+ if (Civi::settings()->get('syncCMSEmail') && is_object($user)) {
if ($config->userSystem->is_drupal) {
$primary_email = $uniqId;
}
* Id of the contact to update.
*/
public static function updateUFName($contactId) {
- if (!$contactId) {
+ if (!Civi::settings()->get('syncCMSEmail') || !$contactId) {
return;
}
+
$config = CRM_Core_Config::singleton();
$ufName = CRM_Contact_BAO_Contact::getPrimaryEmail($contactId);
$ufmatch->uf_name = $emailAddress;
CRM_Core_BAO_UFMatch::create((array) $ufmatch);
+ // If CMS integration is disabled skip Civi email update if CMS user email is changed
+ if (Civi::settings()->get('syncCMSEmail') == FALSE) {
+ return;
+ }
+
//check if the primary email for the contact exists
//$contactDetails[1] - email
//$contactDetails[3] - email id
'description' => ts('Default to only loading matches against this number of contacts'),
'help_text' => ts('Deduping larger databases can crash the server. By configuring a limit other than 0 here the dedupe query will only search for matches against a limited number of contacts.'),
),
+ 'syncCMSEmail' => array(
+ 'group_name' => 'CiviCRM Preferences',
+ 'group' => 'core',
+ 'name' => 'syncCMSEmail',
+ 'type' => 'Boolean',
+ 'quick_form_type' => 'YesNo',
+ 'default' => 1,
+ 'add' => '4.7',
+ 'title' => 'Sync CMS Email',
+ 'is_domain' => 1,
+ 'is_contact' => 0,
+ 'description' => 'If enabled, then CMS email id will be syncronised with CiviCRM contacts\'s primary email.',
+ 'help_text' => NULL,
+ ),
);
</td>
</tr>
{/if}
+ <tr class="crm-uf-form-block-syncCMSEmail">
+ <td class="label">{$form.syncCMSEmail.label}</td>
+ <td>{$form.syncCMSEmail.html}</td>
+ </tr>
</table>
<div class="crm-submit-buttons">{include file="CRM/common/formButtons.tpl" location="bottom"}</div>
<div class="spacer"></div>
$this->getAndCheck($this->_params, $result['id'], 'uf_match');
}
+ /**
+ * Test Civi to CMS email sync optional
+ */
+ public function testUFNameMatchSync() {
+ $this->callAPISuccess('uf_match', 'create', $this->_params);
+ $email1 = substr(sha1(rand()), 0, 7) . '@test.com';
+ $email2 = substr(sha1(rand()), 0, 7) . '@test.com';
+
+ // Case A: Enable CMS integration
+ Civi::settings()->set('syncCMSEmail', TRUE);
+ $this->callAPISuccess('email', 'create', array(
+ 'contact_id' => $this->_contactId,
+ 'email' => $email1,
+ 'is_primary' => 1,
+ ));
+ $ufName = $this->callAPISuccess('uf_match', 'getvalue', array(
+ 'contact_id' => $this->_contactId,
+ 'return' => 'uf_name',
+ ));
+ $this->assertEquals($email1, $ufName);
+
+ // Case B: Disable CMS integration
+ Civi::settings()->set('syncCMSEmail', FALSE);
+ $this->callAPISuccess('email', 'create', array(
+ 'contact_id' => $this->_contactId,
+ 'email' => $email2,
+ 'is_primary' => 1,
+ ));
+ $ufName = $this->callAPISuccess('uf_match', 'getvalue', array(
+ 'contact_id' => $this->_contactId,
+ 'return' => 'uf_name',
+ ));
+ $this->assertNotEquals($email2, $ufName, 'primary email will not match if changed on disabled CMS integration setting');
+ $this->assertEquals($email1, $ufName);
+ }
+
public function testDelete() {
$result = $this->callAPISuccess('uf_match', 'create', $this->_params);
$this->assertEquals(1, $this->callAPISuccess('uf_match', 'getcount', array(