From 1ad9203f0186fb96b1a1149c49f0deb5c6e1a35e Mon Sep 17 00:00:00 2001
From: mattab <matthieu.aubry@gmail.com>
Date: Mon, 15 Jul 2013 17:07:15 +1200
Subject: [PATCH] Making Plugin enable/disable work for a theme

---
 core/AssetManager.php   | 20 ++++++++++++++------
 core/PluginsManager.php |  2 --
 core/View.php           |  2 +-
 3 files changed, 15 insertions(+), 9 deletions(-)

diff --git a/core/AssetManager.php b/core/AssetManager.php
index 518d3110a1..a87db2a3f0 100644
--- a/core/AssetManager.php
+++ b/core/AssetManager.php
@@ -52,11 +52,6 @@ class Piwik_AssetManager
      */
     public static function getCssAssets()
     {
-        if (self::getDisableMergedAssets()) {
-            // Individual includes mode
-            self::removeMergedAsset(self::MERGED_CSS_FILE);
-            self::generateMergedCssFile();
-        }
         return sprintf(self::CSS_IMPORT_DIRECTIVE, self::GET_CSS_MODULE_ACTION);
     }
 
@@ -75,6 +70,19 @@ class Piwik_AssetManager
         return sprintf(self::JS_IMPORT_DIRECTIVE, self::GET_JS_MODULE_ACTION);
     }
 
+    /**
+     * Assets are cached in the browser and Piwik server returns 304 after initial download.
+     * when the Cache buster string changes, the assets will be re-generated
+     *
+     * @return string
+     */
+    public static function generateAssetsCacheBuster()
+    {
+        $pluginList = md5(implode(",", Piwik_PluginsManager::getInstance()->getLoadedPluginsName()));
+        $cacheBuster = md5(Piwik_Common::getSalt() . $pluginList . PHP_VERSION . Piwik_Version::VERSION);
+        return $cacheBuster;
+    }
+
     /**
      * Generate the merged css file.
      *
@@ -92,7 +100,7 @@ class Piwik_AssetManager
         $rootDirectoryLen = strlen($rootDirectory);
 
         if(!class_exists("lessc")) {
-            throw new Exception("Less was added to composer during 2.0. ==> Excecute this command to update composer packages: \$ php composer.phar update");
+            throw new Exception("Less was added to composer during 2.0. ==> Execute this command to update composer packages: \$ php composer.phar update");
         }
         $less = new lessc;
 
diff --git a/core/PluginsManager.php b/core/PluginsManager.php
index c09988452f..ab341e5654 100644
--- a/core/PluginsManager.php
+++ b/core/PluginsManager.php
@@ -188,7 +188,6 @@ class Piwik_PluginsManager
             }
         }
 
-        // Delete merged js/css files to force regenerations to exclude the deactivated plugin
         Piwik_Config::getInstance()->forceSave();
         Piwik::deleteAllCacheOnUpdate();
     }
@@ -248,7 +247,6 @@ class Piwik_PluginsManager
         $this->updatePluginsConfig($plugins);
         Piwik_Config::getInstance()->forceSave();
 
-        // Delete merged js/css files to force regenerations to include the activated plugin
         Piwik::deleteAllCacheOnUpdate();
     }
 
diff --git a/core/View.php b/core/View.php
index 00d30ebc55..183b9601a7 100644
--- a/core/View.php
+++ b/core/View.php
@@ -143,7 +143,7 @@ class Piwik_View implements Piwik_View_Interface
 
     protected function applyFilter_cacheBuster($output)
     {
-        $cacheBuster = md5(Piwik_Common::getSalt() . PHP_VERSION . Piwik_Version::VERSION);
+        $cacheBuster = Piwik_AssetManager::generateAssetsCacheBuster();
         $tag = 'cb=' . $cacheBuster;
 
         $pattern = array(
-- 
GitLab