diff --git a/workflow/engine/bin/tasks/cliWorkspaces.php b/workflow/engine/bin/tasks/cliWorkspaces.php index 836744c64..38fc10699 100644 --- a/workflow/engine/bin/tasks/cliWorkspaces.php +++ b/workflow/engine/bin/tasks/cliWorkspaces.php @@ -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) diff --git a/workflow/engine/bin/tasks/cmdDrafts.php b/workflow/engine/bin/tasks/cmdDrafts.php deleted file mode 100644 index b5f4b7e10..000000000 --- a/workflow/engine/bin/tasks/cmdDrafts.php +++ /dev/null @@ -1,90 +0,0 @@ -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"; -} -?> diff --git a/workflow/engine/bin/tasks/cmdSchema.php b/workflow/engine/bin/tasks/cmdSchema.php deleted file mode 100644 index f34d2b953..000000000 --- a/workflow/engine/bin/tasks/cmdSchema.php +++ /dev/null @@ -1,49 +0,0 @@ -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); -} - -?> \ No newline at end of file diff --git a/workflow/engine/classes/class.system.php b/workflow/engine/classes/class.system.php index c284026dd..4f2e73190 100755 --- a/workflow/engine/classes/class.system.php +++ b/workflow/engine/classes/class.system.php @@ -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(); diff --git a/workflow/engine/classes/class.wsTools.php b/workflow/engine/classes/class.wsTools.php index a1106afee..e548c8fec 100644 --- a/workflow/engine/classes/class.wsTools.php +++ b/workflow/engine/classes/class.wsTools.php @@ -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) {