Skip to content

Commit a39c115

Browse files
committed
Delete Threads/Entries of Deleted Tickets
This commit reallows us to delete threads and thread entries when deleting tickets by adding a column called thread_type to the thread event table that contains the same data as the object_type field on the thread table. The reason for doing this was because in the dashboard reports, we were relying on the object type in the thread table to give us accurate report data.
1 parent a8a4dec commit a39c115

File tree

5 files changed

+8
-5
lines changed

5 files changed

+8
-5
lines changed

include/class.report.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,20 +84,18 @@ function getPlotData() {
8484
$res = db_query('SELECT DISTINCT(E.name) FROM '.THREAD_EVENT_TABLE
8585
.' T JOIN '.EVENT_TABLE . ' E ON E.id = T.event_id'
8686
.' WHERE timestamp BETWEEN '.$start.' AND '.$stop
87-
.' AND T.event_id IN ('.implode(",",$event_ids).')'
87+
.' AND T.event_id IN ('.implode(",",$event_ids).') AND T.thread_type = "T"'
8888
.' ORDER BY 1');
8989
$events = array();
9090
while ($row = db_fetch_row($res)) $events[] = $row[0];
9191

9292
# TODO: Handle user => db timezone offset
9393
# XXX: Implement annulled column from the %ticket_event table
9494
$res = db_query('SELECT H.name, DATE_FORMAT(timestamp, \'%Y-%m-%d\'), '
95-
.'COUNT(DISTINCT T.id)'
95+
.'COUNT(DISTINCT E.id)'
9696
.' FROM '.THREAD_EVENT_TABLE. ' E '
9797
. ' LEFT JOIN '.EVENT_TABLE. ' H
9898
ON (E.event_id = H.id)'
99-
.' JOIN '.THREAD_TABLE. ' T
100-
ON (T.id = E.thread_id AND T.object_type = "T") '
10199
.' WHERE E.timestamp BETWEEN '.$start.' AND '.$stop
102100
.' AND NOT annulled'
103101
.' AND E.event_id IN ('.implode(",",$event_ids).')'
@@ -181,7 +179,7 @@ function getTabularData($group='dept') {
181179
->filter(array(
182180
'annulled' => 0,
183181
'timestamp__range' => array($start, $stop, true),
184-
'thread__object_type' => 'T',
182+
'thread_type' => 'T',
185183
))
186184
->aggregate(array(
187185
'Opened' => SqlAggregate::COUNT(

include/class.task.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,6 +1379,7 @@ function delete($comments='') {
13791379
if (!parent::delete())
13801380
return false;
13811381

1382+
$thread->delete();
13821383
$this->logEvent('deleted');
13831384

13841385
Draft::deleteForNamespace('task.%.' . $this->getId());

include/class.thread.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2123,6 +2123,7 @@ static function forTicket($ticket, $state, $user=false) {
21232123
$staff = $ticket->getStaffId();
21242124

21252125
$inst = self::create(array(
2126+
'thread_type' => ObjectModel::OBJECT_TYPE_TICKET,
21262127
'staff_id' => $staff,
21272128
'team_id' => $ticket->getTeamId(),
21282129
'dept_id' => $ticket->getDeptId(),
@@ -2133,6 +2134,7 @@ static function forTicket($ticket, $state, $user=false) {
21332134

21342135
static function forTask($task, $state, $user=false) {
21352136
$inst = self::create(array(
2137+
'thread_type' => ObjectModel::OBJECT_TYPE_TASK,
21362138
'staff_id' => $task->getStaffId(),
21372139
'team_id' => $task->getTeamId(),
21382140
'dept_id' => $task->getDeptId(),

include/class.ticket.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3471,6 +3471,7 @@ function delete($comments='') {
34713471
}
34723472

34733473

3474+
$t->delete();
34743475
$this->logEvent('deleted');
34753476

34763477
foreach (DynamicFormEntry::forTicket($this->getId()) as $form)

setup/inc/streams/core/install-mysql.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -764,6 +764,7 @@ DROP TABLE IF EXISTS `%TABLE_PREFIX%thread_event`;
764764
CREATE TABLE `%TABLE_PREFIX%thread_event` (
765765
`id` int(10) unsigned NOT NULL AUTO_INCREMENT,
766766
`thread_id` int(11) unsigned NOT NULL default '0',
767+
`thread_type` char(1) NOT NULL DEFAULT '',
767768
`event_id` int(11) unsigned DEFAULT NULL,
768769
`staff_id` int(11) unsigned NOT NULL,
769770
`team_id` int(11) unsigned NOT NULL,

0 commit comments

Comments
 (0)