@@ -131,7 +131,7 @@ public function __construct( $renderAs, $appId = '' ) {
131131 if (empty (self ::$ versionHash )) {
132132 $ v = \OC_App::getAppVersions ();
133133 $ v ['core ' ] = implode ('. ' , \OCP \Util::getVersion ());
134- self ::$ versionHash = md5 (implode (', ' , $ v ));
134+ self ::$ versionHash = substr ( md5 (implode (', ' , $ v )), 0 , 8 );
135135 }
136136 } else {
137137 self ::$ versionHash = md5 ('not installed ' );
@@ -194,16 +194,40 @@ public function __construct( $renderAs, $appId = '' ) {
194194 if (substr ($ file , -strlen ('print.css ' )) === 'print.css ' ) {
195195 $ this ->append ( 'printcssfiles ' , $ web .'/ ' .$ file . $ this ->getVersionHashSuffix () );
196196 } else {
197- $ this ->append ( 'cssfiles ' , $ web .'/ ' .$ file . $ this ->getVersionHashSuffix () );
197+ $ this ->append ( 'cssfiles ' , $ web .'/ ' .$ file . $ this ->getVersionHashSuffix ($ web , $ file ) );
198198 }
199199 }
200200 }
201201
202- protected function getVersionHashSuffix () {
203- if (\OC ::$ server ->getConfig ()->getSystemValue ('debug ' , false )) {
202+ /**
203+ * @param string $path
204+ * @param string $file
205+ * @return string
206+ */
207+ protected function getVersionHashSuffix ($ path = false , $ file = false ) {
208+ if (\OC ::$ server ->getConfig ()->getSystemValue ('debug ' , false )) {
204209 // allows chrome workspace mapping in debug mode
205210 return "" ;
206211 }
212+ $ v = \OC_App::getAppVersions ();
213+
214+ // Try the webroot path for a match
215+ if ($ path !== false && $ path !== '' ) {
216+ $ appName = $ this ->getAppNamefromPath ($ path );
217+ if (array_key_exists ($ appName , $ v )) {
218+ $ appVersion = $ v [$ appName ];
219+ return '?v= ' . substr (md5 ($ appVersion ), 0 , 8 ) . '- ' . $ this ->config ->getAppValue ('theming ' , 'cachebuster ' , '0 ' );
220+ }
221+ }
222+ // fallback to the file path instead
223+ if ($ file !== false && $ file !== '' ) {
224+ $ appName = $ this ->getAppNamefromPath ($ file );
225+ if (array_key_exists ($ appName , $ v )) {
226+ $ appVersion = $ v [$ appName ];
227+ return '?v= ' . substr (md5 ($ appVersion ), 0 , 8 ) . '- ' . $ this ->config ->getAppValue ('theming ' , 'cachebuster ' , '0 ' );
228+ }
229+ }
230+
207231 if ($ this ->config ->getSystemValue ('installed ' , false ) && \OC ::$ server ->getAppManager ()->isInstalled ('theming ' )) {
208232 return '?v= ' . self ::$ versionHash . '- ' . $ this ->config ->getAppValue ('theming ' , 'cachebuster ' , '0 ' );
209233 }
@@ -235,6 +259,23 @@ static public function findStylesheetFiles($styles, $compileScss = true) {
235259 return $ locator ->getResources ();
236260 }
237261
262+ /**
263+ * @param string $path
264+ * @return string|boolean
265+ */
266+ public function getAppNamefromPath ($ path ) {
267+ if ($ path !== '' && is_string ($ path )) {
268+ $ pathParts = explode ('/ ' , $ path );
269+ if ($ pathParts [0 ] === 'css ' ) {
270+ // This is a scss request
271+ return $ pathParts [1 ];
272+ }
273+ return end ($ pathParts );
274+ }
275+ return false ;
276+
277+ }
278+
238279 /**
239280 * @param array $scripts
240281 * @return array
0 commit comments