Catch exceptions from Horde_Db
authorMichael J. Rubinsky <mrubinsk@horde.org>
Wed, 8 Sep 2010 20:59:06 +0000 (16:59 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Wed, 8 Sep 2010 20:59:06 +0000 (16:59 -0400)
content/lib/Objects/Manager.php
content/lib/Types/Manager.php
content/lib/Users/Manager.php

index e9add4c..d1f6b54 100644 (file)
@@ -67,9 +67,13 @@ class Content_Objects_Manager
         $params = $objects;
         $params[] = $type;
 
-        $ids = $this->_db->selectAssoc('SELECT object_id, object_name FROM ' . $this->_t('objects') . ' WHERE object_name IN (' . str_repeat('?,', count($objects) - 1) . '?)' . ' AND type_id = ?', $params);
-        if ($ids) {
-            return $ids;
+        try {
+            $ids = $this->_db->selectAssoc('SELECT object_id, object_name FROM ' . $this->_t('objects') . ' WHERE object_name IN (' . str_repeat('?,', count($objects) - 1) . '?)' . ' AND type_id = ?', $params);
+            if ($ids) {
+                return $ids;
+            }
+        } catch (Horde_Db_Exception $e) {
+            throw new Content_Exception($e);
         }
 
         return false;
@@ -107,20 +111,24 @@ class Content_Objects_Manager
         }
 
         // Get the ids for any objects that already exist.
-        if (count($objectName)) {
-            foreach ($this->_db->selectAll('SELECT object_id, object_name FROM ' . $this->_t('objects')
-                     . ' WHERE object_name IN (' . implode(',', array_map(array($this->_db, 'quote'), array_keys($objectName)))
-                     . ') AND type_id = ' . $type) as $row) {
-
-                $objectIndex = $objectName[$row['object_name']];
-                unset($objectName[$row['object_name']]);
-                $objectIds[$objectIndex] = $row['object_id'];
+        try {
+            if (count($objectName)) {
+                foreach ($this->_db->selectAll('SELECT object_id, object_name FROM ' . $this->_t('objects')
+                         . ' WHERE object_name IN (' . implode(',', array_map(array($this->_db, 'quote'), array_keys($objectName)))
+                         . ') AND type_id = ' . $type) as $row) {
+
+                    $objectIndex = $objectName[$row['object_name']];
+                    unset($objectName[$row['object_name']]);
+                    $objectIds[$objectIndex] = $row['object_id'];
+                }
             }
-        }
 
-        // Create any objects that didn't already exist
-        foreach ($objectName as $object => $objectIndex) {
-            $objectIds[$objectIndex] = $this->_db->insert('INSERT INTO ' . $this->_t('objects') . ' (object_name, type_id) VALUES (' . $this->_db->quote($object) . ', ' . $type . ')');
+            // Create any objects that didn't already exist
+            foreach ($objectName as $object => $objectIndex) {
+                $objectIds[$objectIndex] = $this->_db->insert('INSERT INTO ' . $this->_t('objects') . ' (object_name, type_id) VALUES (' . $this->_db->quote($object) . ', ' . $type . ')');
+            }
+        } catch (Horde_Db_Exception $e) {
+            throw new Content_Exception($e);
         }
 
         return $objectIds;
index 7436a6a..317e7b7 100644 (file)
@@ -64,18 +64,22 @@ class Content_Types_Manager
             }
         }
 
-        // Get the ids for any types that already exist.
-        if (count($typeName)) {
-            foreach ($this->_db->selectAssoc('SELECT type_id, type_name FROM ' . $this->_t('types') . ' WHERE type_name IN ('.implode(',', array_map(array($this->_db, 'quote'), array_keys($typeName))).')') as $id => $type) {
-                $typeIndex = $typeName[$type];
-                unset($typeName[$type]);
-                $typeIds[$typeIndex] = (int)$id;
+        try {
+            // Get the ids for any types that already exist.
+            if (count($typeName)) {
+                foreach ($this->_db->selectAssoc('SELECT type_id, type_name FROM ' . $this->_t('types') . ' WHERE type_name IN ('.implode(',', array_map(array($this->_db, 'quote'), array_keys($typeName))).')') as $id => $type) {
+                    $typeIndex = $typeName[$type];
+                    unset($typeName[$type]);
+                    $typeIds[$typeIndex] = (int)$id;
+                }
             }
-        }
 
-        // Create any types that didn't already exist
-        foreach ($typeName as $type => $typeIndex) {
-            $typeIds[$typeIndex] = $this->_db->insert('INSERT INTO ' . $this->_t('types') . ' (type_name) VALUES (' . $this->_db->quote($type) . ')');
+            // Create any types that didn't already exist
+            foreach ($typeName as $type => $typeIndex) {
+                $typeIds[$typeIndex] = $this->_db->insert('INSERT INTO ' . $this->_t('types') . ' (type_name) VALUES (' . $this->_db->quote($type) . ')');
+            }
+        } catch (Horde_Db_Exception $e) {
+            throw new Content_Exception($e);
         }
 
         return $typeIds;
index 1c6c86d..2d8fde4 100644 (file)
@@ -65,17 +65,21 @@ class Content_Users_Manager
         }
 
         // Get the ids for any users that already exist.
-        if (count($userName)) {
-            foreach ($this->_db->selectAll('SELECT user_id, user_name FROM ' . $this->_t('users') . ' WHERE user_name IN ('.implode(',', array_map(array($this->_db, 'quote'), array_keys($userName))).')') as $row) {
-                $userIndex = $userName[$row['user_name']];
-                unset($userName[$row['user_name']]);
-                $userIds[$userIndex] = $row['user_id'];
+        try {
+            if (count($userName)) {
+                foreach ($this->_db->selectAll('SELECT user_id, user_name FROM ' . $this->_t('users') . ' WHERE user_name IN ('.implode(',', array_map(array($this->_db, 'quote'), array_keys($userName))).')') as $row) {
+                    $userIndex = $userName[$row['user_name']];
+                    unset($userName[$row['user_name']]);
+                    $userIds[$userIndex] = $row['user_id'];
+                }
             }
-        }
 
-        // Create any users that didn't already exist
-        foreach ($userName as $user => $userIndex) {
-            $userIds[$userIndex] = $this->_db->insert('INSERT INTO ' . $this->_t('users') . ' (user_name) VALUES (' . $this->_db->quote($user) . ')');
+            // Create any users that didn't already exist
+            foreach ($userName as $user => $userIndex) {
+                $userIds[$userIndex] = $this->_db->insert('INSERT INTO ' . $this->_t('users') . ' (user_name) VALUES (' . $this->_db->quote($user) . ')');
+            }
+        } catch (Horde_Db_Exception $e) {
+            throw new Content_Exception($e);
         }
 
         return $userIds;