From 0b767eec3c571a62accb018c0a58b90d88c96447 Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Wed, 6 Oct 2010 13:24:26 -0400 Subject: [PATCH] Don't assume styles.php is already generated. --- ansel/migration/3_ansel_upgrade_style.php | 76 ++++++++++++++++--------------- 1 file changed, 39 insertions(+), 37 deletions(-) diff --git a/ansel/migration/3_ansel_upgrade_style.php b/ansel/migration/3_ansel_upgrade_style.php index 59ffbc2c7..b714b327c 100644 --- a/ansel/migration/3_ansel_upgrade_style.php +++ b/ansel/migration/3_ansel_upgrade_style.php @@ -27,47 +27,49 @@ class AnselUpgradeStyle extends Horde_Db_Migration_Base $t->end(); } - // Make sure we have the full styles array. - require ANSEL_BASE . '/config/styles.php'; + if (file_exists(ANSEL_BASE . '/config/styles.php')) { + // Make sure we have the full styles array. + require ANSEL_BASE . '/config/styles.php'; - // Migrate existing data - $sql = 'SELECT share_id, attribute_style FROM ansel_shares'; - $this->announce('Migrating gallery styles.', 'cli.message'); - $defaults = array( - 'thumbstyle' => 'Thumb', - 'background' => 'none', - 'gallery_view' => 'Gallery', - 'widgets' => array( - 'Tags' => array('view' => 'gallery'), - 'OtherGalleries' => array(), - 'Geotag' => array(), - 'Links' => array(), - 'GalleryFaces' => array(), - 'OwnerFaces' => array())); + // Migrate existing data + $sql = 'SELECT share_id, attribute_style FROM ansel_shares'; + $this->announce('Migrating gallery styles.', 'cli.message'); + $defaults = array( + 'thumbstyle' => 'Thumb', + 'background' => 'none', + 'gallery_view' => 'Gallery', + 'widgets' => array( + 'Tags' => array('view' => 'gallery'), + 'OtherGalleries' => array(), + 'Geotag' => array(), + 'Links' => array(), + 'GalleryFaces' => array(), + 'OwnerFaces' => array())); - $rows = $this->_connection->selectAll($sql); - $update = 'UPDATE ansel_shares SET attribute_style=? WHERE share_id=?;'; - foreach ($rows as $row) { - // Make sure we haven't already migrated - if (@unserialize($row['attribute_style']) instanceof Ansel_Style) { - $this->announce('Skipping share ' . $row['attribute_style'] . ', already migrated.', 'cli.message'); - continue; - } - if (empty($styles[$row['attribute_style']])) { - $newStyle = ''; - } else { - $properties = array_merge($defaults, $styles[$row['attribute_style']]); + $rows = $this->_connection->selectAll($sql); + $update = 'UPDATE ansel_shares SET attribute_style=? WHERE share_id=?;'; + foreach ($rows as $row) { + // Make sure we haven't already migrated + if (@unserialize($row['attribute_style']) instanceof Ansel_Style) { + $this->announce('Skipping share ' . $row['attribute_style'] . ', already migrated.', 'cli.message'); + continue; + } + if (empty($styles[$row['attribute_style']])) { + $newStyle = ''; + } else { + $properties = array_merge($defaults, $styles[$row['attribute_style']]); - // Translate previous generator names: - $properties = $this->_translate_generators($properties); - $newStyle = serialize(new Ansel_Style($properties)); - } - $this->announce('Migrating share id: ' . $row['share_id'] . ' from: ' . $row['attribute_style'] . ' to: ' . $newStyle, 'cli.message'); + // Translate previous generator names: + $properties = $this->_translate_generators($properties); + $newStyle = serialize(new Ansel_Style($properties)); + } + $this->announce('Migrating share id: ' . $row['share_id'] . ' from: ' . $row['attribute_style'] . ' to: ' . $newStyle, 'cli.message'); - try { - $this->_connection->execute($update, array($newStyle, $row['attribute_style'])); - } catch (Horde_Db_Exception $e) { - $this->announce('ERROR: ' . $e->getMessage()); + try { + $this->_connection->execute($update, array($newStyle, $row['attribute_style'])); + } catch (Horde_Db_Exception $e) { + $this->announce('ERROR: ' . $e->getMessage()); + } } } } -- 2.11.0