public function up()
{
$this->changeColumn('ansel_shares', 'attribute_style', 'text');
// Create: ansel_hashes
$t = $this->createTable('ansel_hashes', array('autoincrementKey' => false));
$t->column('style_hash', 'string', array('limit' => 255));
$t->primaryKey(array('style_hash'));
$t->end();
$styles = Horde::loadConfiguration('styles.php', 'styles', 'ansel');
// 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->select($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');
try {
$this->_connection->execute($update, array($newStyle, $row['share_id']));
} catch (Horde_Db_Exception $e) {
$this->announce('ERROR: ' . $e->getMessage());
}
}
}