{
public function up()
{
+ $GLOBALS['registry']->pushApp('ansel');
$this->changeColumn('ansel_shares', 'attribute_style', 'text');
// Create: ansel_hashes
- $t = $this->createTable('ansel_hashes', array('primaryKey' => 'style_hash'));
- $t->column('style_hash', 'string', array('limit' => 255));
- $t->end();
+ $tableList = $this->tables();
+ if (!in_array('ansel_hashes', $tableList)) {
+ $t = $this->createTable('ansel_hashes', array('primaryKey' => 'style_hash'));
+ $t->column('style_hash', 'string', array('limit' => 255));
+ $t->end();
+ }
+
+ // 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()));
+
+ $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[0] . ', 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');
+
+ try {
+ $this->_connection->execute($update, array($newStyle, $row['attribute_style']));
+ } catch (Horde_Db_Exception $e) {
+ $this->announce('ERROR: ' . $e->getMessage());
+ }
+ }
}
public function down()
$this->dropTable('ansel_hashes');
}
+ /**
+ * Translates old style array from Ansel 1.x to Ansel 2.x.
+ *
+ * @param array $properties
+ */
+ private function _translate_generators($properties)
+ {
+ $thumb_map = array(
+ 'thumb' => 'Thumb',
+ 'prettythumb' => 'RoundedThumb',
+ 'shadowsharpthumb' => 'ShadowThumb',
+ 'polaroidthumb' => 'PolaroidThumb');
+
+ // Make sure we didn't already translate
+ if (!empty($thumb_map[$properties['thumbstyle']])) {
+ $properties['thumbstyle'] = $thumb_map[$properties['thumbstyle']];
+ unset($properties['requires_png']);
+ unset($properties['name']);
+ unset($properties['title']);
+ unset($properties['hide']);
+ unset($properties['default_galleryimage_type']);
+ }
+ return $properties;
+ }
+
}
\ No newline at end of file
+++ /dev/null
-#!/usr/bin/env php
-<?php
-/**
- * Script for migrating Ansel 1.x styles to the new style object in Ansel 2.
- * This script should be run *after* the migration has run for the schema, but
- * before users are allowed to log back in.
- *
- * @author Michael J. Rubinsky <mrubinsk@horde.org>
- */
-
-/**
- * Translates old style array from Ansel 1.x to Ansel 2.x.
- *
- * @param array $properties
- */
-function translate_generators($properties)
-{
- $thumb_map = array(
- 'thumb' => 'Thumb',
- 'prettythumb' => 'RoundedThumb',
- 'shadowsharpthumb' => 'ShadowThumb',
- 'polaroidthumb' => 'PolaroidThumb');
-
- $properties['thumbstyle'] = $thumb_map[$properties['thumbstyle']];
- unset($properties['requires_png']);
- unset($properties['name']);
- unset($properties['title']);
- unset($properties['hide']);
- unset($properties['default_galleryimage_type']);
-
- return $properties;
-}
-
-$debug = false;
-require_once dirname(__FILE__) . '/../../lib/Application.php';
-Horde_Registry::appInit('ansel', array('authentication' => 'none', 'cli' => true));
-
-// Make sure we have the full styles array.
-require ANSEL_BASE . '/config/styles.php';
-
-$sql = 'SELECT share_id, attribute_style FROM ansel_shares';
-$cli->message('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 = $ansel_db->queryAll($sql);
-$update = $ansel_db->prepare('UPDATE ansel_shares SET attribute_style=? WHERE share_id=?;');
-foreach ($rows as $row) {
- // Make sure we haven't already migrated
- if (@unserialize($row[1]) instanceof Ansel_Style) {
- $cli->message('Skipping share ' . $row[0] . ', already migrated.', 'cli.message');
- continue;
- }
- if (empty($styles[$row[1]])) {
- $newStyle = '';
- } else {
- $properties = array_merge($defaults, $styles[$row[1]]);
-
- // Translate previous generator names:
- $properties = translate_generators($properties);
-
- $newStyle = serialize(new Ansel_Style($properties));
- }
- if ($debug) {
- $cli->message('Migrating share id: ' . $row[0] . ' from: ' . $row[1] . ' to: ' . $newStyle, 'cli.message');
- }
- $results = $update->execute(array($newStyle, $row[0]));
- if ($results instanceof PEAR_Error) {
- $cli->message($results->getMessage(), 'cli.error');
- }
-}
-$cli->message('Gallery styles successfully migrated.', 'cli.success');