From: Coleman Watts Date: Sun, 12 Jul 2020 20:56:25 +0000 (-0400) Subject: REF - Cleanup StatusPreference BAO to be more standard X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=fcb37cd59fc6c202661e222d9bf54533a6b37f26;p=civicrm-core.git REF - Cleanup StatusPreference BAO to be more standard --- diff --git a/CRM/Core/BAO/StatusPreference.php b/CRM/Core/BAO/StatusPreference.php index d4e182eadc..044a538d04 100644 --- a/CRM/Core/BAO/StatusPreference.php +++ b/CRM/Core/BAO/StatusPreference.php @@ -10,11 +10,8 @@ */ /** - * * @package CRM * @copyright CiviCRM LLC https://civicrm.org/licensing - * $Id$ - * */ /** @@ -27,16 +24,15 @@ class CRM_Core_BAO_StatusPreference extends CRM_Core_DAO_StatusPreference { * * @param array $params * - * @return array + * @return CRM_Core_DAO_StatusPreference * @throws CRM_Core_Exception */ public static function create($params) { - $statusPreference = new CRM_Core_BAO_StatusPreference(); + $statusPreference = new CRM_Core_DAO_StatusPreference(); // Default severity level to ignore is 0 (DEBUG). - if (!isset($params['ignore_severity'])) { - $params['ignore_severity'] = 0; - } + $params['ignore_severity'] = $params['ignore_severity'] ?? 0; + // Severity can be either text ('critical') or an integer <= 7. // It's a magic number, but based on PSR-3 standards. if (!CRM_Utils_Rule::integer($params['ignore_severity'])) { @@ -50,32 +46,25 @@ class CRM_Core_BAO_StatusPreference extends CRM_Core_DAO_StatusPreference { throw new CRM_Core_Exception(ts('Invalid string passed as severity level.')); } - // Check if this StatusPreference already exists. + // Set default domain when creating (or updating by name) + if (empty($params['id']) && empty($params['domain_id'])) { + $params['domain_id'] = CRM_Core_Config::domainID(); + } + + // Enforce unique status pref names. Update if a duplicate name is found in the same domain. if (empty($params['id']) && !empty($params['name'])) { - $statusPreference->domain_id = CRM_Utils_Array::value('domain_id', $params, CRM_Core_Config::domainID()); + $statusPreference->domain_id = $params['domain_id']; $statusPreference->name = $params['name']; - $statusPreference->find(TRUE); } - $statusPreference->copyValues($params); - - $edit = (bool) $statusPreference->id; - if ($edit) { - CRM_Utils_Hook::pre('edit', 'StatusPreference', $statusPreference->id, $statusPreference); - } - else { - CRM_Utils_Hook::pre('create', 'StatusPreference', NULL, $statusPreference); - } + $op = $statusPreference->id ? 'edit' : 'create'; + CRM_Utils_Hook::pre($op, 'StatusPreference', $statusPreference->id, $params); + $statusPreference->copyValues($params); $statusPreference->save(); - if ($edit) { - CRM_Utils_Hook::post('edit', 'StatusPreference', $statusPreference->id, $statusPreference); - } - else { - CRM_Utils_Hook::post('create', 'StatusPreference', NULL, $statusPreference); - } + CRM_Utils_Hook::post($op, 'StatusPreference', $statusPreference->id, $statusPreference); return $statusPreference; }