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
This commit is contained in:
Victor Saisa Lopez
2013-04-16 17:11:25 -04:00
parent c79fcd0d2d
commit c1bf46c80a
8 changed files with 82 additions and 37 deletions

View File

@@ -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";}

View File

@@ -18,7 +18,7 @@ var maborak = function(forceCssLoad){
this.info={
version: "0.3",
name: "maborak",
file :"maborak.js"
file: "maborak" + ((BROWSER_CACHE_FILES_UID != "")? "." + BROWSER_CACHE_FILES_UID : "") + ".js"
},
this.forceCssLoad = forceCssLoad ? true : false;
@@ -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();

View File

@@ -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);
}
}
}
}
}

View File

@@ -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 .= '<TITLE>' . $this->title . "</TITLE>\n";
$browserCacheFilesUid = G::browserCacheFilesGetUid();
$head = $head . "
<script type=\"text/javascript\">
var BROWSER_CACHE_FILES_UID = \"" . (($browserCacheFilesUid != null && file_exists(PATH_TRUNK . "gulliver" . PATH_SEP . "js" . PATH_SEP . "maborak" . PATH_SEP . "core" . PATH_SEP . "maborak.$browserCacheFilesUid.js"))? $browserCacheFilesUid : null) . "\";
</script>
";
foreach ($this->scriptFiles as $file) {
$head .= "<script type='text/javascript' src='" . $file . "'></script>\n";
$head = $head . "<script type=\"text/javascript\" src=\"" . G::browserCacheFilesUrl($file) . "\"></script>\n";
}
if (!in_array($this->translationsFile, $this->scriptFiles)) {
@@ -232,7 +238,7 @@ class headPublisher
$head .= $this->headerScript;
$head .= "</script>\n";
$head .= "<script type=\"text/javascript\" src=\"" . G::browserCacheFilesSetUrl("/js/maborak/core/maborak.loader.js") . "\"></script>\n";
$head .= "<script type=\"text/javascript\" src=\"" . G::browserCacheFilesUrl("/js/maborak/core/maborak.loader.js") . "\"></script>\n";
return $head;
}
@@ -260,7 +266,7 @@ class headPublisher
//$head .= "<script language='javascript'>\n";
foreach ($this->scriptFiles as $file) {
if (($file != "/js/maborak/core/maborak.js") && ($file != $jslabel)) {
$head .= " eval(ajax_function('" . $file . "','',''));\n";
$head = $head . " eval(ajax_function(\"" . G::browserCacheFilesUrl($file) . "\", \"\", \"\"));\n";
}
}
foreach ($this->leimnudLoad as $file) {

View File

@@ -140,7 +140,7 @@ try {
$browserCacheFilesUid = G::browserCacheFilesGetUid();
$template->assign("BROWSER_CACHE_FILES_UID", ($browserCacheFilesUid != null)? "?c=" . $browserCacheFilesUid : null);
$template->assign("URL_MABORAK_JS", G::browserCacheFilesUrl("/js/maborak/core/maborak.js"));
$template->assign("siteUrl", $http . $_SERVER["HTTP_HOST"]);
$template->assign("sysSys", SYS_SYS);
$template->assign("sysLang", SYS_LANG);

View File

@@ -30,9 +30,7 @@ $oTemplatePower->assign('USR_UID', $aUser['USR_UID']);
$oTemplatePower->assign('USR_FULLNAME', $aData['USR_FIRSTNAME'] . ' ' . $aData['USR_LASTNAME'] . ' (' . $aData['USR_USERNAME'] . ')');
*/
$browserCacheFilesUid = G::browserCacheFilesGetUid();
$oTemplatePower->assign("BROWSER_CACHE_FILES_UID", ($browserCacheFilesUid != null)? "?c=" . $browserCacheFilesUid : null);
$oTemplatePower->assign("URL_MABORAK_JS", G::browserCacheFilesUrl("/js/maborak/core/maborak.js"));
$G_PUBLISH->AddContent( 'template', '', '', '', $oTemplatePower );

View File

@@ -1,7 +1,7 @@
<html>
<head>
<script type="text/javascript" src="{siteUrl}/jscore/labels/{sysLang}.js"></script>
<script type="text/javascript" src="{siteUrl}/js/maborak/core/maborak.js{BROWSER_CACHE_FILES_UID}"></script>
<script type="text/javascript" src="{siteUrl}{URL_MABORAK_JS}"></script>
<script type="text/javascript" src="{siteUrl}/js/jscalendar/lang/calendar-{sysLang}.js"></script>
<script type="text/javascript" src="{siteUrl}/jsform/gulliver/dynaforms_Options.js"></script>

View File

@@ -1,6 +1,6 @@
<html>
<head>
<script type="text/javascript" src="/js/maborak/core/maborak.js{BROWSER_CACHE_FILES_UID}"></script>
<script type="text/javascript" src="{URL_MABORAK_JS}"></script>
<script type="text/javascript">
var leimnud = new maborak();