Added support to upgrade plugins database.

This commit is contained in:
Alexandre Rosenfeld
2010-12-17 14:35:56 +00:00
parent cc93331656
commit a0a53ef23b
5 changed files with 48 additions and 144 deletions

View File

@@ -10,6 +10,8 @@ pake_task('cacheview-upgrade');
pake_task('database-upgrade');
pake_task('database-check');
pake_task('plugins-database-upgrade');
pake_task('database-export');
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) {
G::LoadSystem('dbMaintenance');
if (count($args) < 2)

View File

@@ -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";
}
?>

View File

@@ -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);
}
?>

View File

@@ -55,7 +55,7 @@ class System {
foreach (glob(PATH_PLUGINS . "*") as $filename) {
$info = pathinfo($filename);
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;
}
/**
* 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.
*
* @param string $sSchemaFile schema filename
* @param string $dbAdapter database adapter name
* @return $sContent
*/
public static function getSchema() {
$sSchemaFile = PATH_TRUNK . "workflow/engine/config/schema.xml";
public static function getSchema($sSchemaFile) {
$dbAdapter = "mysql";
$aSchema = array();
$oXml = new DomDocument();

View File

@@ -301,7 +301,19 @@ class workspaceTools {
// 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();
if (strcmp($dbInfo["DB_ADAPTER"], "mysql") != 0) {