From 03449a5b0dd724877e6549cbcb01432127ba5131 Mon Sep 17 00:00:00 2001 From: mickadoo Date: Wed, 15 Mar 2017 09:36:26 +0000 Subject: [PATCH] CRM-20254: simplify adding cache code logic. remove useless test case --- CRM/Core/Resources.php | 19 +++---------------- tests/phpunit/CRM/Core/ResourcesTest.php | 4 ---- 2 files changed, 3 insertions(+), 20 deletions(-) diff --git a/CRM/Core/Resources.php b/CRM/Core/Resources.php index bccbefa845..f4bbb81d32 100644 --- a/CRM/Core/Resources.php +++ b/CRM/Core/Resources.php @@ -887,22 +887,9 @@ class CRM_Core_Resources { * @return string */ public function addCacheCode($url) { - parse_str(parse_url($url, PHP_URL_QUERY), $queryParts); - $existing = isset($queryParts['r']) ? $queryParts['r'] : NULL; - $latest = $this->cacheCode; + $hasQuery = strpos($url, '?') !== false; + $operator = $hasQuery ? '&' : '?'; - if ($existing) { - if ($existing === $latest) { - return $url; // no need to update - } - else { - return str_replace('r=' . $existing, 'r=' . $latest, $url); - } - } - - $operator = empty($queryParts) ? '?' : '&'; - - return $url . $operator . 'r=' . $latest; + return $url . $operator . 'r=' . $this->cacheCode; } - } diff --git a/tests/phpunit/CRM/Core/ResourcesTest.php b/tests/phpunit/CRM/Core/ResourcesTest.php index edc675b047..2977a9b289 100644 --- a/tests/phpunit/CRM/Core/ResourcesTest.php +++ b/tests/phpunit/CRM/Core/ResourcesTest.php @@ -378,10 +378,6 @@ class CRM_Core_ResourcesTest extends CiviUnitTestCase { 'www.civicrm.org/custom.css?foo=bar', 'www.civicrm.org/custom.css?foo=bar&r=' . $this->cacheBusterString, ), - array( - 'civicrm.org/custom.css?r=old&foo=bar', - 'civicrm.org/custom.css?r=' . $this->cacheBusterString . '&foo=bar', - ), array( 'civicrm.org/custom.css?car=blue&foo=bar', 'civicrm.org/custom.css?car=blue&foo=bar&r=' . $this->cacheBusterString, -- 2.25.1