From 7424c03791df77f8c4af4b76e9aba584d1069c77 Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Wed, 8 Sep 2010 16:59:06 -0400 Subject: [PATCH] Catch exceptions from Horde_Db --- content/lib/Objects/Manager.php | 38 +++++++++++++++++++++++--------------- content/lib/Types/Manager.php | 24 ++++++++++++++---------- content/lib/Users/Manager.php | 22 +++++++++++++--------- 3 files changed, 50 insertions(+), 34 deletions(-) diff --git a/content/lib/Objects/Manager.php b/content/lib/Objects/Manager.php index e9add4c97..d1f6b5402 100644 --- a/content/lib/Objects/Manager.php +++ b/content/lib/Objects/Manager.php @@ -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; diff --git a/content/lib/Types/Manager.php b/content/lib/Types/Manager.php index 7436a6a42..317e7b79d 100644 --- a/content/lib/Types/Manager.php +++ b/content/lib/Types/Manager.php @@ -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; diff --git a/content/lib/Users/Manager.php b/content/lib/Users/Manager.php index 1c6c86d5c..2d8fde4e5 100644 --- a/content/lib/Users/Manager.php +++ b/content/lib/Users/Manager.php @@ -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; -- 2.11.0