From: larssandergreen Date: Sat, 14 Oct 2023 20:35:32 +0000 (-0600) Subject: Use writeRecords for Navigations X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=391560f7382fa9697cfa4800183dfeddfa68057c;p=civicrm-core.git Use writeRecords for Navigations --- diff --git a/CRM/Core/BAO/Navigation.php b/CRM/Core/BAO/Navigation.php index 5357b6f7d4..c9a4c61202 100644 --- a/CRM/Core/BAO/Navigation.php +++ b/CRM/Core/BAO/Navigation.php @@ -74,7 +74,6 @@ class CRM_Core_BAO_Navigation extends CRM_Core_DAO_Navigation { * @return CRM_Core_DAO_Navigation */ public static function add(&$params) { - $navigation = new CRM_Core_DAO_Navigation(); if (empty($params['id'])) { $params['is_active'] = CRM_Utils_Array::value('is_active', $params, FALSE); $params['has_separator'] = CRM_Utils_Array::value('has_separator', $params, FALSE); @@ -102,10 +101,7 @@ class CRM_Core_BAO_Navigation extends CRM_Core_DAO_Navigation { $params['permission'] = implode(',', $params['permission']); } - $navigation->copyValues($params); - - $navigation->save(); - return $navigation; + return self::writeRecord($params); } /** @@ -513,11 +509,11 @@ ORDER BY weight"; break; case "rename": - self::processRename($nodeID, $label); + self::writeRecord(['id' => $nodeID, 'label' => $label]); break; case "delete": - self::processDelete($nodeID); + self::deleteRecord(['id' => $nodeID]); break; } @@ -578,8 +574,6 @@ ORDER BY weight"; $incrementOtherNodes = FALSE; } - $transaction = new CRM_Core_Transaction(); - // now update the existing nodes to weight + 1, if required. if ($incrementOtherNodes) { $query = "UPDATE civicrm_navigation SET weight = weight + 1 @@ -588,11 +582,8 @@ ORDER BY weight"; CRM_Core_DAO::executeQuery($query); } - // finally set the weight of current node - $query = "UPDATE civicrm_navigation SET weight = {$newWeight}, parent_id = {$newParentID} WHERE id = {$nodeID}"; - CRM_Core_DAO::executeQuery($query); - - $transaction->commit(); + // finally set the weight and parent of current node + self::writeRecord(['id' => $nodeID, 'weight' => $newWeight, 'parent_id' => $newParentID]); } /** @@ -600,19 +591,20 @@ ORDER BY weight"; * * @param int $nodeID * @param $label + * @deprecated - use API */ public static function processRename($nodeID, $label) { - CRM_Core_DAO::setFieldValue('CRM_Core_DAO_Navigation', $nodeID, 'label', $label); + self::writeRecord(['id' => $nodeID, 'label' => $label]); } /** * Process delete action for tree. * * @param int $nodeID + * @deprecated - use API */ public static function processDelete($nodeID) { - $query = "DELETE FROM civicrm_navigation WHERE id = {$nodeID}"; - CRM_Core_DAO::executeQuery($query); + self::deleteRecord(['id' => $nodeID]); } /** diff --git a/CRM/Report/BAO/ReportInstance.php b/CRM/Report/BAO/ReportInstance.php index eb7ff8fd6f..1e183b19a9 100644 --- a/CRM/Report/BAO/ReportInstance.php +++ b/CRM/Report/BAO/ReportInstance.php @@ -240,7 +240,7 @@ class CRM_Report_BAO_ReportInstance extends CRM_Report_DAO_ReportInstance implem // When deleting a report, also delete from navigation menu $navId = CRM_Core_DAO::getFieldValue('CRM_Report_DAO_ReportInstance', $event->id, 'navigation_id'); if ($navId) { - CRM_Core_BAO_Navigation::processDelete($navId); + CRM_Core_BAO_Navigation::deleteRecord(['id' => $navId]); CRM_Core_BAO_Navigation::resetNavigation(); } } diff --git a/CRM/Report/Form/Instance.php b/CRM/Report/Form/Instance.php index ecd3942715..fe77273cfc 100644 --- a/CRM/Report/Form/Instance.php +++ b/CRM/Report/Form/Instance.php @@ -318,7 +318,7 @@ class CRM_Report_Form_Instance { // Delete navigation if exists. $navId = CRM_Core_DAO::getFieldValue('CRM_Report_DAO_ReportInstance', $instanceID, 'navigation_id', 'id'); if ($navId) { - CRM_Core_BAO_Navigation::processDelete($navId); + CRM_Core_BAO_Navigation::deleteRecord(['id' => $navId]); CRM_Core_BAO_Navigation::resetNavigation(); } }