PMC-565
This commit is contained in:
@@ -5,14 +5,16 @@ use ProcessMaker\Core\System;
|
||||
|
||||
CLI::taskName('upgrade');
|
||||
CLI::taskDescription("Upgrade workspaces.\n\n This command should be run after upgrading ProcessMaker to a new version so that all workspaces are also upgraded to the\n new version.");
|
||||
|
||||
CLI::taskOpt('child', "Used by the main upgrade thread", 'child', 'child');
|
||||
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::taskOpt('nomafe', 'If this option is enabled, the MAFE files translation is not built.', 'nomafe', 'no-mafe');
|
||||
/*----------------------------------********---------------------------------*/
|
||||
CLI::taskOpt('keep_dyn_content', "Include the DYN_CONTENT_HISTORY value. Ex: --keep_dyn_content", 'i', 'keep_dyn_content');
|
||||
/*----------------------------------********---------------------------------*/
|
||||
CLI::taskRun("run_upgrade");
|
||||
/*----------------------------------********---------------------------------*/
|
||||
|
||||
CLI::taskName('unify-database');
|
||||
CLI::taskDescription(
|
||||
<<<EOT
|
||||
@@ -36,177 +38,160 @@ CLI::taskRun("run_unify_database");
|
||||
/*----------------------------------********---------------------------------*/
|
||||
|
||||
/**
|
||||
* A version of rm_dir which does not exits on error.
|
||||
* Execute the upgrade
|
||||
*
|
||||
* @param string $filename directory or file to remove
|
||||
* @param bool $filesOnly either to remove the containing directory as well or not
|
||||
* @param array $parameters
|
||||
* @param array $args
|
||||
*/
|
||||
function rm_dir($filename, $filesOnly = false)
|
||||
function run_upgrade($parameters, $args)
|
||||
{
|
||||
if (is_file($filename)) {
|
||||
@unlink($filename) or CLI::logging(CLI::error("Could not remove file $filename")."\n");
|
||||
} else {
|
||||
foreach (glob("$filename/*") as $f) {
|
||||
rm_dir($f);
|
||||
}
|
||||
if (!$filesOnly) {
|
||||
@rmdir($filename) or CLI::logging(CLI::error("Could not remove directory $filename")."\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
// Get values from command and arguments
|
||||
$workspaces = get_workspaces_from_args($parameters);
|
||||
$mainThread = $printHF = !array_key_exists('child', $args);
|
||||
$updateXmlForms = !array_key_exists('noxml', $args);
|
||||
$updateMafe = !array_key_exists('nomafe', $args);
|
||||
$keepDynContent = false;
|
||||
/*----------------------------------********---------------------------------*/
|
||||
$keepDynContent = array_key_exists('keep_dyn_content', $args); //In community version this section will be removed
|
||||
/*----------------------------------********---------------------------------*/
|
||||
|
||||
function run_upgrade($command, $args)
|
||||
{
|
||||
CLI::logging("UPGRADE", PROCESSMAKER_PATH . "upgrade.log");
|
||||
CLI::logging("Checking files integrity...\n");
|
||||
//setting flag to true to check into sysGeneric.php
|
||||
$workspaces = get_workspaces_from_args($command);
|
||||
$oneWorkspace = 'true';
|
||||
if (count($workspaces) == 1) {
|
||||
foreach ($workspaces as $index => $workspace) {
|
||||
$oneWorkspace = $workspace->name;
|
||||
// Initializing variables
|
||||
$globalStartTime = microtime(true);
|
||||
$numberOfWorkspaces = count($workspaces);
|
||||
$countWorkspace = 1;
|
||||
|
||||
if ($printHF) {
|
||||
// Set upgrade flag
|
||||
if (count($workspaces) === 1) {
|
||||
// For the specific workspace send in the command
|
||||
G::isPMUnderUpdating(1, $workspaces[0]->name);
|
||||
} else {
|
||||
// For all workspaces
|
||||
G::isPMUnderUpdating(1);
|
||||
}
|
||||
|
||||
// Print information when start the upgrade process
|
||||
CLI::logging('UPGRADE LOG INITIALIZED', PROCESSMAKER_PATH . 'upgrade.log');
|
||||
CLI::logging("UPGRADE STARTED\n");
|
||||
}
|
||||
$flag = G::isPMUnderUpdating(1, $oneWorkspace);
|
||||
//start to upgrade
|
||||
$checksum = System::verifyChecksum();
|
||||
if ($checksum === false) {
|
||||
CLI::logging(CLI::error("checksum.txt not found, integrity check is not possible") . "\n");
|
||||
if (!CLI::question("Integrity check failed, do you want to continue the upgrade?")) {
|
||||
CLI::logging("Upgrade failed\n");
|
||||
$flag = G::isPMUnderUpdating(0);
|
||||
die();
|
||||
}
|
||||
} else {
|
||||
if (!empty($checksum['missing'])) {
|
||||
CLI::logging(CLI::error("The following files were not found in the installation:")."\n");
|
||||
foreach ($checksum['missing'] as $missing) {
|
||||
CLI::logging(" $missing\n");
|
||||
|
||||
foreach ($workspaces as $workspace) {
|
||||
if ($mainThread) {
|
||||
CLI::logging("FOLDERS AND FILES OF THE SYSTEM\n");
|
||||
// Upgrade actions for global files
|
||||
CLI::logging("* Start cleaning compiled folder...\n");
|
||||
$start = microtime(true);
|
||||
if (defined('PATH_C')) {
|
||||
G::rm_dir(PATH_C);
|
||||
G::mk_dir(PATH_C, 0777);
|
||||
}
|
||||
}
|
||||
if (!empty($checksum['diff'])) {
|
||||
CLI::logging(CLI::error("The following files have modifications:")."\n");
|
||||
foreach ($checksum['diff'] as $diff) {
|
||||
CLI::logging(" $diff\n");
|
||||
CLI::logging("* End cleaning compiled folder...(Completed on " . (microtime(true) - $start) . " seconds)\n");
|
||||
|
||||
CLI::logging("* Start to remove deprecated files...\n");
|
||||
$start = microtime(true);
|
||||
$workspace->removeDeprecatedFiles();
|
||||
CLI::logging("* End to remove deprecated files...(Completed on " . (microtime(true) - $start) . " seconds)\n");
|
||||
|
||||
CLI::logging("* Start checking Enterprise folder/files...\n");
|
||||
$start = microtime(true);
|
||||
$workspace->verifyFilesOldEnterprise();
|
||||
CLI::logging("* End checking Enterprise folder/files...(Completed on " . (microtime(true) - $start) . " seconds)\n");
|
||||
|
||||
CLI::logging("* Start checking framework paths...\n");
|
||||
$start = microtime(true);
|
||||
$workspace->checkFrameworkPaths();
|
||||
CLI::logging("* End checking framework paths...(Completed on " . (microtime(true) - $start) . " seconds)\n");
|
||||
|
||||
CLI::logging("* Start fixing serialized instance in serverConf.singleton file...\n");
|
||||
$start = microtime(true);
|
||||
$serverConf = ServerConf::getSingleton();
|
||||
$serverConf->updateClassNameInFile();
|
||||
CLI::logging("* End fixing serialized instance in serverConf.singleton file...(Completed on " .
|
||||
(microtime(true) - $start) . " seconds)\n");
|
||||
|
||||
CLI::logging("* Start the safe upgrade for javascript files cached by the browser (Maborak, ExtJs)...\n");
|
||||
$start = microtime(true);
|
||||
G::browserCacheFilesSetUid();
|
||||
CLI::logging("* End the safe upgrade for javascript files cached by the browser (Maborak, ExtJs)...(Completed on " .
|
||||
(microtime(true) - $start) . " seconds)\n");
|
||||
|
||||
CLI::logging("* Start to backup patch files...\n");
|
||||
$arrayPatch = glob(PATH_TRUNK . 'patch-*');
|
||||
if ($arrayPatch) {
|
||||
foreach ($arrayPatch as $value) {
|
||||
if (file_exists($value)) {
|
||||
// Copy patch content
|
||||
$names = pathinfo($value);
|
||||
$nameFile = $names['basename'];
|
||||
|
||||
$contentFile = file_get_contents($value);
|
||||
$contentFile = preg_replace("[\n|\r|\n\r]", '', $contentFile);
|
||||
CLI::logging($contentFile . ' installed (' . $nameFile . ')', PATH_DATA . 'log/upgrades.log');
|
||||
|
||||
// Move patch file
|
||||
$newFile = PATH_DATA . $nameFile;
|
||||
G::rm_dir($newFile);
|
||||
copy($value, $newFile);
|
||||
G::rm_dir($value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!(empty($checksum['missing']) || empty($checksum['diff']))) {
|
||||
if (!CLI::question("Integrity check failed, do you want to continue the upgrade?")) {
|
||||
CLI::logging("Upgrade failed\n");
|
||||
$flag = G::isPMUnderUpdating(0);
|
||||
die();
|
||||
}
|
||||
}
|
||||
}
|
||||
CLI::logging("Clearing cache...\n");
|
||||
if (defined('PATH_C')) {
|
||||
G::rm_dir(PATH_C);
|
||||
G::mk_dir(PATH_C, 0777);
|
||||
}
|
||||
CLI::logging("* End to backup patch files...(Completed on " . (microtime(true) - $start) . " seconds)\n");
|
||||
|
||||
$count = count($workspaces);
|
||||
$first = true;
|
||||
$errors = false;
|
||||
$countWorkspace = 0;
|
||||
$buildCacheView = array_key_exists('buildACV', $args);
|
||||
$flagUpdateXml = !array_key_exists('noxml', $args);
|
||||
$optionMigrateHistoryData = [
|
||||
/*----------------------------------********---------------------------------*/
|
||||
'keepDynContent' => array_key_exists('keep_dyn_content', $args)
|
||||
/*----------------------------------********---------------------------------*/
|
||||
];
|
||||
CLI::logging("* Start to backup log files...\n");
|
||||
$start = microtime(true);
|
||||
$workspace->backupLogFiles();
|
||||
CLI::logging("* End to backup log files... (Completed on " . (microtime(true) - $start) . " seconds)\n");
|
||||
|
||||
foreach ($workspaces as $index => $workspace) {
|
||||
if (empty(config("system.workspace"))) {
|
||||
define("SYS_SYS", $workspace->name);
|
||||
config(["system.workspace" => $workspace->name]);
|
||||
// The previous actions should be executed only the first time
|
||||
$mainThread = false;
|
||||
}
|
||||
if ($numberOfWorkspaces === 1) {
|
||||
// Displaying information of the current workspace to upgrade
|
||||
CLI::logging("UPGRADING DATABASE AND FILES OF WORKSPACE '{$workspace->name}' ($countWorkspace/$numberOfWorkspaces)\n");
|
||||
|
||||
if (!defined("PATH_DATA_SITE")) {
|
||||
define("PATH_DATA_SITE", PATH_DATA . "sites" . PATH_SEP . config("system.workspace") . PATH_SEP);
|
||||
}
|
||||
// Build parameters
|
||||
$arrayOptTranslation = [
|
||||
'updateXml' => $updateXmlForms,
|
||||
'updateMafe' => $updateMafe
|
||||
];
|
||||
$optionMigrateHistoryData = [
|
||||
'keepDynContent' => $keepDynContent
|
||||
];
|
||||
|
||||
if (!defined('DB_ADAPTER')) {
|
||||
define('DB_ADAPTER', 'mysql');
|
||||
}
|
||||
|
||||
try {
|
||||
$countWorkspace++;
|
||||
CLI::logging("Upgrading workspaces ($countWorkspace/$count): " . CLI::info($workspace->name) . "\n");
|
||||
$workspace->upgrade($buildCacheView, $workspace->name, false, 'en', ['updateXml' => $flagUpdateXml, 'updateMafe' => $first], $optionMigrateHistoryData);
|
||||
// Upgrade database and files from a specific workspace
|
||||
$workspace->upgrade($workspace->name, true, SYS_LANG, $arrayOptTranslation, $optionMigrateHistoryData);
|
||||
$workspace->close();
|
||||
$first = false;
|
||||
$flagUpdateXml = false;
|
||||
} catch (Exception $e) {
|
||||
CLI::logging("Errors upgrading workspace " . CLI::info($workspace->name) . ": " . CLI::error($e->getMessage()) . "\n");
|
||||
$errors = true;
|
||||
} else {
|
||||
// Build arguments
|
||||
$args = '--child';
|
||||
$args .= $updateXmlForms ? '' : ' --no-xml';
|
||||
$args .= $updateMafe ? '' : ' --no-mafe';
|
||||
$args .= $keepDynContent ? ' --keep_dyn_content' : '';
|
||||
|
||||
// Build and execute command in another thread
|
||||
$command = PHP_BINARY . ' processmaker upgrade ' . $args . ' ' . $workspace->name;
|
||||
passthru($command);
|
||||
}
|
||||
|
||||
// After the first execution is required set this values to false
|
||||
$updateXmlForms = false;
|
||||
$updateMafe = false;
|
||||
|
||||
// Increment workspaces counter
|
||||
$countWorkspace++;
|
||||
}
|
||||
|
||||
//Verify the information of the singleton ServConf by changing the name of the class if is required.
|
||||
CLI::logging("\nCheck/Fix serialized instance in serverConf.singleton file\n\n");
|
||||
$serverConf = ServerConf::getSingleton();
|
||||
$serverConf->updateClassNameInFile();
|
||||
if ($printHF) {
|
||||
// Print information when finish the upgrade process
|
||||
CLI::logging('UPGRADE FINISHED (Completed on ' . (microtime(true) - $globalStartTime) .
|
||||
' seconds), ProcessMaker ' . System::getVersion() . ' installed)' . "\n\n");
|
||||
|
||||
// SAVE Upgrades/Patches
|
||||
$arrayPatch = glob(PATH_TRUNK . 'patch-*');
|
||||
|
||||
if ($arrayPatch) {
|
||||
foreach ($arrayPatch as $value) {
|
||||
if (file_exists($value)) {
|
||||
// copy content the patch
|
||||
$names = pathinfo($value);
|
||||
$nameFile = $names['basename'];
|
||||
|
||||
$contentFile = file_get_contents($value);
|
||||
$contentFile = preg_replace("[\n|\r|\n\r]", '', $contentFile);
|
||||
CLI::logging($contentFile . ' installed (' . $nameFile . ')', PATH_DATA . 'log/upgrades.log');
|
||||
|
||||
// move file of patch
|
||||
$newFile = PATH_DATA . $nameFile;
|
||||
G::rm_dir($newFile);
|
||||
copy($value, $newFile);
|
||||
G::rm_dir($value);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
CLI::logging('ProcessMaker ' . System::getVersion(). ' installed', PATH_DATA . 'log/upgrades.log');
|
||||
// Delete upgrade flag
|
||||
G::isPMUnderUpdating(0);
|
||||
}
|
||||
|
||||
//Safe upgrade for JavaScript files
|
||||
CLI::logging("\nSafe upgrade for files cached by the browser\n\n");
|
||||
|
||||
G::browserCacheFilesSetUid();
|
||||
|
||||
//Status
|
||||
if ($errors) {
|
||||
CLI::logging("Upgrade finished but there were errors upgrading workspaces.\n");
|
||||
CLI::logging(CLI::error("Please check the log above to correct any issues.") . "\n");
|
||||
} else {
|
||||
CLI::logging("Upgrade successful\n");
|
||||
}
|
||||
|
||||
//setting flag to false
|
||||
$flag = G::isPMUnderUpdating(0);
|
||||
}
|
||||
|
||||
function listFiles($dir)
|
||||
{
|
||||
$files = array();
|
||||
$lista = glob($dir.'/*');
|
||||
foreach ($lista as $valor) {
|
||||
if (is_dir($valor)) {
|
||||
$inner_files = listFiles($valor);
|
||||
if (is_array($inner_files)) {
|
||||
$files = array_merge($files, $inner_files);
|
||||
}
|
||||
}
|
||||
if (is_file($valor)) {
|
||||
array_push($files, $valor);
|
||||
}
|
||||
}
|
||||
return $files;
|
||||
}
|
||||
/*----------------------------------********---------------------------------*/
|
||||
function run_unify_database($args)
|
||||
{
|
||||
|
||||
@@ -103,26 +103,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).
|
||||
@@ -384,69 +364,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
|
||||
@@ -1181,7 +1098,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");
|
||||
|
||||
Reference in New Issue
Block a user