From 1a7f0e943b0bb51041032883e13a4d9c0abc961b Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Wed, 27 Oct 2021 12:58:03 -0400 Subject: [PATCH] CRM_Core_Menu - Fix syntax, undefined variables, unused code, pass-by-ref --- CRM/Core/Menu.php | 79 ++++++++++++------------------------ CRM/Upgrade/Page/Cleanup.php | 49 ---------------------- 2 files changed, 25 insertions(+), 103 deletions(-) delete mode 100644 CRM/Upgrade/Page/Cleanup.php diff --git a/CRM/Core/Menu.php b/CRM/Core/Menu.php index a25a8e39cb..ad45953413 100644 --- a/CRM/Core/Menu.php +++ b/CRM/Core/Menu.php @@ -16,8 +16,6 @@ * @copyright CiviCRM LLC https://civicrm.org/licensing */ -require_once 'CRM/Core/I18n.php'; - /** * Class CRM_Core_Menu. */ @@ -37,13 +35,13 @@ class CRM_Core_Menu { */ public static $_permissionedItems = NULL; - public static $_serializedElements = array( + public static $_serializedElements = [ 'access_arguments', 'access_callback', 'page_arguments', 'page_callback', 'breadcrumb', - ); + ]; public static $_menuCache = NULL; const MENU_ITEM = 1; @@ -58,8 +56,6 @@ class CRM_Core_Menu { */ public static function &xmlItems($fetchFromXML = FALSE) { if (!self::$_items || $fetchFromXML) { - $config = CRM_Core_Config::singleton(); - // We needs this until Core becomes a component $coreMenuFilesNamespace = 'CRM_Core_xml_Menu'; $coreMenuFilesPath = str_replace('_', DIRECTORY_SEPARATOR, $coreMenuFilesNamespace); @@ -121,7 +117,7 @@ class CRM_Core_Menu { if ($item->ids_arguments) { $ids = []; - foreach (array('json' => 'json', 'html' => 'html', 'exception' => 'exceptions') as $tag => $attr) { + foreach (['json' => 'json', 'html' => 'html', 'exception' => 'exceptions'] as $tag => $attr) { $ids[$attr] = []; foreach ($item->ids_arguments->{$tag} as $value) { $ids[$attr][] = (string) $value; @@ -158,10 +154,10 @@ class CRM_Core_Menu { foreach ($elements as $element) { $items[] = $element; } - $value = array($items, $op); + $value = [$items, $op]; } else { - $value = array(array($value), 'and'); + $value = [[$value], 'and']; } } elseif ($key == 'is_public' || $key == 'is_ssl') { @@ -191,8 +187,8 @@ class CRM_Core_Menu { * * @return bool */ - public static function isArrayTrue(&$values) { - foreach ($values as $name => $value) { + public static function isArrayTrue($values) { + foreach ($values as $value) { if (!$value) { return FALSE; } @@ -209,13 +205,13 @@ class CRM_Core_Menu { * @throws CRM_Core_Exception */ public static function fillMenuValues(&$menu, $path) { - $fieldsToPropagate = array( + $fieldsToPropagate = [ 'access_callback', 'access_arguments', 'page_callback', 'page_arguments', 'is_ssl', - ); + ]; $fieldsPresent = []; foreach ($fieldsToPropagate as $field) { $fieldsPresent[$field] = isset($menu[$path][$field]); @@ -355,16 +351,16 @@ class CRM_Core_Menu { $query = !empty($item['path_arguments']) ? str_replace(',', '&', $item['path_arguments']) . '&reset=1' : 'reset=1'; - $value = array( + $value = [ 'title' => $item['title'], 'desc' => $item['desc'] ?? NULL, - 'id' => strtr($item['title'], array( + 'id' => strtr($item['title'], [ '(' => '_', ')' => '', ' ' => '', ',' => '_', '/' => '_', - )), + ]), 'url' => CRM_Utils_System::url($path, $query, FALSE, NULL, @@ -375,7 +371,7 @@ class CRM_Core_Menu { ), 'icon' => $item['icon'] ?? NULL, 'extra' => $item['extra'] ?? NULL, - ); + ]; if (!array_key_exists($item['adminGroup'], $values)) { $values[$item['adminGroup']] = []; $values[$item['adminGroup']]['fields'] = []; @@ -388,25 +384,17 @@ class CRM_Core_Menu { ksort($values[$group]); } - $menu['admin'] = array('breadcrumb' => $values); + $menu['admin'] = ['breadcrumb' => $values]; } /** * Get admin links. * - * @return null + * @return array|null */ - public static function &getAdminLinks() { + public static function getAdminLinks() { $links = self::get('admin'); - - if (!$links || - !isset($links['breadcrumb']) - ) { - return NULL; - } - - $values = &$links['breadcrumb']; - return $values; + return $links['breadcrumb'] ?? NULL; } /** @@ -441,7 +429,7 @@ class CRM_Core_Menu { isset($menu[$currentPath]['title']) ) { $urlVar = !empty($menu[$currentPath]['path_arguments']) ? '&' . $menu[$currentPath]['path_arguments'] : ''; - $crumbs[] = array( + $crumbs[] = [ 'title' => $menu[$currentPath]['title'], 'url' => CRM_Utils_System::url($currentPath, 'reset=1' . $urlVar, @@ -456,7 +444,7 @@ class CRM_Core_Menu { // forceBackend; CRM-14439 work-around; acceptable for now because we don't display breadcrumbs on frontend TRUE ), - ); + ]; } } $menu[$path]['breadcrumb'] = $crumbs; @@ -486,21 +474,17 @@ class CRM_Core_Menu { array_pop($pathElements); if (empty($pathElements)) { - return array(NULL, NULL); + return [NULL, NULL]; } $newPath = implode('/', $pathElements); return self::getReturnUrl($menu, $newPath); } else { - return array( - CRM_Utils_Array::value('return_url', - $menu[$path] - ), - CRM_Utils_Array::value('return_url_args', - $menu[$path] - ), - ); + return [ + $menu[$path]['return_url'] ?? NULL, + $menu[$path]['return_url_args'] ?? NULL, + ]; } } @@ -551,9 +535,6 @@ class CRM_Core_Menu { * Menu entry array. */ public static function get($path) { - // return null if menu rebuild - $config = CRM_Core_Config::singleton(); - $args = explode('/', $path); $elements = []; @@ -622,20 +603,10 @@ UNION ( } } - // *FIXME* : hack for 4.1 -> 4.2 upgrades. if (preg_match('/^civicrm\/(upgrade\/)?queue\//', $path)) { CRM_Queue_Menu::alter($path, $menuPath); } - // Part of upgrade framework but not run inside main upgrade because it deletes data - // Once we have another example of a 'cleanup' we should generalize the clause below so it grabs string - // which follows upgrade/ and checks for existence of a function in Cleanup class. - if ($path == 'civicrm/upgrade/cleanup425') { - $menuPath['page_callback'] = array('CRM_Upgrade_Page_Cleanup', 'cleanup425'); - $menuPath['access_arguments'][0][] = 'administer CiviCRM'; - $menuPath['access_callback'] = array('CRM_Core_Permission', 'checkMenu'); - } - if (!empty($menuPath)) { $i18n = CRM_Core_I18n::singleton(); $i18n->localizeTitles($menuPath); @@ -652,7 +623,7 @@ UNION ( if (!is_string($pathArgs)) { return; } - $args = []; + $arr = []; $elements = explode(',', $pathArgs); foreach ($elements as $keyVal) { diff --git a/CRM/Upgrade/Page/Cleanup.php b/CRM/Upgrade/Page/Cleanup.php deleted file mode 100644 index ece1c2aa14..0000000000 --- a/CRM/Upgrade/Page/Cleanup.php +++ /dev/null @@ -1,49 +0,0 @@ -assign('columnHeaders', $columnHeaders); - $template->assign('rows', $rows); - - $preMessage = !empty($rows) ? ts('The following records have been processed. Membership records with action = Un-linked have been disconnected from the listed contribution record:') : ts('Could not find any records to process.'); - $template->assign('preMessage', $preMessage); - - $postMessage = ts('You can click here to try running the 4.2 upgrade script again. (Review upgrade documentation)', - [ - 1 => CRM_Utils_System::url('civicrm/upgrade', 'reset=1'), - 2 => CRM_Utils_System::docURL2('sysadmin/upgrade', TRUE), - ]); - $template->assign('postMessage', $postMessage); - - $content = $template->fetch('CRM/common/upgradeCleanup.tpl'); - echo CRM_Utils_System::theme($content, FALSE, TRUE); - } - -} -- 2.25.1