Files
luos/workflow/engine/bin/tasks/cliUpgrade.php

302 lines
13 KiB
PHP
Raw Normal View History

2010-12-16 20:36:29 +00:00
<?php
2018-02-01 13:06:32 +00:00
use Illuminate\Support\Facades\DB;
2017-08-14 16:13:46 -04:00
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.");
2019-03-18 13:36:08 -04:00
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');
2019-03-18 13:36:08 -04:00
CLI::taskOpt('nomafe', 'If this option is enabled, the MAFE files translation is not built.', 'nomafe', 'no-mafe');
2018-06-11 09:58:48 -04:00
/*----------------------------------********---------------------------------*/
2018-06-15 16:24:13 -04:00
CLI::taskOpt('keep_dyn_content', "Include the DYN_CONTENT_HISTORY value. Ex: --keep_dyn_content", 'i', 'keep_dyn_content');
2018-06-11 09:58:48 -04:00
/*----------------------------------********---------------------------------*/
2014-03-17 11:54:09 -04:00
CLI::taskRun("run_upgrade");
/*----------------------------------********---------------------------------*/
2019-03-18 13:36:08 -04:00
CLI::taskName('unify-database');
2017-12-04 13:25:35 +00:00
CLI::taskDescription(
<<<EOT
Unify RBAC, Reports and Workflow database schemas to match the latest version
Specify the workspaces whose databases schemas should be unified.
If no workspace is specified, then the database schema will be upgraded or
repaired on all available workspaces.
This command will read the system schema and attempt to modify the workspaces'
tables to match this new schema. In version 2.8 and later, it will merge the 3
databases used in previous versions of ProcessMaker into one database. This
command may be used after upgrading from ProcessMaker 2.5 to a later version
of ProcessMaker.
EOT
);
/*----------------------------------********---------------------------------*/
CLI::taskArg('workspace');
/*----------------------------------********---------------------------------*/
CLI::taskRun("run_unify_database");
/*----------------------------------********---------------------------------*/
/**
2019-03-18 13:36:08 -04:00
* Execute the upgrade
*
2019-03-18 13:36:08 -04:00
* @param array $parameters
* @param array $args
*/
2019-03-18 13:36:08 -04:00
function run_upgrade($parameters, $args)
{
2019-03-18 13:36:08 -04:00
// 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
/*----------------------------------********---------------------------------*/
// 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);
}
2010-12-16 20:36:29 +00:00
2019-03-18 13:36:08 -04:00
// Print information when start the upgrade process
CLI::logging('UPGRADE LOG INITIALIZED', PROCESSMAKER_PATH . 'upgrade.log');
CLI::logging("UPGRADE STARTED\n");
}
2019-03-18 13:36:08 -04:00
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);
}
2019-03-18 13:36:08 -04:00
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);
}
}
}
2019-03-18 13:36:08 -04:00
CLI::logging("* End to backup patch files...(Completed on " . (microtime(true) - $start) . " seconds)\n");
2019-03-18 13:36:08 -04:00
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");
2019-03-18 13:36:08 -04:00
// The previous actions should be executed only the first time
$mainThread = false;
}
2019-03-18 13:36:08 -04:00
if ($numberOfWorkspaces === 1) {
// Displaying information of the current workspace to upgrade
CLI::logging("UPGRADING DATABASE AND FILES OF WORKSPACE '{$workspace->name}' ($countWorkspace/$numberOfWorkspaces)\n");
// Build parameters
$arrayOptTranslation = [
'updateXml' => $updateXmlForms,
'updateMafe' => $updateMafe
];
$optionMigrateHistoryData = [
'keepDynContent' => $keepDynContent
];
// Upgrade database and files from a specific workspace
2019-03-20 10:58:58 -04:00
$workspace->upgrade($workspace->name, SYS_LANG, $arrayOptTranslation, $optionMigrateHistoryData);
$workspace->close();
2019-03-18 13:36:08 -04:00
} 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);
}
2019-03-18 13:36:08 -04:00
// After the first execution is required set this values to false
$updateXmlForms = false;
$updateMafe = false;
2019-03-18 13:36:08 -04:00
// Increment workspaces counter
$countWorkspace++;
}
2019-03-18 13:36:08 -04:00
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");
2010-12-16 20:36:29 +00:00
2019-03-18 13:36:08 -04:00
// Delete upgrade flag
G::isPMUnderUpdating(0);
}
}
2019-03-18 13:36:08 -04:00
/*----------------------------------********---------------------------------*/
function run_unify_database($args)
{
$workspaces = array();
2017-12-04 13:25:35 +00:00
if (count($args) > 2) {
$filename = array_pop($args);
foreach ($args as $arg) {
2017-08-11 14:10:44 -04:00
$workspaces[] = new WorkspaceTools($arg);
}
2017-12-04 13:25:35 +00:00
} elseif (count($args) > 0) {
2017-08-11 14:10:44 -04:00
$workspace = new WorkspaceTools($args[0]);
$workspaces[] = $workspace;
}
CLI::logging("UPGRADE", PROCESSMAKER_PATH . "upgrade.log");
CLI::logging("Checking workspaces...\n");
//setting flag to true to check into sysGeneric.php
$flag = G::isPMUnderUpdating(0);
//start to unify
$count = count($workspaces);
if ($count > 1) {
2017-12-04 13:25:35 +00:00
if (!Bootstrap::isLinuxOs()) {
CLI::error("This is not a Linux enviroment, please specify workspace.\n");
return;
}
}
$first = true;
$errors = false;
$countWorkspace = 0;
$buildCacheView = array_key_exists("buildACV", $args);
foreach ($workspaces as $workspace) {
try {
$countWorkspace++;
if (! $workspace->workspaceExists()) {
echo "Workspace {$workspace->name} not found\n";
return false;
}
$ws = $workspace->name;
2017-12-04 13:25:35 +00:00
$sContent = file_get_contents(PATH_DB . $ws . PATH_SEP . 'db.php');
if (strpos($sContent, 'rb_')) {
$workspace->onedb = false;
} else {
$workspace->onedb = true;
}
if ($workspace->onedb) {
CLI::logging("The \"$workspace->name\" workspace already using one database...\n");
} else {
//create destination path
$parentDirectory = PATH_DATA . "upgrade";
2017-12-04 13:25:35 +00:00
if (! file_exists($parentDirectory)) {
mkdir($parentDirectory);
}
$tempDirectory = $parentDirectory . basename(tempnam(__FILE__, ''));
2017-12-04 13:25:35 +00:00
if (is_writable($parentDirectory)) {
mkdir($tempDirectory);
} else {
2017-12-04 13:25:35 +00:00
throw new Exception("Could not create directory:" . $parentDirectory);
}
$metadata = $workspace->getMetadata();
2017-12-04 13:25:35 +00:00
CLI::logging("Exporting rb and rp databases to a temporal location...\n");
$metadata["databases"] = $workspace->exportDatabase($tempDirectory, true);
$metadata["version"] = 1;
2017-12-04 13:25:35 +00:00
list($dbHost, $dbUser, $dbPass) = @explode(SYSTEM_HASH, G::decrypt(HASH_INSTALLATION, SYSTEM_HASH));
2018-02-01 13:06:32 +00:00
$connectionName = 'UPGRADE';
InstallerModule::setNewConnection($connectionName, $dbHost, $dbUser, $dbPass,'', '');
foreach ($metadata['databases'] as $db) {
$dbName = $metadata['DB_NAME'];
2017-12-04 13:25:35 +00:00
CLI::logging("+> Restoring {$db['name']} to $dbName database\n");
2018-02-01 13:06:32 +00:00
$aParameters = ['dbHost'=>$dbHost,'dbUser'=>$dbUser,'dbPass'=>$dbPass];
2018-02-01 13:06:32 +00:00
$restore = $workspace->executeScript($dbName, "$tempDirectory/{$db['name']}.sql", $aParameters, $connectionName);
if ($restore) {
2017-12-04 13:25:35 +00:00
CLI::logging("+> Remove {$db['name']} database\n");
2018-02-01 13:06:32 +00:00
DB::connection($connectionName)->statement("DROP DATABASE IF EXISTS {$db['name']}");
}
}
2018-02-01 13:06:32 +00:00
DB::disconnect($connectionName);
2017-12-04 13:25:35 +00:00
CLI::logging("Removing temporary files\n");
G::rm_dir($tempDirectory);
2017-12-04 13:25:35 +00:00
$newDBNames = $workspace->resetDBInfo($dbHost, true, true, true);
2017-12-04 13:25:35 +00:00
CLI::logging(CLI::info("Done restoring databases") . "\n");
}
} catch (Exception $e) {
CLI::logging("Errors upgrading workspace " . CLI::info($workspace->name) . ": " . CLI::error($e->getMessage()) . "\n");
$errors = true;
}
}
$flag = G::isPMUnderUpdating(0);
}
2017-12-04 13:25:35 +00:00
/*----------------------------------********---------------------------------*/