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-25 12:42:30 -04:00
parent e81ef4e327
commit 8ef92c1a8b
8 changed files with 86 additions and 39 deletions

View File

@@ -4899,6 +4899,28 @@ class G
{
$arrayLibrary = array();
//Translations /js/ext/translation.en.js
$arrayLibrary["translation"] = ""; //Not use null
//Translation environment /jscore/labels/en.js
$translationEnvFilePath = PATH_DATA . "META-INF" . PATH_SEP . "translations.env";
if (file_exists($translationEnvFilePath)) {
$arrayData = unserialize(file_get_contents($translationEnvFilePath));
$path = PATH_CORE . "js" . PATH_SEP . "labels" . PATH_SEP;
foreach ($arrayData as $index1 => $value1) {
foreach ($value1 as $index2 => $value2) {
$record = $value2;
if (file_exists($path . $record["LOCALE"] . ".js")) {
$arrayLibrary[$record["LOCALE"]] = $path;
}
}
}
}
//Libraries
$library = G::json_decode(file_get_contents(PATH_HOME . "engine" . PATH_SEP . "bin" . PATH_SEP . "tasks" . PATH_SEP . "libraries.json"));
foreach ($library as $index => $value) {
@@ -4933,13 +4955,17 @@ class G
$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
if (!empty($path)) {
foreach (glob($path . $name . "*") as $file) {
if (preg_match("/^\.\w{32}\.js$/i", str_replace($path . $name, null, $file))) {
@unlink($file); //Delete old file
}
}
if (file_exists($path . $name . ".js")) {
@copy($path . $name . ".js", $path . $name . "." . $uid . ".js"); //Create new file
}
}
@copy($path . $name . ".js", $path . $name . "." . $uid . ".js"); //Create new file
}
}
@@ -4959,15 +4985,28 @@ class G
$n = count($arrayAux);
if ($n > 0 && !empty($arrayAux[$n - 1])) {
$name = $arrayAux[$n - 1];
$arrayAux = explode("?", $arrayAux[$n - 1]);
$name = $arrayAux[0];
if (preg_match("/^(.*)\.js$/i", $name, $arrayMatch)) {
$index = $arrayMatch[1];
$index = (preg_match("/^translation\..*$/", $index))? "translation" : $index;
$arrayLibrary = G::browserCacheFilesGetLibraryJs();
if (isset($arrayLibrary[$arrayMatch[1]])) {
$path = $arrayLibrary[$arrayMatch[1]];
if (isset($arrayLibrary[$index])) {
$path = $arrayLibrary[$index];
$sw = 0;
if (file_exists($path . $arrayMatch[1] . "." . $browserCacheFilesUid . ".js")) {
if (!empty($path)) {
if (file_exists($path . $arrayMatch[1] . "." . $browserCacheFilesUid . ".js")) {
$sw = 1;
}
} else {
$sw = 1;
}
if ($sw == 1) {
$url = str_replace($name, $arrayMatch[1] . "." . $browserCacheFilesUid . ".js", $url);
}
}