From: Ben Klang Date: Sat, 3 Apr 2010 01:58:20 +0000 (-0400) Subject: Shout: Clean up menu <-> number associations on delete X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=42447a3b75a97b09a414d3c4bf089d17004f1c09;p=horde.git Shout: Clean up menu <-> number associations on delete --- diff --git a/shout/lib/Driver/Sql.php b/shout/lib/Driver/Sql.php index dc6d3e755..23283e3a8 100644 --- a/shout/lib/Driver/Sql.php +++ b/shout/lib/Driver/Sql.php @@ -167,6 +167,19 @@ class Shout_Driver_Sql extends Shout_Driver public function deleteMenu($account, $menu) { + // Disassociate any numbers that were previously associated + $sql = 'UPDATE numbers SET menu_id = 1 WHERE ' . + '(SELECT id FROM menus WHERE name = ? AND account_id = ' . + '(SELECT id FROM accounts WHERE code = ?))'; + $values = array($menu, $account); + $msg = 'SQL query in Shout_Driver_Sql#deleteMenu(): ' . $sql; + Horde::logMessage($msg, 'DEBUG'); + $result = $this->_write_db->query($sql, $values); + if ($result instanceof PEAR_Error) { + throw new Shout_Exception($result); + } + + // Remove any associated menu entries $sql = 'DELETE FROM menu_entries WHERE menu_id = ' . '(SELECT id FROM menus WHERE name = ? AND account_id = ' . '(SELECT id FROM accounts WHERE code = ?))'; @@ -178,6 +191,7 @@ class Shout_Driver_Sql extends Shout_Driver throw new Shout_Exception($result); } + // Finally, remove the menu itself. $sql = 'DELETE FROM menus WHERE name = ? AND account_id = ' . '(SELECT id FROM accounts WHERE code = ?)'; $values = array($menu, $account);