Add script for later migration of share data.
authorJan Schneider <jan@horde.org>
Thu, 20 Jan 2011 18:09:20 +0000 (19:09 +0100)
committerJan Schneider <jan@horde.org>
Thu, 20 Jan 2011 18:09:20 +0000 (19:09 +0100)
kronolith/scripts/upgrades/convert_sql_shares_to_sqlng.php [new file with mode: 0755]

diff --git a/kronolith/scripts/upgrades/convert_sql_shares_to_sqlng.php b/kronolith/scripts/upgrades/convert_sql_shares_to_sqlng.php
new file mode 100755 (executable)
index 0000000..fcfb0dc
--- /dev/null
@@ -0,0 +1,31 @@
+#!/usr/bin/env php
+<?php
+/**
+ * This script migrates Kronolith's share data from the SQL Horde_Share
+ * driver to the next-generation SQL Horde_Share driver.
+ *
+ * It is supposed to run at any time after migrating Kronolith to the latest DB
+ * schema version. The schema migration already migrates the data once, but
+ * this script can be used to migrate the data again, e.g. if starting to use
+ * the NG driver at a later time.
+ */
+
+/* Set up the CLI environment */
+require_once dirname(__FILE__) . '/../../lib/Application.php';
+Horde_Registry::appInit('kronolith', array('authentication' => 'none', 'cli' => true));
+
+require_once dirname(__FILE__) . '/../../migration/15_kronolith_upgrade_sqlng.php';
+
+$db = $injector->getInstance('Horde_Db_Adapter');
+$migration = new KronolithUpgradeSqlng($db);
+$cli = new Horde_Cli();
+
+$delete = $cli->prompt('Delete existing shares from the NEW backend before migrating the OLD backend? This should be done to avoid duplicate entries or primary key collisions in the storage backend from earlier migrations.', array('y' => 'Yes', 'n' => 'No'), 'n');
+
+if ($delete == 'y' || $delete == 'Y') {
+    $db->delete('DELETE FROM kronolith_sharesng');
+    $db->delete('DELETE FROM kronolith_sharesng_users');
+    $db->delete('DELETE FROM kronolith_sharesng_groups');
+}
+
+$migration->dataUp();