Added support to upgrade plugins database.
This commit is contained in:
@@ -10,6 +10,8 @@ pake_task('cacheview-upgrade');
|
|||||||
pake_task('database-upgrade');
|
pake_task('database-upgrade');
|
||||||
pake_task('database-check');
|
pake_task('database-check');
|
||||||
|
|
||||||
|
pake_task('plugins-database-upgrade');
|
||||||
|
|
||||||
pake_task('database-export');
|
pake_task('database-export');
|
||||||
pake_task('database-import');
|
pake_task('database-import');
|
||||||
|
|
||||||
@@ -62,6 +64,18 @@ function run_cacheview_upgrade($command, $args) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function run_plugins_database_upgrade($command, $args) {
|
||||||
|
$workspaces = get_workspaces_from_args($args);
|
||||||
|
foreach ($workspaces as $workspace) {
|
||||||
|
try {
|
||||||
|
logging("Upgrading plugins database for " . info($workspace->name) . "\n");
|
||||||
|
$workspace->upgradePluginsDatabase();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
logging("Errors upgrading plugins database: " . error($e->getMessage()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function run_database_export($command, $args) {
|
function run_database_export($command, $args) {
|
||||||
G::LoadSystem('dbMaintenance');
|
G::LoadSystem('dbMaintenance');
|
||||||
if (count($args) < 2)
|
if (count($args) < 2)
|
||||||
|
|||||||
@@ -1,90 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
pake_task('drafts-clean');
|
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
|
||||||
|
|
||||||
function run_drafts_clean($task, $args)
|
|
||||||
{
|
|
||||||
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";
|
|
||||||
}
|
|
||||||
?>
|
|
||||||
@@ -1,49 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
pake_task('schema-check');
|
|
||||||
pake_task('schema-fix');
|
|
||||||
|
|
||||||
G::LoadClass( "wsTools" );
|
|
||||||
|
|
||||||
function schemaCommand($command, $args) {
|
|
||||||
if (count($args) < 1) {
|
|
||||||
$workspaces = workspaceTools::listWorkspaces();
|
|
||||||
} else {
|
|
||||||
$workspaces = array(new workspaceTools($args[0]));
|
|
||||||
}
|
|
||||||
$checkOnly = (strcmp($command, "check") == 0);
|
|
||||||
foreach ($workspaces as $workspace) {
|
|
||||||
if ($checkOnly)
|
|
||||||
print_r("Checking ".$workspace->workspaceName."\n");
|
|
||||||
else
|
|
||||||
print_r("Fixing ".$workspace->workspaceName."\n");
|
|
||||||
try {
|
|
||||||
$changes = $workspace->repairSchema($checkOnly);
|
|
||||||
if ($changes != false) {
|
|
||||||
if ($checkOnly) {
|
|
||||||
echo "> Schema has changed, run fix to repair\n";
|
|
||||||
echo " Tables to add: " . count($changes['tablesToAdd'])."\n";
|
|
||||||
echo " Tables to alter: " . count($changes['tablesToAlter'])."\n";
|
|
||||||
echo " Indexes to add: " . count($changes['tablesWithNewIndex'])."\n";
|
|
||||||
echo " Indexes to alter: " . count($changes['tablesToAlterIndex'])."\n";
|
|
||||||
} else {
|
|
||||||
echo "> Schema fixed\n";
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
echo "> Schema is OK\n";
|
|
||||||
}
|
|
||||||
} catch (Exception $e) {
|
|
||||||
echo "Could not ". $command ." ". $workspace->workspaceName .": ".$e->getMessage() . "\n";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
function run_schema_fix($task, $args) {
|
|
||||||
schemaCommand("fix", $args);
|
|
||||||
}
|
|
||||||
|
|
||||||
function run_schema_check($task, $args) {
|
|
||||||
schemaCommand("check", $args);
|
|
||||||
}
|
|
||||||
|
|
||||||
?>
|
|
||||||
@@ -55,7 +55,7 @@ class System {
|
|||||||
foreach (glob(PATH_PLUGINS . "*") as $filename) {
|
foreach (glob(PATH_PLUGINS . "*") as $filename) {
|
||||||
$info = pathinfo($filename);
|
$info = pathinfo($filename);
|
||||||
if (array_key_exists("extension", $info) && (strcmp($info["extension"], "php") == 0)) {
|
if (array_key_exists("extension", $info) && (strcmp($info["extension"], "php") == 0)) {
|
||||||
$plugins[] = $info["basename"];
|
$plugins[] = basename($filename, ".php");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -690,15 +690,32 @@ class System {
|
|||||||
return $sContent;
|
return $sContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the system schema.
|
||||||
|
*
|
||||||
|
* @return schema content in an array
|
||||||
|
*/
|
||||||
|
public static function getSystemSchema() {
|
||||||
|
return System::getSchema(PATH_TRUNK . "workflow/engine/config/schema.xml");
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the schema for a plugin.
|
||||||
|
*
|
||||||
|
* @param string $pluginName name of the plugin
|
||||||
|
* @return $sContent
|
||||||
|
*/
|
||||||
|
public static function getPluginSchema($pluginName) {
|
||||||
|
return System::getSchema(PATH_PLUGINS . $pluginName . "/config/schema.xml");
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves a schema array from a file.
|
* Retrieves a schema array from a file.
|
||||||
*
|
*
|
||||||
* @param string $sSchemaFile schema filename
|
* @param string $sSchemaFile schema filename
|
||||||
* @param string $dbAdapter database adapter name
|
|
||||||
* @return $sContent
|
* @return $sContent
|
||||||
*/
|
*/
|
||||||
public static function getSchema() {
|
public static function getSchema($sSchemaFile) {
|
||||||
$sSchemaFile = PATH_TRUNK . "workflow/engine/config/schema.xml";
|
|
||||||
$dbAdapter = "mysql";
|
$dbAdapter = "mysql";
|
||||||
$aSchema = array();
|
$aSchema = array();
|
||||||
$oXml = new DomDocument();
|
$oXml = new DomDocument();
|
||||||
|
|||||||
@@ -301,7 +301,19 @@ class workspaceTools {
|
|||||||
// end of reset
|
// end of reset
|
||||||
}
|
}
|
||||||
|
|
||||||
public function upgradeDatabase($checkOnly = false) {
|
public function upgradePluginsDatabase() {
|
||||||
|
foreach (System::getPlugins() as $pluginName) {
|
||||||
|
$pluginSchema = System::getPluginSchema($pluginName);
|
||||||
|
$this->upgradeSchema($pluginSchema);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public function upgradeDatabase($checkOnly) {
|
||||||
|
$systemSchema = System::getSystemSchema();
|
||||||
|
return $this->upgradeSchema($systemSchema);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function upgradeSchema($schema, $checkOnly = false) {
|
||||||
$dbInfo = $this->getDBInfo();
|
$dbInfo = $this->getDBInfo();
|
||||||
|
|
||||||
if (strcmp($dbInfo["DB_ADAPTER"], "mysql") != 0) {
|
if (strcmp($dbInfo["DB_ADAPTER"], "mysql") != 0) {
|
||||||
|
|||||||
Reference in New Issue
Block a user