Skip to content
Snippets Groups Projects
Commit b7080f5a authored by colemanw's avatar colemanw
Browse files

SiteEmailAddress - Enforce default one default per domain

Also removed unnecessary domain filtering logic from OptionValue as this was the only option group it applied to.
parent a8b07502
Branches
Tags
No related merge requests found
......@@ -551,11 +551,6 @@ class CRM_Core_BAO_OptionValue extends CRM_Core_DAO_OptionValue implements \Civi
$query = 'UPDATE civicrm_option_value SET is_default = 0 WHERE option_group_id = %1 AND id <> %2';
$queryParams = [1 => [$optionGroupID, 'Integer'], 2 => [$id, 'Integer']];
// Limit update by domain of option. This is loaded if it is a domain option group.
if (!empty($optionValue->domain_id)) {
$query .= ' AND domain_id = %3';
$queryParams[3] = [(int) $optionValue->domain_id, 'Integer'];
}
if (in_array($groupName, ['email_greeting', 'postal_greeting', 'addressee'], TRUE)) {
$variableNumber = count($queryParams) + 1;
$query .= ' AND filter = %' . $variableNumber;
......
<?php
/*
+--------------------------------------------------------------------+
| Copyright CiviCRM LLC. All rights reserved. |
| |
| This work is published under the GNU AGPLv3 license with some |
| permitted exceptions and without any warranty. For full license |
| and copyright information, see https://civicrm.org/licensing |
+--------------------------------------------------------------------+
*/
/**
*
* @package CRM
* @copyright CiviCRM LLC https://civicrm.org/licensing
*/
/**
* SiteEmailAddress business logic
*/
class CRM_Core_BAO_SiteEmailAddress extends CRM_Core_DAO_SiteEmailAddress implements \Civi\Core\HookInterface {
public static function self_hook_civicrm_pre(\Civi\Core\Event\PreEvent $event) {
// When setting default, ensure other records for this domain are not the default
if (($event->action === 'create' || $event->action === 'edit') && !empty($event->params['is_default'])) {
$domainId = $event->params['domain_id'] ?? self::getDbVal('domain_id', $event->id);
CRM_Core_DAO::executeQuery('UPDATE civicrm_site_email_address SET is_default = 0 WHERE domain_id = %1 AND is_default = 1', [
1 => [$domainId, 'Positive'],
]);
}
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment