2010-12-16 20:36:29 +00:00
|
|
|
<?php
|
2011-01-22 12:20:08 +00:00
|
|
|
/**
|
2011-01-27 15:04:37 +00:00
|
|
|
* cliWorkspaces.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>
|
2011-01-22 12:20:08 +00:00
|
|
|
* @package workflow-engine-bin-tasks
|
2011-01-28 14:16:58 +00:00
|
|
|
*/
|
2010-12-16 20:36:29 +00:00
|
|
|
|
2011-01-27 15:04:37 +00:00
|
|
|
CLI::taskName('info');
|
|
|
|
|
CLI::taskDescription(<<<EOT
|
|
|
|
|
Print information about the current system and specified workspaces.
|
|
|
|
|
EOT
|
|
|
|
|
);
|
|
|
|
|
CLI::taskArg('workspace-name', true, true);
|
|
|
|
|
CLI::taskRun(run_info);
|
|
|
|
|
|
|
|
|
|
CLI::taskName('workspace-backup');
|
|
|
|
|
CLI::taskDescription(<<<EOT
|
|
|
|
|
Backup the specified workspace to an archive.
|
|
|
|
|
|
|
|
|
|
BACKUP-NAME is the backup filename. If it contains slashes, it will be
|
|
|
|
|
treated as a filename, either absolute or relative. Otherwise it will be
|
|
|
|
|
treated as a filename inside the backups directory in the 'shared' folder.
|
|
|
|
|
If no BACKUP-NAME is specified, it will use the workspace name as the
|
|
|
|
|
filename.
|
|
|
|
|
|
|
|
|
|
A backup archive will contain all information about the specified workspace
|
|
|
|
|
so that it can be restored later. A database dump will be created and all
|
|
|
|
|
the workspace files will be included in the archive.
|
|
|
|
|
EOT
|
|
|
|
|
);
|
|
|
|
|
CLI::taskArg('workspace', false);
|
|
|
|
|
CLI::taskArg('backup-file', true);
|
|
|
|
|
CLI::taskRun(run_workspace_backup);
|
|
|
|
|
|
|
|
|
|
CLI::taskName('workspace-restore');
|
|
|
|
|
CLI::taskDescription(<<<EOT
|
|
|
|
|
Restore a workspace from a backup.
|
|
|
|
|
|
|
|
|
|
BACKUP-NAME is the backup filename. If it contains slashes, it will be
|
|
|
|
|
treated as a filename, either absolute or relative. Otherwise it will be
|
|
|
|
|
treated as a filename inside the backups directory in the 'shared' folder.
|
|
|
|
|
|
|
|
|
|
If WORKSPACE is specified, it will be used as the workspace to restore to,
|
|
|
|
|
otherwise the workspace will be restored using the same name as before.
|
|
|
|
|
EOT
|
|
|
|
|
);
|
|
|
|
|
CLI::taskArg('backup-file', false);
|
|
|
|
|
CLI::taskArg('workspace', true);
|
|
|
|
|
CLI::taskRun(run_workspace_restore);
|
|
|
|
|
|
|
|
|
|
CLI::taskName('cacheview-repair');
|
|
|
|
|
CLI::taskDescription(<<<EOT
|
|
|
|
|
Create and populate APP_CACHE_VIEW
|
|
|
|
|
|
|
|
|
|
You can specify as many workspaces as you want and if no workspace is
|
|
|
|
|
specified, it will run the upgrade on all available workspaces.
|
|
|
|
|
|
|
|
|
|
In order to improve the performance, ProcessMaker includes a cache of cases
|
|
|
|
|
in the table APP_CACHE_VIEW. This table must be in sync with the database
|
|
|
|
|
to present the right information in the inbox. This command will create the
|
|
|
|
|
table and populate it with the right information. You only need to use this
|
|
|
|
|
command after upgrading or if the inbox is out of sync.
|
|
|
|
|
EOT
|
|
|
|
|
);
|
|
|
|
|
CLI::taskArg('workspace', true, true);
|
|
|
|
|
CLI::taskRun(run_cacheview_upgrade);
|
|
|
|
|
|
|
|
|
|
CLI::taskName('database-upgrade');
|
|
|
|
|
CLI::taskDescription(<<<EOT
|
|
|
|
|
Repair the database schema to the latest version
|
|
|
|
|
|
|
|
|
|
You can specify as many workspaces as you want and if no workspace is
|
|
|
|
|
specified, it will run the upgrade on all available workspaces.
|
|
|
|
|
|
|
|
|
|
This command will read the system schema and attempt to modify the workspaces
|
|
|
|
|
tables to this new schema. This is useful after an upgrade when the workspace
|
|
|
|
|
database is not upgraded or when the database does not contain the right
|
|
|
|
|
schema.
|
|
|
|
|
EOT
|
|
|
|
|
);
|
|
|
|
|
CLI::taskArg('workspace', true, true);
|
|
|
|
|
CLI::taskRun(run_database_upgrade);
|
|
|
|
|
|
|
|
|
|
CLI::taskName('plugins-database-upgrade');
|
|
|
|
|
CLI::taskDescription(<<<EOT
|
|
|
|
|
Repair the database schema to the latest version
|
|
|
|
|
|
|
|
|
|
You can specify as many workspaces as you want and if no workspace is
|
|
|
|
|
specified, it will run the upgrade on all available workspaces.
|
|
|
|
|
|
|
|
|
|
The same as database-upgrade but works with schemas provided by plugins.
|
|
|
|
|
This is useful if there are installed plugins that include database schemas.
|
|
|
|
|
EOT
|
|
|
|
|
);
|
|
|
|
|
CLI::taskArg('workspace', true, true);
|
|
|
|
|
CLI::taskRun(run_plugins_database_upgrade);
|
|
|
|
|
|
|
|
|
|
CLI::taskName('workspace-upgrade');
|
|
|
|
|
CLI::taskDescription(<<<EOT
|
|
|
|
|
Upgrade the workspace(s) specified.
|
|
|
|
|
|
|
|
|
|
If no workspace is specified, the command will be run in all workspaces. You
|
|
|
|
|
can specify more then one workspace.
|
|
|
|
|
|
|
|
|
|
This command is a shortcut to execute all upgrade commands in this workspace.
|
|
|
|
|
Upgrading a workspace will make it corresponds to this version of
|
|
|
|
|
ProcessMaker. Use this command to upgrade workspaces individually, otherwise
|
|
|
|
|
use the upgrade command to upgrade the entire system.
|
|
|
|
|
EOT
|
|
|
|
|
);
|
|
|
|
|
CLI::taskArg('workspace-name', true, true);
|
|
|
|
|
CLI::taskRun(run_workspace_upgrade);
|
|
|
|
|
|
|
|
|
|
CLI::taskName('translation-repair');
|
|
|
|
|
CLI::taskDescription(<<<EOT
|
|
|
|
|
Upgrade translations for the specified workspace(s).
|
|
|
|
|
|
|
|
|
|
If no workspace is specified, the command will be run in all workspaces. You
|
|
|
|
|
can specify more then one workspace.
|
|
|
|
|
|
|
|
|
|
This command will go through each language installed in ProcessMaker and
|
|
|
|
|
update this workspace translations to match the installed translations.
|
|
|
|
|
EOT
|
|
|
|
|
);
|
|
|
|
|
CLI::taskArg('workspace-name', true, true);
|
|
|
|
|
CLI::taskRun(run_translation_upgrade);
|
|
|
|
|
|
2011-01-28 14:16:58 +00:00
|
|
|
/**
|
|
|
|
|
* Function run_info
|
|
|
|
|
* access public
|
|
|
|
|
*/
|
2011-01-27 15:04:37 +00:00
|
|
|
function run_info($args, $opts) {
|
2010-12-16 20:36:29 +00:00
|
|
|
$workspaces = get_workspaces_from_args($args, false);
|
2011-01-27 15:04:37 +00:00
|
|
|
workspaceTools::printSysInfo();
|
2010-12-16 20:36:29 +00:00
|
|
|
foreach ($workspaces as $workspace) {
|
|
|
|
|
echo "\n";
|
|
|
|
|
$workspace->printMetadata(false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-27 15:04:37 +00:00
|
|
|
function run_workspace_upgrade($args, $opts) {
|
2010-12-16 20:36:29 +00:00
|
|
|
$workspaces = get_workspaces_from_args($args);
|
2011-02-02 15:42:12 +00:00
|
|
|
$first = true;
|
2010-12-16 20:36:29 +00:00
|
|
|
foreach ($workspaces as $workspace) {
|
|
|
|
|
try {
|
2011-02-02 15:42:12 +00:00
|
|
|
$workspace->upgrade($first);
|
|
|
|
|
$first = false;
|
2010-12-16 20:36:29 +00:00
|
|
|
} catch (Exception $e) {
|
|
|
|
|
echo "Errors upgrading workspace " . info($workspace->name) . ": " . error($e->getMessage()) . "\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-27 15:04:37 +00:00
|
|
|
function run_translation_upgrade($args, $opts) {
|
2010-12-16 20:36:29 +00:00
|
|
|
$workspaces = get_workspaces_from_args($args);
|
2011-02-02 15:42:12 +00:00
|
|
|
$first = true;
|
2010-12-16 20:36:29 +00:00
|
|
|
foreach ($workspaces as $workspace) {
|
|
|
|
|
try {
|
|
|
|
|
echo "Upgrading translation for " . pakeColor::colorize($workspace->name, "INFO") . "\n";
|
2011-02-02 15:42:12 +00:00
|
|
|
$workspace->upgradeTranslation($first);
|
|
|
|
|
$first = false;
|
2010-12-16 20:36:29 +00:00
|
|
|
} catch (Exception $e) {
|
|
|
|
|
echo "Errors upgrading translation of workspace " . info($workspace->name) . ": " . error($e->getMessage()) . "\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-27 15:04:37 +00:00
|
|
|
function run_cacheview_upgrade($args, $opts) {
|
2010-12-16 20:36:29 +00:00
|
|
|
$workspaces = get_workspaces_from_args($args);
|
|
|
|
|
foreach ($workspaces as $workspace) {
|
|
|
|
|
try {
|
|
|
|
|
echo "Upgrading cache view for " . pakeColor::colorize($workspace->name, "INFO") . "\n";
|
|
|
|
|
$workspace->upgradeCacheView();
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
echo "Errors upgrading translation of workspace " . info($workspace->name) . ": " . error($e->getMessage()) . "\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-27 15:04:37 +00:00
|
|
|
function run_plugins_database_upgrade($args, $opts) {
|
2010-12-17 14:35:56 +00:00
|
|
|
$workspaces = get_workspaces_from_args($args);
|
|
|
|
|
foreach ($workspaces as $workspace) {
|
|
|
|
|
try {
|
2011-01-27 15:04:37 +00:00
|
|
|
CLI::logging("Upgrading plugins database for " . info($workspace->name) . "\n");
|
2010-12-17 14:35:56 +00:00
|
|
|
$workspace->upgradePluginsDatabase();
|
|
|
|
|
} catch (Exception $e) {
|
2011-01-27 15:04:37 +00:00
|
|
|
CLI::logging("Errors upgrading plugins database: " . error($e->getMessage()));
|
2010-12-17 14:35:56 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-27 15:04:37 +00:00
|
|
|
function run_database_export($args, $opts) {
|
2010-12-16 20:36:29 +00:00
|
|
|
if (count($args) < 2)
|
|
|
|
|
throw new Exception ("Please provide a workspace name and a directory for export");
|
|
|
|
|
$workspace = new workspaceTools($args[0]);
|
|
|
|
|
$workspace->exportDatabase($args[1]);
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-27 15:04:37 +00:00
|
|
|
function run_database_import($args, $opts) {
|
2010-12-16 20:36:29 +00:00
|
|
|
throw new Exception("Not implemented");
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-27 15:04:37 +00:00
|
|
|
function run_database_upgrade($args, $opts) {
|
2010-12-16 20:36:29 +00:00
|
|
|
database_upgrade("upgrade", $args);
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-27 15:04:37 +00:00
|
|
|
function run_database_check($args, $opts) {
|
2010-12-16 20:36:29 +00:00
|
|
|
database_upgrade("check", $args);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function database_upgrade($command, $args) {
|
|
|
|
|
$workspaces = get_workspaces_from_args($args);
|
|
|
|
|
$checkOnly = (strcmp($command, "check") == 0);
|
|
|
|
|
foreach ($workspaces as $workspace) {
|
|
|
|
|
if ($checkOnly)
|
|
|
|
|
print_r("Checking database in ".pakeColor::colorize($workspace->name, "INFO")." ");
|
|
|
|
|
else
|
|
|
|
|
print_r("Upgrading database in ".pakeColor::colorize($workspace->name, "INFO")." ");
|
|
|
|
|
try {
|
2011-01-10 14:14:31 +00:00
|
|
|
$changes = $workspace->upgradeDatabase($checkOnly);
|
2010-12-16 20:36:29 +00:00
|
|
|
if ($changes != false) {
|
|
|
|
|
if ($checkOnly) {
|
|
|
|
|
echo "> ".pakeColor::colorize("Run upgrade", "INFO")."\n";
|
|
|
|
|
echo " Tables (add = " . count($changes['tablesToAdd']);
|
|
|
|
|
echo ", alter = " . count($changes['tablesToAlter']) . ") ";
|
|
|
|
|
echo "- Indexes (add = " . count($changes['tablesWithNewIndex'])."";
|
|
|
|
|
echo ", alter = " . count($changes['tablesToAlterIndex']).")\n";
|
|
|
|
|
} else {
|
|
|
|
|
echo "> Schema fixed\n";
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
echo "> OK\n";
|
|
|
|
|
}
|
|
|
|
|
} catch (Exception $e) {
|
|
|
|
|
echo "> Error: ".error($e->getMessage()) . "\n";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function delete_app_from_table($con, $tableName, $appUid, $col="APP_UID") {
|
|
|
|
|
$stmt = $con->createStatement();
|
|
|
|
|
$sql = "DELETE FROM " . $tableName . " WHERE " . $col . "='" . $appUid . "'";
|
|
|
|
|
$rs = $stmt->executeQuery($sql, ResultSet::FETCHMODE_NUM);
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-27 15:04:37 +00:00
|
|
|
function run_drafts_clean($args, $opts) {
|
2010-12-16 20:36:29 +00:00
|
|
|
echo "Cleaning drafts\n";
|
|
|
|
|
|
|
|
|
|
if (count($args) < 1)
|
|
|
|
|
throw new Exception ("Please specify a workspace name");
|
|
|
|
|
$workspace = $args[0];
|
|
|
|
|
|
|
|
|
|
if (!file_exists(PATH_DB . $workspace . '/db.php')) {
|
|
|
|
|
throw new Exception('Could not find workspace ' . $workspace);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$allDrafts = false;
|
|
|
|
|
if (count($args) < 2) {
|
|
|
|
|
echo "Cases older them this much days will be deleted (ENTER for all): ";
|
|
|
|
|
$days = rtrim( fgets( STDIN ), "\n" );
|
|
|
|
|
if ($days == "") {
|
|
|
|
|
$allDrafts = true;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$days = $args[1];
|
|
|
|
|
if (strcmp($days, "all") == 0) {
|
|
|
|
|
$allDrafts = true;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!$allDrafts && (!is_numeric($days) || intval($days) <= 0)) {
|
|
|
|
|
throw new Exception("Days value is not valid: " . $days);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($allDrafts)
|
|
|
|
|
echo "Removing all drafts\n";
|
|
|
|
|
else
|
|
|
|
|
echo "Removing drafts older than " . $days . " days\n";
|
|
|
|
|
|
|
|
|
|
/* Load the configuration from the workspace */
|
|
|
|
|
require_once( PATH_DB . $workspace . '/db.php' );
|
|
|
|
|
require_once( PATH_THIRDPARTY . 'propel/Propel.php');
|
|
|
|
|
|
|
|
|
|
PROPEL::Init ( PATH_METHODS.'dbConnections/rootDbConnections.php' );
|
|
|
|
|
$con = Propel::getConnection("root");
|
|
|
|
|
|
|
|
|
|
$stmt = $con->createStatement();
|
|
|
|
|
|
|
|
|
|
if (!$allDrafts)
|
|
|
|
|
$dateSql = "AND DATE_SUB(CURDATE(),INTERVAL " . $days . " DAY) >= APP_CREATE_DATE";
|
|
|
|
|
else
|
|
|
|
|
$dateSql = "";
|
|
|
|
|
/* Search for all the draft cases */
|
|
|
|
|
$sql = "SELECT APP_UID FROM APPLICATION WHERE APP_STATUS='DRAFT'" . $dateSql;
|
|
|
|
|
$appRows = $stmt->executeQuery($sql, ResultSet::FETCHMODE_ASSOC);
|
|
|
|
|
|
|
|
|
|
/* Tables to remove the cases from */
|
|
|
|
|
$tables = array(
|
|
|
|
|
"APPLICATION",
|
|
|
|
|
"APP_DELEGATION",
|
|
|
|
|
"APP_CACHE_VIEW",
|
|
|
|
|
"APP_THREAD",
|
|
|
|
|
"APP_DOCUMENT",
|
|
|
|
|
"APP_EVENT",
|
|
|
|
|
"APP_HISTORY",
|
|
|
|
|
"APP_MESSAGE"
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
echo "Found " . $appRows->getRecordCount() . " cases to remove";
|
|
|
|
|
foreach ($appRows as $row) {
|
|
|
|
|
echo ".";
|
|
|
|
|
$appUid = $row['APP_UID'];
|
|
|
|
|
foreach ($tables as $table) {
|
|
|
|
|
delete_app_from_table($con, $table, $appUid);
|
|
|
|
|
}
|
|
|
|
|
delete_app_from_table($con, "CONTENT", $appUid, "CON_ID");
|
|
|
|
|
if (file_exists(PATH_DB . $workspace . '/files/'. $appUid)) {
|
|
|
|
|
echo "\nRemoving files from " . $appUid . "\n";
|
|
|
|
|
G::rm_dir(PATH_DB . $workspace . '/files/'. $appUid);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
echo "\n";
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-27 15:04:37 +00:00
|
|
|
function run_workspace_backup($args, $opts) {
|
|
|
|
|
$workspaces = array();
|
|
|
|
|
if (sizeof($args) > 2) {
|
|
|
|
|
$filename = array_pop($args);
|
|
|
|
|
foreach ($args as $arg) {
|
|
|
|
|
$workspaces[] = new workspaceTools($arg);
|
|
|
|
|
}
|
|
|
|
|
} else if (sizeof($args) > 0) {
|
|
|
|
|
$workspaces[] = new workspaceTools($args[0]);
|
|
|
|
|
if (sizeof($args) == 2)
|
|
|
|
|
$filename = $args[1];
|
|
|
|
|
else
|
|
|
|
|
$filename = $workspace->name . ".tar.gz";
|
|
|
|
|
}
|
|
|
|
|
foreach ($workspaces as $workspace)
|
|
|
|
|
$workspace->backup($filename);
|
2011-01-10 14:14:31 +00:00
|
|
|
}
|
|
|
|
|
|
2011-01-27 15:04:37 +00:00
|
|
|
function run_workspace_restore($args, $opts) {
|
2011-01-14 23:11:13 +00:00
|
|
|
//$workspace = new workspaceTools($args[0]);
|
|
|
|
|
workspaceTools::restore($args[0], $args[1]);
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-28 14:16:58 +00:00
|
|
|
?>
|