MFB: Fix sequence name, catch errors.
authorJan Schneider <jan@horde.org>
Mon, 20 Jul 2009 12:24:42 +0000 (14:24 +0200)
committerJan Schneider <jan@horde.org>
Mon, 20 Jul 2009 12:24:42 +0000 (14:24 +0200)
ingo/scripts/upgrades/convert_datatree_shares_to_sql.php
kronolith/scripts/upgrades/convert_datatree_shares_to_sql.php
turba/scripts/upgrades/convert_datatree_shares_to_sql.php

index 73ad514..89816eb 100755 (executable)
@@ -24,6 +24,7 @@ require_once 'MDB2.php';
 $config = $GLOBALS['conf']['sql'];
 unset($config['charset']);
 $db = MDB2::factory($config);
+$db->setOption('seqcol_name', 'id');
 
 $error_cnt = 0;
 $delete_dt_data = false;
@@ -37,23 +38,26 @@ if ($answer != 'y') {
 }
 
 /* Get the share entries */
-$sql = 'SELECT datatree_id, datatree_name FROM horde_datatree WHERE '
-    . 'group_uid = \'horde.shares.ingo\'';
-$shares_result = $db->query($sql);
+$shares_result = $db->query('SELECT datatree_id, datatree_name FROM horde_datatree WHERE group_uid = \'horde.shares.ingo\'');
 if (is_a($shares_result, 'PEAR_Error')) {
     die($shares_result->toString());
 }
 
+$query = $db->prepare('SELECT attribute_name, attribute_key, attribute_value FROM horde_datatree_attributes WHERE datatree_id = ?');
 while ($row = $shares_result->fetchRow(MDB2_FETCHMODE_ASSOC)) {
     $share_id = $row['datatree_id'];
     $share_name = $row['datatree_name'];
 
     /* Build an array to hold the new row data */
-    $data = array('share_id' => $db->nextId('ingo_shares'),
+    $nextId = $db->nextId('ingo_shares');
+    if (is_a($nextId, 'PEAR_Error')) {
+        $cli->message($nextId->toString(), 'cli.error');
+        $error_cnt++;
+        continue;
+    }
+    $data = array('share_id' => $nextId,
                   'share_name' => $share_name);
 
-    $sql = 'SELECT attribute_name, attribute_key, attribute_value FROM horde_datatree_attributes WHERE datatree_id = ?';
-    $query = $db->prepare($sql);
     $query_result = $query->execute($share_id);
     $rows = $query_result->fetchAll(MDB2_FETCHMODE_ASSOC);
     $users = array();
index ff3f48a..bdd845c 100755 (executable)
@@ -23,6 +23,7 @@ require_once HORDE_BASE . '/config/conf.php';
 $config = $GLOBALS['conf']['sql'];
 unset($config['charset']);
 $db = MDB2::factory($config);
+$db->setOption('seqcol_name', 'id');
 
 $error_cnt = 0;
 $delete_dt_data = false;
@@ -36,23 +37,26 @@ if ($answer != 'y') {
 }
 
 /* Get the share entries */
-$sql = 'SELECT datatree_id, datatree_name FROM horde_datatree WHERE '
-    . 'group_uid = \'horde.shares.kronolith\'';
-$shares_result = $db->query($sql);
+$shares_result = $db->query('SELECT datatree_id, datatree_name FROM horde_datatree WHERE group_uid = \'horde.shares.kronolith\'');
 if (is_a($shares_result, 'PEAR_Error')) {
     die($shares_result->toString());
 }
 
+$query = $db->prepare('SELECT attribute_name, attribute_key, attribute_value FROM horde_datatree_attributes WHERE datatree_id = ?');
 while ($row = $shares_result->fetchRow(MDB2_FETCHMODE_ASSOC)) {
     $share_id = $row['datatree_id'];
     $share_name = $row['datatree_name'];
 
     /* Build an array to hold the new row data */
-    $data = array('share_id' => $db->nextId('kronolith_shares'),
+    $nextId = $db->nextId('kronolith_shares');
+    if (is_a($nextId, 'PEAR_Error')) {
+        $cli->message($nextId->toString(), 'cli.error');
+        $error_cnt++;
+        continue;
+    }
+    $data = array('share_id' => $nextId,
                   'share_name' => $share_name);
 
-    $sql = 'SELECT attribute_name, attribute_key, attribute_value FROM horde_datatree_attributes WHERE datatree_id = ?';
-    $query = $db->prepare($sql);
     $query_result = $query->execute($share_id);
     $rows = $query_result->fetchAll(MDB2_FETCHMODE_ASSOC);
     $users = array();
index 6a11185..2ff26b3 100755 (executable)
@@ -25,6 +25,7 @@ require_once 'MDB2.php';
 $config = $GLOBALS['conf']['sql'];
 unset($config['charset']);
 $db = MDB2::factory($config);
+$db->setOption('seqcol_name', 'id');
 
 $error_cnt = 0;
 $delete_dt_data = false;
@@ -38,23 +39,26 @@ if ($answer != 'y') {
 }
 
 /* Get the share entries */
-$sql = 'SELECT datatree_id, datatree_name FROM horde_datatree WHERE '
-    . 'group_uid = \'horde.shares.turba\'';
-$shares_result = $db->query($sql);
+$shares_result = $db->query('SELECT datatree_id, datatree_name FROM horde_datatree WHERE group_uid = \'horde.shares.turba\'');
 if (is_a($shares_result, 'PEAR_Error')) {
     die($shares_result->toString());
 }
 
+$query = $db->prepare('SELECT attribute_name, attribute_key, attribute_value FROM horde_datatree_attributes WHERE datatree_id = ?');
 while ($row = $shares_result->fetchRow(MDB2_FETCHMODE_ASSOC)) {
     $share_id = $row['datatree_id'];
     $share_name = $row['datatree_name'];
 
     /* Build an array to hold the new row data */
-    $data = array('share_id' => $db->nextId('turba_shares'),
+    $nextId = $db->nextId('turba_shares');
+    if (is_a($nextId, 'PEAR_Error')) {
+        $cli->message($nextId->toString(), 'cli.error');
+        $error_cnt++;
+        continue;
+    }
+    $data = array('share_id' => $nextId,
                   'share_name' => $share_name);
 
-    $sql = 'SELECT attribute_name, attribute_key, attribute_value FROM horde_datatree_attributes WHERE datatree_id = ?';
-    $query = $db->prepare($sql);
     $query_result = $query->execute($share_id);
     $rows = $query_result->fetchAll(MDB2_FETCHMODE_ASSOC);
     $users = array();