Re-implemented CLI to provide help messages.
This commit is contained in:
@@ -1,60 +1,109 @@
|
||||
<?php
|
||||
/**
|
||||
* cliUpgrade.php
|
||||
*
|
||||
* ProcessMaker Open Source Edition
|
||||
* Copyright (C) 2011 Colosa Inc.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as
|
||||
* published by the Free Software Foundation, either version 3 of the
|
||||
* License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* For more information, contact Colosa Inc, 2566 Le Jeune Rd.,
|
||||
* Coral Gables, FL, 33134, USA, or email info@colosa.com.
|
||||
*
|
||||
* @author Alexandre Rosenfeld <alexandre@colosa.com>
|
||||
* @package workflow-engine-bin-tasks
|
||||
**/
|
||||
|
||||
G::LoadClass("system");
|
||||
G::LoadClass("wsTools");
|
||||
|
||||
pake_task("upgrade");
|
||||
CLI::taskName('upgrade');
|
||||
CLI::taskDescription(<<<EOT
|
||||
Upgrade workspaces.
|
||||
|
||||
This command should be run after ProcessMaker files are upgraded so that all
|
||||
workspaces are upgraded to the current version.
|
||||
EOT
|
||||
);
|
||||
CLI::taskRun(run_upgrade);
|
||||
|
||||
|
||||
/**
|
||||
* A versoni of rm_dir which does not exits on error.
|
||||
*
|
||||
* @param string $filename directory or file to remove
|
||||
* @param bool $filesOnly either to remove the containing directory as well or not
|
||||
*/
|
||||
function rm_dir($filename, $filesOnly = false) {
|
||||
if (is_file($filename)) {
|
||||
@unlink($filename) or CLI::message(CLI::error("Could not remove file $filename")."\n");;
|
||||
} else {
|
||||
foreach(glob("$filename/*") as $f) {
|
||||
rm_dir($f);
|
||||
}
|
||||
if (!$filesOnly)
|
||||
@rmdir($filename) or CLI::message(CLI::error("Could not remove directory $filename")."\n");
|
||||
}
|
||||
}
|
||||
|
||||
function run_upgrade($command, $args) {
|
||||
logging("UPGRADE", PROCESSMAKER_PATH . "upgrade.log");
|
||||
logging("Checking files integrity...\n");
|
||||
CLI::logging("UPGRADE", PROCESSMAKER_PATH . "upgrade.log");
|
||||
CLI::logging("Checking files integrity...\n");
|
||||
$checksum = System::verifyChecksum();
|
||||
if ($checksum === false) {
|
||||
logging(error("checksum.txt not found, integrity check is not possible") . "\n");
|
||||
if (!question("Integrity check failed, do you want to continue the upgrade?")) {
|
||||
logging("Upgrade failed\n");
|
||||
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");
|
||||
die();
|
||||
}
|
||||
} else {
|
||||
if (!empty($checksum['missing'])) {
|
||||
logging(error("The following files were not found in the installation:")."\n");
|
||||
CLI::logging(CLI::error("The following files were not found in the installation:")."\n");
|
||||
foreach($checksum['missing'] as $missing) {
|
||||
logging(" $missing\n");
|
||||
CLI::logging(" $missing\n");
|
||||
}
|
||||
}
|
||||
if (!empty($checksum['diff'])) {
|
||||
logging(error("The following files have modifications:")."\n");
|
||||
CLI::logging(CLI::error("The following files have modifications:")."\n");
|
||||
foreach($checksum['diff'] as $diff) {
|
||||
logging(" $diff\n");
|
||||
CLI::logging(" $diff\n");
|
||||
}
|
||||
}
|
||||
if (!(empty($checksum['missing']) || empty($checksum['diff']))) {
|
||||
if (!question("Integrity check failed, do you want to continue the upgrade?")) {
|
||||
logging("Upgrade failed\n");
|
||||
if (!CLI::question("Integrity check failed, do you want to continue the upgrade?")) {
|
||||
CLI::logging("Upgrade failed\n");
|
||||
die();
|
||||
}
|
||||
}
|
||||
}
|
||||
logging("Clearing cache...\n");
|
||||
CLI::logging("Clearing cache...\n");
|
||||
if(defined('PATH_C'))
|
||||
G::rm_dir(PATH_C);
|
||||
rm_dir(PATH_C, true);
|
||||
$workspaces = get_workspaces_from_args($args);
|
||||
$count = count($workspaces);
|
||||
$first = true;
|
||||
foreach ($workspaces as $index => $workspace) {
|
||||
try {
|
||||
logging("Upgrading workspaces ($index/$count): " . info($workspace->name) . "\n");
|
||||
CLI::logging("Upgrading workspaces ($index/$count): " . CLI::info($workspace->name) . "\n");
|
||||
$workspace->upgrade($first);
|
||||
$workspace->close();
|
||||
$first = false;
|
||||
} catch (Exception $e) {
|
||||
logging("Errors upgrading workspace " . info($workspace->name) . ": " . error($e->getMessage()) . "\n");
|
||||
CLI::logging("Errors upgrading workspace " . CLI::info($workspace->name) . ": " . CLI::error($e->getMessage()) . "\n");
|
||||
}
|
||||
}
|
||||
logging("Upgrade successful\n");
|
||||
CLI::logging("Upgrade successful\n");
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
Reference in New Issue
Block a user