From 24aa50f612552f775dc6c2054a8a61b0bbf95b88 Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Fri, 30 Apr 2010 12:06:39 +0200 Subject: [PATCH] MFB: Add option to delete individual ticket history entries. --- whups/docs/CHANGES | 2 +- whups/lib/Driver/sql.php | 80 +++++++++++++++++++++++++++++++++++++++++ whups/lib/Renderer/Comment.php | 14 +++++++- whups/ticket/delete_history.php | 33 +++++++++++++++++ 4 files changed, 127 insertions(+), 2 deletions(-) create mode 100644 whups/ticket/delete_history.php diff --git a/whups/docs/CHANGES b/whups/docs/CHANGES index e86ffb0d6..ff32d5bb8 100644 --- a/whups/docs/CHANGES +++ b/whups/docs/CHANGES @@ -9,7 +9,7 @@ v2.0-cvs v1.0.2-cvs ---------- - +[jan] Add option to delete individual ticket history entries. ------ diff --git a/whups/lib/Driver/sql.php b/whups/lib/Driver/sql.php index 3fca21e95..5357257da 100644 --- a/whups/lib/Driver/sql.php +++ b/whups/lib/Driver/sql.php @@ -1174,6 +1174,86 @@ class Whups_Driver_sql extends Whups_Driver { } /** + * Deletes all changes of a transaction. + * + * @param integer $transaction A transaction id. + */ + function deleteHistory($transaction) + { + $transaction = (int)$transaction; + + /* Deleting comments. */ + $query = 'SELECT log_value FROM whups_logs WHERE log_type = ? AND transaction_id = ?'; + $values = array('comment', $transaction); + Horde::logMessage( + sprintf('Whups_Driver_sql::deleteTransaction(): query="%s"; values="%s"', + $query, implode(',', $values)), 'DEBUG'); + $comments = $this->_db->getCol($query, 'log_value', $values); + if (is_a($comments, 'PEAR_Error')) { + Horde::logMessage($comments, 'ERR'); + return $comments; + } + + if ($comments) { + $query = sprintf('DELETE FROM whups_comments WHERE comment_id IN (%s)', + implode(',', $comments)); + Horde::logMessage( + sprintf('Whups_Driver_sql::deleteTransaction(): query="%s"', $query), 'DEBUG'); + $result = $this->_write_db->query($query); + if (is_a($result, 'PEAR_Error')) { + Horde::logMessage($result, 'ERR'); + return $result; + } + } + + /* Deleting attachments. */ + if (isset($GLOBALS['conf']['vfs']['type'])) { + $query = 'SELECT ticket_id, log_value FROM whups_logs WHERE log_type = ? AND transaction_id = ?'; + $values = array('attachment', $transaction); + Horde::logMessage( + sprintf('Whups_Driver_sql::deleteTransaction(): query="%s"; values="%s"', + $query, implode(',', $values)), 'DEBUG'); + $attachments = $this->_db->query($query, $values); + if (is_a($attachments, 'PEAR_Error')) { + Horde::logMessage($attachments, 'ERR'); + return $attachments; + } + require_once 'VFS.php'; + $vfs = &VFS::singleton($GLOBALS['conf']['vfs']['type'], + Horde::getDriverConfig('vfs')); + if (is_a($vfs, 'PEAR_Error')) { + return $vfs; + } + + while ($attachment = $attachments->fetchRow(DB_FETCHMODE_ASSOC)) { + $dir = WHUPS_VFS_ATTACH_PATH . '/' . $attachment['ticket_id']; + if ($vfs->exists($dir, $attachment['log_value'])) { + try { + $result = $vfs->deleteFile($dir, $attachment['log_value']); + } catch (VFS_Exception $e) { + return PEAR::raiseError($e->getMessage()); + } + } else { + Horde::logMessage(sprintf(_("Attachment %s not found."), + $attachment['log_value']), + 'WARN'); + } + } + } + + $query = 'DELETE FROM whups_logs WHERE transaction_id = ?'; + Horde::logMessage( + sprintf('Whups_Driver_sql::deleteTransaction(): query="%s"; values="%s"', + $query, implode(',', $values)), + 'DEBUG'); + $result = $this->_write_db->query($query, array($transaction)); + if (is_a($result, 'PEAR_Error')) { + Horde::logMessage($result, 'ERR'); + } + return $result; + } + + /** * Return a list of queues with open tickets, and the number of * open tickets in each. * diff --git a/whups/lib/Renderer/Comment.php b/whups/lib/Renderer/Comment.php index 761426150..13c96df8f 100755 --- a/whups/lib/Renderer/Comment.php +++ b/whups/lib/Renderer/Comment.php @@ -167,6 +167,18 @@ class Horde_Form_Renderer_Comment extends Horde_Form_Renderer { } if (count($changes)) { + // Admins can delete entries. + $delete_link = ''; + if (Whups::hasPermission($vars->get('queue'), 'queue', Horde_Perms::DELETE)) { + $delete_link = Horde::applicationUrl('ticket/delete_history.php') + ->add(array('transaction' => $transaction, + 'id' => $vars->get('ticket_id'), + 'url' => Horde::selfUrl(true, false, true))) + ->link(array('title' => _("Delete entry"), 'onclick' => 'return window.confirm(\'' . addslashes(_("Permanently delete entry?")) . '\');')) + . Horde::img('delete.png', _("Delete entry")) + . ''; + } + ob_start(); $class = $private ? 'pc' : 'c'; ?> @@ -176,7 +188,7 @@ class Horde_Form_Renderer_Comment extends Horde_Form_Renderer { getValue('date_format'), $vars->get('timestamp')) ?> get('user_id') ? Whups::formatUser($vars->get('user_id'), false, true, true) : ' ' ?> ', $changes) ?> - + diff --git a/whups/ticket/delete_history.php b/whups/ticket/delete_history.php new file mode 100644 index 000000000..b7973d327 --- /dev/null +++ b/whups/ticket/delete_history.php @@ -0,0 +1,33 @@ +get('queue'), 'queue', Horde_Perms::DELETE)) { + $notification->push(_("Permission Denied"), 'horde.error'); + header('Location: ' . Horde::applicationUrl($prefs->getValue('whups_default_view') . '.php', true)); + exit; +} + +$vars = Horde_Variables::getDefaultVariables(); +$result = $whups_driver->deleteHistory($vars->get('transaction')); +if (is_a($result, 'PEAR_Error')) { + $notification->push($result, 'horde.error'); +} else { + $notification->push(_("Entry deleted."), 'horde.success'); +} + +if ($url = Horde_Util::getFormData('url')) { + header('Location: ' . $url); +} else { + header('Location: ' . Horde::applicationUrl($prefs->getValue('whups_default_view') . '.php', true)); +} -- 2.11.0