[Pkg-owncloud-commits] [owncloud] 30/46: Refer to relative path instead of absolute path

David Prévot taffit at moszumanska.debian.org
Fri Oct 24 15:11:43 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository owncloud.

commit ff93c5859bd1c1fa77c432726e7536ec22a038ad
Author: Lukas Reschke <lukas at owncloud.com>
Date:   Mon Oct 20 12:37:32 2014 +0200

    Refer to relative path instead of absolute path
    
    There is no need to refer to the absolute path here if we can use the relative one.
    
    Conflicts:
    	lib/private/templatelayout.php
    
    Conflicts:
    	lib/private/templatelayout.php
---
 lib/private/templatelayout.php | 30 +++++++++++++++++++++---------
 1 file changed, 21 insertions(+), 9 deletions(-)

diff --git a/lib/private/templatelayout.php b/lib/private/templatelayout.php
index 56ccbd1..1f2f3eb 100644
--- a/lib/private/templatelayout.php
+++ b/lib/private/templatelayout.php
@@ -140,7 +140,7 @@ class OC_TemplateLayout extends OC_Template {
 	public function generateAssets()
 	{
 		$jsFiles = self::findJavascriptFiles(OC_Util::$scripts);
-		$jsHash = self::hashScriptNames($jsFiles);
+		$jsHash = self::hashFileNames($jsFiles);
 
 		if (!file_exists("assets/$jsHash.js")) {
 			$jsFiles = array_map(function ($item) {
@@ -156,7 +156,7 @@ class OC_TemplateLayout extends OC_Template {
 		}
 
 		$cssFiles = self::findStylesheetFiles(OC_Util::$styles);
-		$cssHash = self::hashScriptNames($cssFiles);
+		$cssHash = self::hashFileNames($cssFiles);
 
 		if (!file_exists("assets/$cssHash.css")) {
 			$cssFiles = array_map(function ($item) {
@@ -187,16 +187,28 @@ class OC_TemplateLayout extends OC_Template {
 	}
 
 	/**
+	 * Converts the absolute filepath to a relative path from \OC::$SERVERROOT
+	 * @param string $filePath Absolute path
+	 * @return string Relative path
+	 * @throws Exception If $filePath is not under \OC::$SERVERROOT
+	 */
+	public static function convertToRelativePath($filePath) {
+		$relativePath = explode(\OC::$SERVERROOT, $filePath);
+		if(count($relativePath) !== 2) {
+			throw new \Exception('$filePath is not under the \OC::$SERVERROOT');
+		}
+
+		return $relativePath[1];
+	}
+
+	/**
 	 * @param array $files
 	 * @return string
 	 */
-	private static function hashScriptNames($files)
-	{
-		$files = array_map(function ($item) {
-			$root = $item[0];
-			$file = $item[2];
-			return $root . '/' . $file;
-		}, $files);
+	private static function hashFileNames($files) {
+		foreach($files as $i => $file) {
+			$files[$i] = self::convertToRelativePath($file[0]).'/'.$file[2];
+		}
 
 		sort($files);
 		// include the apps' versions hash to invalidate the cached assets

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list