This commit is contained in:
Julio Cesar Laura Avendaño
2019-03-18 13:36:08 -04:00
parent d4c81fe47f
commit b29170b87b
7 changed files with 268 additions and 547 deletions

View File

@@ -80,7 +80,6 @@ return array(
'ToolBar' => ToolBar::class,
'Tree' => PmTree::class,
'triggerLibrary' => TriggerLibrary::class,
'Upgrade' => Upgrade::class,
'workspaceTools' => WorkspaceTools::class,
'wsBase' => WsBase::class,
'wsResponse' => WsResponse::class,

File diff suppressed because it is too large Load Diff

View File

@@ -106,26 +106,6 @@ EOT
CLI::taskArg('workspace', true, true);
CLI::taskRun("run_plugins_database_upgrade");
CLI::taskName('workspace-upgrade');
CLI::taskDescription(<<<EOT
Upgrade the specified workspace(s).
If no workspace is specified, the command will be run in all workspaces. More
than one workspace can be specified.
This command is a shortcut to execute all the upgrade commands for workspaces.
Upgrading a workspace will make it correspond to the current version of
ProcessMaker.
Use this command to upgrade workspaces individually, otherwise use the
'processmaker upgrade' command to upgrade the entire system.
EOT
);
CLI::taskArg('workspace-name', true, true);
CLI::taskOpt('buildACV', 'If this option is enabled, the Cache View is built.', 'ACV', 'buildACV');
CLI::taskOpt('noxml', 'If this option is enabled, the XML files translation is not built.', 'NoXml', 'no-xml');
CLI::taskRun("run_workspace_upgrade");
CLI::taskName('translation-repair');
CLI::taskDescription(<<<EOT
Upgrade or repair translations for the specified workspace(s).
@@ -412,69 +392,6 @@ function run_info($args, $opts)
}
}
/**
* Check if we need to execute the workspace-upgrade
* If we apply the command for all workspaces, we will need to execute one by one by redefining the constants
*
* @param string $args, workspace name that we need to apply the database-upgrade
* @param string $opts, additional arguments
*
* @return void
*/
function run_workspace_upgrade($args, $opts)
{
//Read the additional parameters for this command
$parameters = '';
$parameters .= array_key_exists('buildACV', $opts) ? '--buildACV ' : '';
$parameters .= array_key_exists('noxml', $opts) ? '--no-xml ' : '';
$parameters .= array_key_exists("lang", $opts) ? 'lang=' . $opts['lang'] : 'lang=' . SYS_LANG;
//Check if the command is executed by a specific workspace
if (count($args) === 1) {
workspace_upgrade($args, $opts);
} else {
$workspaces = get_workspaces_from_args($args);
foreach ($workspaces as $workspace) {
passthru(PHP_BINARY . ' processmaker upgrade ' . $parameters . ' ' . $workspace->name);
}
}
}
/**
* This function is executed only by one workspace, for the command workspace-upgrade
*
* @param array $args, workspace name for to apply the upgrade
* @param array $opts, specify additional arguments for language, flag for buildACV, flag for noxml
*
* @return void
*/
function workspace_upgrade($args, $opts) {
$first = true;
$workspaces = get_workspaces_from_args($args);
$lang = array_key_exists("lang", $opts) ? $opts['lang'] : 'en';
$buildCacheView = array_key_exists('buildACV', $opts);
$flagUpdateXml = !array_key_exists('noxml', $opts);
$wsName = $workspaces[key($workspaces)]->name;
Bootstrap::setConstantsRelatedWs($wsName);
//Loop, read all the attributes related to the one workspace
foreach ($workspaces as $workspace) {
try {
$workspace->upgrade(
$buildCacheView,
$workspace->name,
false,
$lang,
['updateXml' => $flagUpdateXml, 'updateMafe' => $first]
);
$first = false;
$flagUpdateXml = false;
} catch (Exception $e) {
G::outRes("Errors upgrading workspace " . CLI::info($workspace->name) . ": " . CLI::error($e->getMessage()) . "\n");
}
}
}
/**
* We will upgrade the CONTENT table
* If we apply the command for all workspaces, we will need to execute one by one by redefining the constants
@@ -1210,7 +1127,7 @@ function migrate_content($args, $opts)
foreach ($workspaces as $workspace) {
print_r('Regenerating content in: ' . pakeColor::colorize($workspace->name, 'INFO') . "\n");
CLI::logging("-> Regenerating content \n");
$workspace->migrateContentRun($workspace->name, $lang);
$workspace->migrateContentRun($lang);
}
$stop = microtime(true);
CLI::logging("<*> Optimizing content data Process took " . ($stop - $start) . " seconds.\n");

View File

@@ -1,128 +0,0 @@
<?php
use ProcessMaker\Core\System;
class Upgrade
{
private $addon = null;
public function __construct($addon)
{
$this->addon = $addon;
}
public function install()
{
$filter = new InputFilter();
$start = microtime(1);
$filename = $this->addon->getDownloadFilename();
$time = microtime(1);
$archive = new Archive_Tar ($filename);
$time = microtime(1);
$extractDir = dirname($this->addon->getDownloadFilename()) . "/extract";
$extractDir = $filter->xssFilterHard($extractDir);
$backupDir = dirname($this->addon->getDownloadFilename()) . "/backup";
$backupDir = $filter->xssFilterHard($backupDir);
if (file_exists($extractDir)) {
G::rm_dir($extractDir);
}
if (file_exists($backupDir)) {
G::rm_dir($backupDir);
}
if (!is_dir($backupDir)) {
mkdir($backupDir);
}
$time = microtime(1);
echo "Extracting files...\n";
$archive->extractModify($extractDir, 'processmaker');
$checksumFile = file_get_contents("$extractDir/checksum.txt");
$time = microtime(1);
$checksums = array();
foreach (explode("\n", $checksumFile) as $line) {
$checksums[trim(substr($line, 33))] = substr($line, 0, 32);
}
$checksum = array();
$changedFiles = array();
$time = microtime(1);
$files = $this->ls_dir($extractDir);
echo "Updating ProcessMaker files...\n";
$time = microtime(1);
$checksumTime = 0;
foreach ($checksums as $filename => $checksum) {
if (is_dir("$extractDir/$filename")) {
$filename = $filter->xssFilterHard($filename);
print $filename;
continue;
}
$installedFile = PATH_TRUNK . "/$filename";
if (!file_exists($installedFile)) {
$installedMD5 = "";
} else {
$time = microtime(1);
$installedMD5 = G::encryptFileOld($installedFile);
$checksumTime += microtime(1) - $time;
}
$archiveMD5 = $checksum;
if (strcasecmp($archiveMD5, $installedMD5) != 0) {
$changedFiles[] = $filename;
if (!is_dir(dirname($backupDir.'/'.$filename))) {
mkdir(dirname($backupDir.'/'.$filename), 0777, true);
}
if (file_exists($installedFile) && is_file($installedFile)) {
copy($installedFile, $backupDir.'/'.$filename);
}
if (!is_dir(dirname($installedFile))) {
mkdir(dirname($installedFile), 0777, true);
}
if (!copy("$extractDir/$filename", $installedFile)) {
throw new Exception("Could not overwrite '$filename'");
}
}
}
printf("Updated %d files\n", count($changedFiles));
printf("Clearing cache...\n");
if (defined('PATH_C')) {
G::rm_dir(PATH_C);
mkdir(PATH_C, 0777, true);
}
$workspaces = System::listWorkspaces();
$count = count($workspaces);
$first = true;
$num = 0;
foreach ($workspaces as $index => $workspace) {
try {
$num += 1;
printf("Upgrading workspaces ($num/$count): {$workspace->name}\n");
$workspace->upgrade(false, config("system.workspace"), false, 'en', ['updateXml' => $first, 'updateMafe' => $first]);
$workspace->close();
$first = false;
} catch (Exception $e) {
printf("Errors upgrading workspace {$workspace->name}: {$e->getMessage()}\n");
}
}
}
private function ls_dir($dir, $basename = null)
{
$files = array();
if ($basename == null) {
$basename = $dir;
}
foreach (glob("$dir/*") as $filename) {
if (is_dir($filename)) {
$files = array_merge($files, $this->ls_dir($filename, $basename));
} else {
$files[] = substr($filename, strlen($basename) + 1);
}
}
return $files;
}
}

File diff suppressed because it is too large Load Diff

View File

@@ -385,13 +385,7 @@ class AddonsManager extends BaseAddonsManager
$this->setState();
} else {
if ($this->getAddonType() == "core") {
$upgrade = new Upgrade($this);
$upgrade->install();
} else {
throw new Exception("Addon type {$this->getAddonType()} not supported.");
}
throw new Exception("Addon type {$this->getAddonType()} not supported.");
}
}

View File

@@ -243,39 +243,6 @@ class System
return $items;
}
/**
* Review the checksum.txt
*
* @return array $result
*/
public static function verifyChecksum()
{
if (!file_exists(PATH_TRUNK . "checksum.txt")) {
return false;
}
$lines = explode("\n", file_get_contents(PATH_TRUNK . "checksum.txt"));
$result = array("diff" => array(), "missing" => array()
);
foreach ($lines as $line) {
if (empty($line)) {
continue;
}
list ($checksum, $empty, $filename) = explode(" ", $line);
//Skip xmlform because these files always change.
if (strpos($filename, "/xmlform/") !== false) {
continue;
}
if (file_exists(realpath($filename))) {
if (strcmp($checksum, G::encryptFileOld(realpath($filename))) != 0) {
$result['diff'][] = $filename;
}
} else {
$result['missing'][] = $filename;
}
}
return $result;
}
/**
* This function checks files to do updated to pm
*