Add update script for moving deprecated gallery categories to the tag system
authorMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 16 Sep 2010 21:45:08 +0000 (17:45 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 16 Sep 2010 21:45:08 +0000 (17:45 -0400)
ansel/scripts/upgrades/2010-09-16_migrate_categories_to_tags.php [new file with mode: 0644]

diff --git a/ansel/scripts/upgrades/2010-09-16_migrate_categories_to_tags.php b/ansel/scripts/upgrades/2010-09-16_migrate_categories_to_tags.php
new file mode 100644 (file)
index 0000000..baca56b
--- /dev/null
@@ -0,0 +1,23 @@
+#!/usr/bin/env php
+<?php
+/**
+ * Script for migrating Ansel 1.x categories to the tags system in Ansel 2.
+ * This script should be run *after* tags are migrated to content/.
+ *
+ * @author Michael J. Rubinsky <mrubinsk@horde.org>
+ */
+require_once dirname(__FILE__) . '/../../lib/Application.php';
+Horde_Registry::appInit('ansel', array('authentication' => 'none', 'cli' => true));
+
+/* Gallery tags */
+$sql = 'SELECT share_id, attribute_category, share_owner FROM ansel_shares';
+
+// Maybe iterate over results and aggregate them by user and gallery so we can
+// tag all tags for a single gallery at once. Probably not worth it for a one
+// time upgrade script.
+$cli->message('Migrating gallery categories.', 'cli.message');
+$rows = $ansel_db->queryAll($sql);
+foreach ($rows as $row) {
+    $GLOBALS['injector']->getInstance('Ansel_Tagger')->tag($row[0], $row[1], $row[2], 'gallery');
+}
+$cli->message('Gallery categories successfully migrated.', 'cli.success');