From c1bf46c80a7a2726b78515a346b1dd3a64221683 Mon Sep 17 00:00:00 2001 From: Victor Saisa Lopez Date: Tue, 16 Apr 2013 17:11:25 -0400 Subject: [PATCH] BUG 0000 "Safe upgrade for JavaScript files" SOLVED - New feature - Safe upgrade for JavaScript files - Added new feature, - This new feature is activated when you run one of the following commands: $ ./processmaker upgrade $ ./processmaker build-js $ ./processmaker browser-cache-files-upgrade - The new feature creates an attribute in the file "processmaker/workflow/engine/config/env.ini" Example: browser_cache_files_uid = "xxxxxxxxxxyyyyyyyyyyzzzzzzzzzzaa" - After running the command, the browser should automatically cache the new files * Available from version ProcessMaker-2.5 --- gulliver/js/maborak/core/maborak.js | 7 +- gulliver/js/maborak/core/maborak.old.js | 14 ++-- gulliver/system/class.g.php | 72 ++++++++++++++----- gulliver/system/class.headPublisher.php | 16 +++-- .../processes/processes_webEntryGenerate.php | 2 +- .../methods/services/login_getStarted.php | 4 +- .../engine/templates/processes/webentry.tpl | 2 +- .../templates/services/login_getStarted.html | 2 +- 8 files changed, 82 insertions(+), 37 deletions(-) diff --git a/gulliver/js/maborak/core/maborak.js b/gulliver/js/maborak/core/maborak.js index 2308e45ba..28413630d 100644 --- a/gulliver/js/maborak/core/maborak.js +++ b/gulliver/js/maborak/core/maborak.js @@ -1,5 +1,5 @@ -var maborak=function(forceCssLoad){this.info={version:"0.3",name:"maborak",file:"maborak.js"},this.forceCssLoad=forceCssLoad?true:false;this.make=function(options) +var maborak=function(forceCssLoad){this.info={version:"0.3",name:"maborak",file:"maborak"+((BROWSER_CACHE_FILES_UID!="")?"."+BROWSER_CACHE_FILES_UID:"")+".js"},this.forceCssLoad=forceCssLoad?true:false;this.make=function(options) {this.protoCore();this.module={debug:function(flag){this.flag=flag||false;this.log=function(v) {if(typeof console!='undefined'&&this.flag===true) {console.log(v||'');}};return this;}}.expand(this);this.options={thisIsNotPM:false}.concat(options||{});this.report=new this.bitacora();this.loadMethods([this.checkBrowser],this);this.event=this.factory(this.mantis,true);this.tools=this.factory(this.extended.tools,true);this.file=this.factory(this.fileCore,true);this.dom=this.factory(this.extended.D0M,true);this.iphone=this.factory(this.iphoneBrowser,true);this.cookie=this.factory(this.extended.cookie,true);this.Package=new this.PackageCore(this,this.file.db);this.report.add("Class loaded.");this.info.base=this.tools.baseJS(this.info.file);this.info.images=this.info.base+"images/";this.path_root=this.tools.path_root(this.info.base)+"/";if(this.options.modules){this.Package.Load(this.options.modules,{Instance:this,Type:"module"});} @@ -183,11 +183,10 @@ return rf;};};this.PackageCore=function(parent,db) {this.options={zip:false}.concat(options||{});if(arguments.length<2||!this.check()){return false;} this.toLoad=((this.options.Absolute===true)?this.options.Path:file).split(",");if(this.type==='module'&&(this.options.zip===true||this.parent.options.zip===true)) {var tl=[];for(var i=this.toLoad.length;i>0;i--) -{this.name=this.toLoad[this.toLoad.length-i];if(!this.isset()){tl.push(this.name);this.write(false);}} -if(tl.length>0){var script=$dce("script");this.parent.dom.capture("tag.head 0").appendChild(script);script.src=(this.parent.options.inGulliver===true)?this.path+'maborak.loader.js':this.path+'server/maborak.loader.php?load='+tl.join(',');script.type="text/javascript";script.charset=this.parent.charset;if(this.type=="module"){this.write(script);}}} +{this.name=this.toLoad[this.toLoad.length-i];if(!this.isset()){tl.push(this.name);this.write(false);}}} else {for(var i=this.toLoad.length;i>0;i--) -{this.name=this.toLoad[this.toLoad.length-i];if(!this.isset()){this.src=this.source();var script=$dce("script");this.parent.dom.capture("tag.head 0").appendChild(script);script.src=this.src;script.type="text/javascript";script.charset=this.parent.charset;if(this.type=="module"){this.write(script);}}}} +{this.name=this.toLoad[this.toLoad.length-i];if(!this.isset()){this.src=stringReplace("maborak\\.loader\\.js","maborak.loader"+((BROWSER_CACHE_FILES_UID!="")?"."+BROWSER_CACHE_FILES_UID:"")+".js",this.source());var script=$dce("script");this.parent.dom.capture("tag.head 0").appendChild(script);script.src=this.src;script.type="text/javascript";script.charset=this.parent.charset;if(this.type=="module"){this.write(script);}}}} delete this.Class;delete this.file;delete this.info;delete this.path;delete this.toLoad;delete this.type;delete this.src;return true;};this.source=function() {if(this.type=="module") {return this.path+"module."+this.name+".js";} diff --git a/gulliver/js/maborak/core/maborak.old.js b/gulliver/js/maborak/core/maborak.old.js index 9b2734829..091c43a9f 100755 --- a/gulliver/js/maborak/core/maborak.old.js +++ b/gulliver/js/maborak/core/maborak.old.js @@ -16,9 +16,9 @@ ***************************************************************************/ var maborak = function(forceCssLoad){ this.info={ - version :"0.3", - name :"maborak", - file :"maborak.js" + version: "0.3", + name: "maborak", + file: "maborak" + ((BROWSER_CACHE_FILES_UID != "")? "." + BROWSER_CACHE_FILES_UID : "") + ".js" }, this.forceCssLoad = forceCssLoad ? true : false; @@ -743,7 +743,7 @@ var maborak = function(forceCssLoad){ { return this.replace(new RegExp(tagScript, 'img'), ''); }; - + /** * Return first letters as uppercase, rest lower. */ @@ -753,7 +753,7 @@ var maborak = function(forceCssLoad){ return $1.toUpperCase(); }); }; - + /** * XMLSerializer Crossbrowser */ @@ -1140,6 +1140,7 @@ var maborak = function(forceCssLoad){ } } //alert(this.parent.options.thisIsNotPM); + /* if (tl.length > 0) { var script = $dce("script"); this.parent.dom.capture("tag.head 0").appendChild(script); @@ -1152,6 +1153,7 @@ var maborak = function(forceCssLoad){ this.write(script); } } + */ } else { @@ -1161,7 +1163,7 @@ var maborak = function(forceCssLoad){ if (!this.isset()) { //if (this.options.noWrite === false && this.type!='module') //{ - this.src = this.source(); + this.src = stringReplace("maborak\\.loader\\.js", "maborak.loader" + ((BROWSER_CACHE_FILES_UID != "")? "." + BROWSER_CACHE_FILES_UID : "") + ".js", this.source()); var script = $dce("script"); this.parent.dom.capture("tag.head 0").appendChild(script); //script.src = this.src+"?d="+Math.random(); diff --git a/gulliver/system/class.g.php b/gulliver/system/class.g.php index 6342e1314..2269acf83 100644 --- a/gulliver/system/class.g.php +++ b/gulliver/system/class.g.php @@ -4898,12 +4898,52 @@ class G } } + public static function browserCacheFilesGetLibraryJs() + { + $arrayLibrary = array(); + + $library = json_decode(file_get_contents(PATH_HOME . "engine" . PATH_SEP . "bin" . PATH_SEP . "tasks" . PATH_SEP . "libraries.json")); + + foreach ($library as $index => $value) { + $lib = $value; + + if ($lib->build) { + if (substr($lib->build_js_to, -1) != "/") { + $lib->build_js_to = $lib->build_js_to . "/"; + } + + $arrayLibrary[$lib->name] = PATH_TRUNK . $lib->build_js_to; + } + } + + return $arrayLibrary; + } + public static function browserCacheFilesSetUid() { + //Set UID + $uid = G::generateUniqueID(); + $arrayData = array(); - $arrayData["browser_cache_files_uid"] = G::generateUniqueID(); + $arrayData["browser_cache_files_uid"] = $uid; G::update_php_ini(PATH_CONFIG . "env.ini", $arrayData); + + //Set file JavaScript + $arrayLibrary = G::browserCacheFilesGetLibraryJs(); + + foreach ($arrayLibrary as $index => $value) { + $name = $index; + $path = $value; + + foreach (glob($path . $name . "*") as $file) { + if (preg_match("/^\.\w{32}\.js$/i", str_replace($path . $name, null, $file))) { + @unlink($file); //Delete old file + } + } + + @copy($path . $name . ".js", $path . $name . "." . $uid . ".js"); //Create new file + } } public static function browserCacheFilesGetUid() @@ -4913,28 +4953,28 @@ class G return (isset($sysConf["browser_cache_files_uid"]))? $sysConf["browser_cache_files_uid"] : null; } - public static function browserCacheFilesSetUrl($url) + public static function browserCacheFilesUrl($url) { $browserCacheFilesUid = self::browserCacheFilesGetUid(); if ($browserCacheFilesUid != null) { - $arrayLibrary = array(); - - $library = json_decode(file_get_contents(PATH_HOME . "engine" . PATH_SEP . "bin" . PATH_SEP . "tasks" . PATH_SEP . "libraries.json")); - - foreach ($library as $index => $value) { - $lib = $value; - - if ($lib->build) { - $arrayLibrary[] = $lib->name . ".js"; - } - } - $arrayAux = explode("/", $url); $n = count($arrayAux); - if ($n > 0 && !empty($arrayAux[$n - 1]) && array_search($arrayAux[$n - 1], $arrayLibrary) !== false) { - $url = $url . ((strpos($arrayAux[$n - 1], "?") !== false)? "&c=" : "?c=") . $browserCacheFilesUid; + if ($n > 0 && !empty($arrayAux[$n - 1])) { + $name = $arrayAux[$n - 1]; + + if (preg_match("/^(.*)\.js$/i", $name, $arrayMatch)) { + $arrayLibrary = G::browserCacheFilesGetLibraryJs(); + + if (isset($arrayLibrary[$arrayMatch[1]])) { + $path = $arrayLibrary[$arrayMatch[1]]; + + if (file_exists($path . $arrayMatch[1] . "." . $browserCacheFilesUid . ".js")) { + $url = str_replace($name, $arrayMatch[1] . "." . $browserCacheFilesUid . ".js", $url); + } + } + } } } diff --git a/gulliver/system/class.headPublisher.php b/gulliver/system/class.headPublisher.php index 4f2dc8f8c..a9ed5a214 100644 --- a/gulliver/system/class.headPublisher.php +++ b/gulliver/system/class.headPublisher.php @@ -125,8 +125,6 @@ class headPublisher */ public function addScriptFile($url, $LoadType = 1) { - $url = G::browserCacheFilesSetUrl($url); - if ($LoadType == 1) { $this->scriptFiles[$url] = $url; } @@ -215,8 +213,16 @@ class headPublisher $head = ''; $head .= '' . $this->title . "\n"; + $browserCacheFilesUid = G::browserCacheFilesGetUid(); + + $head = $head . " + + "; + foreach ($this->scriptFiles as $file) { - $head .= "\n"; + $head = $head . "\n"; } if (!in_array($this->translationsFile, $this->scriptFiles)) { @@ -232,7 +238,7 @@ class headPublisher $head .= $this->headerScript; $head .= "\n"; - $head .= "\n"; + $head .= "\n"; return $head; } @@ -260,7 +266,7 @@ class headPublisher //$head .= " - + diff --git a/workflow/engine/templates/services/login_getStarted.html b/workflow/engine/templates/services/login_getStarted.html index ec491a456..cafe3bb4d 100755 --- a/workflow/engine/templates/services/login_getStarted.html +++ b/workflow/engine/templates/services/login_getStarted.html @@ -1,6 +1,6 @@ - +