]> source.dussan.org Git - nextcloud-server.git/commitdiff
Add debug mode
authorRoeland Jago Douma <roeland@famdouma.nl>
Wed, 22 Mar 2017 14:42:17 +0000 (15:42 +0100)
committerRoeland Jago Douma <roeland@famdouma.nl>
Fri, 24 Mar 2017 09:58:11 +0000 (10:58 +0100)
Signed-off-by: Roeland Jago Douma <roeland@famdouma.nl>
lib/private/Template/JSCombiner.php
lib/private/Template/JSResourceLocator.php
lib/private/TemplateLayout.php

index f470ee330c7984e02853f16c8b545149df5e283c..a7bbf129e01d924ad59a09fae209b9cfe60b0fcd 100644 (file)
@@ -22,6 +22,7 @@
  */
 namespace OC\Template;
 
+use OC\SystemConfig;
 use OCP\ICache;
 use OCP\Files\IAppData;
 use OCP\Files\NotFoundException;
@@ -40,6 +41,9 @@ class JSCombiner {
        /** @var ICache */
        protected $depsCache;
 
+       /** @var SystemConfig */
+       protected $config;
+
        /**
         * JSCombiner constructor.
         *
@@ -49,10 +53,12 @@ class JSCombiner {
         */
        public function __construct(IAppData $appData,
                                                                IURLGenerator $urlGenerator,
-                                                               ICache $depsCache) {
+                                                               ICache $depsCache,
+                                                               SystemConfig $config) {
                $this->appData = $appData;
                $this->urlGenerator = $urlGenerator;
                $this->depsCache = $depsCache;
+               $this->config = $config;
        }
 
        /**
@@ -62,6 +68,10 @@ class JSCombiner {
         * @return bool
         */
        public function process($root, $file, $app) {
+               if ($this->config->getValue('debug')) {
+                       return false;
+               }
+
                $path = explode('/', $root . '/' . $file);
 
                $fileName = array_pop($path);
@@ -166,4 +176,24 @@ class JSCombiner {
 
                return substr($this->urlGenerator->linkToRoute('core.Js.getJs', array('fileName' => $fileName, 'appName' => $appName)), strlen(\OC::$WEBROOT) + 1);
        }
+
+       /**
+        * @param string $root
+        * @param string $file
+        * @return string[]
+        */
+       public function getContent($root, $file) {
+               $data = json_decode(file_get_contents($root . '/' . $file));
+
+               $path = explode('/', $file);
+               array_pop($path);
+               $path = implode('/', $path);
+
+               $result = [];
+               foreach ($data as $f) {
+                       $result[] = $path . '/' . $f;
+               }
+
+               return $result;
+       }
 }
index 6f863e859d9450f77e04f54f030744a8d1e14b31..41b44c143efb2739d641b7c9be7f0af847d321e1 100644 (file)
@@ -96,6 +96,14 @@ class JSResourceLocator extends ResourceLocator {
                        if ($this->jsCombiner->process($root, $file, $app)) {
                                $this->append($this->serverroot, $this->jsCombiner->getCachedJS($app, $file), false, false);
                                return true;
+                       } else {
+                               // Add all the files from the json
+                               $files = $this->jsCombiner->getContent($root, $file);
+                               $app_url = \OC_App::getAppWebPath($app);
+
+                               foreach ($files as $jsFile) {
+                                       $this->append($root, $jsFile, $app_url);
+                               }
                        }
                }
 
index d172da1184b4b10c551be3acc4236d11a5a901f5..956cba400864f1f15dbd8c20ec36c1c656050053 100644 (file)
@@ -254,7 +254,8 @@ class TemplateLayout extends \OC_Template {
                        new JSCombiner(
                                \OC::$server->getAppDataDir('js'),
                                \OC::$server->getURLGenerator(),
-                               \OC::$server->getMemCacheFactory()->create('JS')
+                               \OC::$server->getMemCacheFactory()->create('JS'),
+                               \OC::$server->getSystemConfig()
                        )
                        );
                $locator->find($scripts);