From f704f30497b7566ff752427e576c3b0f714457b9 Mon Sep 17 00:00:00 2001 From: Julio Cesar Laura Date: Thu, 16 Aug 2012 18:31:10 -0400 Subject: [PATCH] BUG 9594 Have no cache for JavaScript SOLVED - The js file for the dynaforms always use the same name, then when the browser loads the page use the same js file - Now the cache js files are generated with different names, according to the modify date of the xmlform --- gulliver/system/class.xmlform.php | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/gulliver/system/class.xmlform.php b/gulliver/system/class.xmlform.php index e30e58362..54b7678c4 100755 --- a/gulliver/system/class.xmlform.php +++ b/gulliver/system/class.xmlform.php @@ -4345,11 +4345,14 @@ class XmlForm $parsedFilePath = defined ( 'PATH_C' ) ? ( defined('SYS_SYS') ? PATH_C . 'ws' . PATH_SEP . SYS_SYS . PATH_SEP: PATH_C ) : PATH_DATA; $parsedFilePath .= 'xmlform/' . substr ( $parsedFile, strlen ( $this->home ) ); + // Improvement for the js cache - Start + $realPath = substr(realpath($this->fileName), strlen(realpath($this->home)), - 4); + $filesToDelete = substr((defined('PATH_C') ? PATH_C : PATH_DATA) . 'xmlform/', 0, - 1) . $realPath . '.*.js'; + $auxPath = explode(PATH_SEP, $realPath); + $auxPath[count($auxPath) - 1] = $auxPath[count($auxPath) - 1] . '.' . md5(filemtime($this->fileName)); + $realPath = implode(PATH_SEP, $auxPath); + // Improvement for the js cache - End $this->parsedFile = $parsedFilePath; - //Note that scriptFile must be public URL. - $realPath = substr ( realpath ( $this->fileName ), strlen ( realpath ( $this->home ) ), - 4 ); - if (substr ( $realPath, 0, 1 ) != PATH_SEP) - $realPath = PATH_SEP . $realPath; $this->scriptURL = '/jsform' . $realPath . '.js'; $this->scriptFile = substr ( (defined ( 'PATH_C' ) ? PATH_C : PATH_DATA) . 'xmlform/', 0, - 1 ) . substr ( $this->scriptURL, 7 ); $this->id = G::createUID ( '', substr ( $this->fileName, strlen ( $this->home ) ) ); @@ -4357,6 +4360,9 @@ class XmlForm $newVersion = false; if ($forceParse || ((! file_exists ( $this->parsedFile )) || (filemtime ( $filename ) > filemtime ( $this->parsedFile )) || (filemtime ( __FILE__ ) > filemtime ( $this->parsedFile ))) || (! file_exists ( $this->scriptFile )) || (filemtime ( $filename ) > filemtime ( $this->scriptFile ))) { + foreach (glob($filesToDelete) as $fileToDelete) { + @unlink($fileToDelete); + } $this->tree = new Xml_Document ( ); $this->tree->parseXmlFile ( $filename ); //$this->tree->unsetParent();