Add tag->content migration, remove old upgrade script
authorMichael J. Rubinsky <mrubinsk@horde.org>
Wed, 6 Oct 2010 15:06:34 +0000 (11:06 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Wed, 6 Oct 2010 15:30:08 +0000 (11:30 -0400)
ansel/migration/4_ansel_upgrade_tagstocontent.php [new file with mode: 0644]
ansel/scripts/upgrades/2010-07-30_migrate_tags_to_content.php [deleted file]

diff --git a/ansel/migration/4_ansel_upgrade_tagstocontent.php b/ansel/migration/4_ansel_upgrade_tagstocontent.php
new file mode 100644 (file)
index 0000000..07340ae
--- /dev/null
@@ -0,0 +1,52 @@
+<?php
+/**
+ * Move tags from ansel to content storage.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @author   Michael J. Rubinsky <mrubinsk@horde.org>
+ * @category Horde
+ * @license  http://www.fsf.org/copyleft/gpl.html GPL
+ * @package  Ansel
+ */
+class AnselUpgradeTagsToContent extends Horde_Db_Migration_Base
+{
+    public function up()
+    {
+        $GLOBALS['registry']->pushApp('ansel');
+
+        /* Gallery tags */
+        $sql = 'SELECT gallery_id, tag_name, share_owner FROM ansel_shares RIGHT JOIN '
+            . 'ansel_galleries_tags ON ansel_shares.share_id = ansel_galleries_tags.gallery_id '
+            . 'LEFT JOIN ansel_tags ON ansel_tags.tag_id = ansel_galleries_tags.tag_id;';
+
+        // 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.
+        $this->announce('Migrating gallery tags. This may take a while.');
+        $rows = $this->_connection->selectAssoc($sql);
+        foreach ($rows as $row) {
+            $GLOBALS['injector']->getInstance('Ansel_Tagger')->tag($row['gallery_id'], $row['tag_name'], $row['share_owner'], 'gallery');
+        }
+        $this->announce('Gallery tags finished.');
+        $sql = 'SELECT ansel_images.image_id iid, tag_name, share_owner FROM ansel_images '
+            . 'RIGHT JOIN ansel_images_tags ON ansel_images.image_id = ansel_images_tags.image_id '
+            . 'LEFT JOIN ansel_shares ON ansel_shares.share_id = ansel_images.gallery_id '
+            . 'LEFT JOIN ansel_tags ON ansel_tags.tag_id = ansel_images_tags.tag_id';
+        $this->announce('Migrating image tags. This may take even longer...');
+        $rows = $this->_connection->selectAssoc($sql);
+        foreach ($rows as $row) {
+            $GLOBALS['injector']->getInstance('Ansel_Tagger')->tag($row['iid'], $row['tag_name'], $row['share_owner'], 'image');
+        }
+        $this->announce('Image tags finished.');
+    }
+
+    public function down()
+    {
+        // TODO
+    }
+
+}
\ No newline at end of file
diff --git a/ansel/scripts/upgrades/2010-07-30_migrate_tags_to_content.php b/ansel/scripts/upgrades/2010-07-30_migrate_tags_to_content.php
deleted file mode 100755 (executable)
index d46c562..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-#!/usr/bin/env php
-<?php
-/**
- * Script for migrating Ansel 1.x tags to the Content_Tagger system in Ansel 2.
- *
- * Warning: This script may take a LONG time, depending on the number of users
- * and images.
- *
- * @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 gallery_id, tag_name, share_owner FROM ansel_shares RIGHT JOIN '
-    . 'ansel_galleries_tags ON ansel_shares.share_id = ansel_galleries_tags.gallery_id '
-    . 'LEFT JOIN ansel_tags ON ansel_tags.tag_id = ansel_galleries_tags.tag_id;';
-
-// 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 tags. This may take a while.', '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 tags finished.', 'cli.success');
-
-$sql = 'SELECT ansel_images.image_id, tag_name, share_owner FROM ansel_images '
-    . 'RIGHT JOIN ansel_images_tags ON ansel_images.image_id = ansel_images_tags.image_id '
-    . 'LEFT JOIN ansel_shares ON ansel_shares.share_id = ansel_images.gallery_id '
-    . 'LEFT JOIN ansel_tags ON ansel_tags.tag_id = ansel_images_tags.tag_id';
-$cli->message('Migrating image tags. This may take even longer...', 'cli.message');
-$rows = $ansel_db->queryAll($sql);
-foreach ($rows as $row) {
-    $GLOBALS['injector']->getInstance('Ansel_Tagger')->tag($row[0], $row[1], $row[2], 'image');
-}
-$cli->message('Image tags finished.', 'cli.success');
-