{
public function up()
{
- $GLOBALS['registry']->pushApp('ansel');
+ $tableList = $this->tables();
+ if (in_array('ansel_galleries_tags', $tableList)) {
+ $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;';
+ /* 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');
+ // 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->selectAll($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->selectAll($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.');
+
+ $this->announce('Dropping ansel tag tables');
+ $this->dropTable('ansel_galleries_tags');
+ $this->dropTable('ansel_images_tags');
+ $this->dropTable('ansel_tags');
+ } else {
+ $this->announce('Tags ALREADY migrated to content system.');
}
- $this->announce('Image tags finished.');
}
public function down()
--- /dev/null
+<?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 AnselUpgradeCategoriesToTags extends Horde_Db_Migration_Base
+{
+ public function up()
+ {
+ $GLOBALS['registry']->pushApp('ansel');
+
+ /* Gallery tags */
+ $t = $this->_connection->table('ansel_shares');
+ $cols = $t->getColumns();
+ if (in_array('attribute_category', array_keys($cols))) {
+ $sql = 'SELECT share_id, attribute_category, share_owner FROM ansel_shares';
+ $this->announce('Migrating gallery categories.');
+ $rows = $this->_connection->selectAll($sql);
+ foreach ($rows as $row) {
+ $GLOBALS['injector']->getInstance('Ansel_Tagger')->tag($row['share_id'], $row['attribute_category'], $row['share_owner'], 'gallery');
+ }
+ $this->announce('Gallery categories successfully migrated.');
+ $this->removeColumn('ansel_shares', 'attribute_category');
+ } else {
+ $this->announce('Gallery categories ALREADY migrated.');
+ }
+ }
+
+ public function down()
+ {
+ // Not supported, no way to tell which tags were categories.
+ }
+
+}
\ No newline at end of file
+++ /dev/null
-#!/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');