Add debug output, check for previously run migration.
authorMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 23 Sep 2010 16:30:01 +0000 (12:30 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 23 Sep 2010 16:30:01 +0000 (12:30 -0400)
Set $debug = true at the top of the file to get some debug output.
Script will skip any shares that look like they have already been migrated also.

ansel/scripts/upgrades/2010-09-16_migrate_styles.php

index c43b589..4912ea6 100644 (file)
@@ -7,6 +7,7 @@
  *
  * @author Michael J. Rubinsky <mrubinsk@horde.org>
  */
+$debug = false;
 require_once dirname(__FILE__) . '/../../lib/Application.php';
 Horde_Registry::appInit('ansel', array('authentication' => 'none', 'cli' => true));
 
@@ -30,6 +31,11 @@ $defaults = 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 {
@@ -40,6 +46,12 @@ foreach ($rows as $row) {
         unset($properties['hide']);
         $newStyle = serialize(new Ansel_Style($properties));
     }
-    $update->execute(array($newStyle, $row[0]));
+    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');