From: Michael J. Rubinsky Date: Wed, 6 Oct 2010 15:24:41 +0000 (-0400) Subject: Add category migration, remove old upgrade script, catch some errors if X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=6b8f3f18434e47e485271bcfa9891c8dd88585e2;p=horde.git Add category migration, remove old upgrade script, catch some errors if migration run after some of these updates were already applied. --- diff --git a/ansel/migration/3_ansel_upgrade_style.php b/ansel/migration/3_ansel_upgrade_style.php index e72fc5ad1..9f661adda 100644 --- a/ansel/migration/3_ansel_upgrade_style.php +++ b/ansel/migration/3_ansel_upgrade_style.php @@ -50,7 +50,7 @@ class AnselUpgradeStyle extends Horde_Db_Migration_Base foreach ($rows as $row) { // Make sure we haven't already migrated if (@unserialize($row['attribute_style']) instanceof Ansel_Style) { - $this->announce('Skipping share ' . $row[0] . ', already migrated.', 'cli.message'); + $this->announce('Skipping share ' . $row['attribute_style'] . ', already migrated.', 'cli.message'); continue; } if (empty($styles[$row['attribute_style']])) { diff --git a/ansel/migration/4_ansel_upgrade_tagstocontent.php b/ansel/migration/4_ansel_upgrade_tagstocontent.php index 07340ae38..1d6add04b 100644 --- a/ansel/migration/4_ansel_upgrade_tagstocontent.php +++ b/ansel/migration/4_ansel_upgrade_tagstocontent.php @@ -16,32 +16,42 @@ class AnselUpgradeTagsToContent extends Horde_Db_Migration_Base { 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() diff --git a/ansel/migration/5_ansel_upgrade_categoriestotags.php b/ansel/migration/5_ansel_upgrade_categoriestotags.php new file mode 100644 index 000000000..c92ba17fb --- /dev/null +++ b/ansel/migration/5_ansel_upgrade_categoriestotags.php @@ -0,0 +1,43 @@ + + * @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 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 deleted file mode 100644 index baca56bde..000000000 --- a/ansel/scripts/upgrades/2010-09-16_migrate_categories_to_tags.php +++ /dev/null @@ -1,23 +0,0 @@ -#!/usr/bin/env php - - */ -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');