Add upgrade/migration script for new style format.
authorMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 16 Sep 2010 22:17:38 +0000 (18:17 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 16 Sep 2010 22:17:38 +0000 (18:17 -0400)
Run this after the db migration is run. Do not remove or change
anything in the config/styles.php before this is run.

ansel/scripts/upgrades/2010-09-16_migrate_styles.php [new file with mode: 0644]

diff --git a/ansel/scripts/upgrades/2010-09-16_migrate_styles.php b/ansel/scripts/upgrades/2010-09-16_migrate_styles.php
new file mode 100644 (file)
index 0000000..b698fb0
--- /dev/null
@@ -0,0 +1,45 @@
+#!/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>
+ */
+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) {
+    if ($row[1] == 'ansel_default') {
+        $newStyle = '';
+    } else {
+        $properties = array_merge($defaults, $styles[$row[1]]);
+        unset($properties['requires_png']);
+        unset($properties['name']);
+        unset($properties['title']);
+        unset($properties['hide']);
+        $newStyle = serialize(new Ansel_Style($properties));
+    }
+    $update->execute(array($newStyle, $row[0]));
+}
+$cli->message('Gallery styles successfully migrated.', 'cli.success');