Add ability to delete ticket
This commit is contained in:
parent
2131df0cd9
commit
2ff27e197b
@ -137,6 +137,7 @@ class AttachmentHandler {
|
|||||||
} else {
|
} else {
|
||||||
$attachments = $ticket->replies[$replyId]->attachments;
|
$attachments = $ticket->replies[$replyId]->attachments;
|
||||||
unset($attachments[$indexToRemove]);
|
unset($attachments[$indexToRemove]);
|
||||||
|
$this->ticketGateway->updateAttachmentsForReply($replyId, $attachments, $heskSettings);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -36,7 +36,11 @@ class TicketDeleter {
|
|||||||
$this->attachmentHandler->deleteAttachmentFromTicket($ticketId, $attachment->id, $userContext, $heskSettings);
|
$this->attachmentHandler->deleteAttachmentFromTicket($ticketId, $attachment->id, $userContext, $heskSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-- TODO Delete Replies
|
$this->ticketGateway->deleteReplyDraftsForTicket($ticketId, $heskSettings);
|
||||||
|
|
||||||
|
$this->ticketGateway->deleteRepliesForTicket($ticketId, $heskSettings);
|
||||||
|
|
||||||
|
$this->ticketGateway->deleteNotesForTicket($ticketId, $heskSettings);
|
||||||
|
|
||||||
$this->ticketGateway->deleteTicket($ticketId, $heskSettings);
|
$this->ticketGateway->deleteTicket($ticketId, $heskSettings);
|
||||||
}
|
}
|
||||||
|
@ -56,7 +56,7 @@ class TicketGateway extends CommonDao {
|
|||||||
while ($row = hesk_dbFetchAssoc($rs)) {
|
while ($row = hesk_dbFetchAssoc($rs)) {
|
||||||
$linkedTicketsRs =
|
$linkedTicketsRs =
|
||||||
hesk_dbQuery("SELECT * FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "tickets` WHERE `parent` = " . intval($row['id']));
|
hesk_dbQuery("SELECT * FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "tickets` WHERE `parent` = " . intval($row['id']));
|
||||||
$repliesRs = hesk_dbQuery("SELECT * FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "replies` WHERE `replyto` = " . intval($id) . " ORDER BY `id` ASC");
|
$repliesRs = hesk_dbQuery("SELECT * FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "replies` WHERE `replyto` = " . intval($row['id']) . " ORDER BY `id` ASC");
|
||||||
|
|
||||||
$tickets[] = Ticket::fromDatabaseRow($row, $linkedTicketsRs, $repliesRs, $heskSettings);
|
$tickets[] = Ticket::fromDatabaseRow($row, $linkedTicketsRs, $repliesRs, $heskSettings);
|
||||||
}
|
}
|
||||||
@ -74,14 +74,14 @@ class TicketGateway extends CommonDao {
|
|||||||
function getTicketByTrackingId($trackingId, $heskSettings) {
|
function getTicketByTrackingId($trackingId, $heskSettings) {
|
||||||
$this->init();
|
$this->init();
|
||||||
|
|
||||||
$rs = hesk_dbQuery("SELECT * FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "tickets` WHERE `id` = " . intval($trackingId));
|
$rs = hesk_dbQuery("SELECT * FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "tickets` WHERE `trackid` = " . intval($trackingId));
|
||||||
if (hesk_dbNumRows($rs) === 0) {
|
if (hesk_dbNumRows($rs) === 0) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$row = hesk_dbFetchAssoc($rs);
|
$row = hesk_dbFetchAssoc($rs);
|
||||||
$linkedTicketsRs = hesk_dbQuery("SELECT * FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "tickets` WHERE `parent` = " . intval($trackingId));
|
$linkedTicketsRs = hesk_dbQuery("SELECT * FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "tickets` WHERE `parent` = " . intval($trackingId));
|
||||||
$repliesRs = hesk_dbQuery("SELECT * FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "replies` WHERE `replyto` = " . intval($id) . " ORDER BY `id` ASC");
|
$repliesRs = hesk_dbQuery("SELECT * FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "replies` WHERE `replyto` = " . intval($row['id']) . " ORDER BY `id` ASC");
|
||||||
|
|
||||||
$ticket = Ticket::fromDatabaseRow($row, $linkedTicketsRs, $repliesRs, $heskSettings);
|
$ticket = Ticket::fromDatabaseRow($row, $linkedTicketsRs, $repliesRs, $heskSettings);
|
||||||
|
|
||||||
@ -250,6 +250,30 @@ class TicketGateway extends CommonDao {
|
|||||||
$this->close();
|
$this->close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function deleteRepliesForTicket($ticketId, $heskSettings) {
|
||||||
|
$this->init();
|
||||||
|
|
||||||
|
hesk_dbQuery("DELETE FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "replies` WHERE `replyto` = " . intval($ticketId));
|
||||||
|
|
||||||
|
$this->close();
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteReplyDraftsForTicket($ticketId, $heskSettings) {
|
||||||
|
$this->init();
|
||||||
|
|
||||||
|
hesk_dbQuery("DELETE FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "reply_drafts` WHERE `ticket`=" . intval($ticketId));
|
||||||
|
|
||||||
|
$this->close();
|
||||||
|
}
|
||||||
|
|
||||||
|
function deleteNotesForTicket($ticketId, $heskSettings) {
|
||||||
|
$this->init();
|
||||||
|
|
||||||
|
hesk_dbQuery("DELETE FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "notes` WHERE `ticket`='" . intval($ticketId) . "'");
|
||||||
|
|
||||||
|
$this->close();
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $ticketId int
|
* @param $ticketId int
|
||||||
* @param $heskSettings array
|
* @param $heskSettings array
|
||||||
|
@ -275,6 +275,7 @@ class AttachmentHandlerTest extends TestCase {
|
|||||||
$attachment->savedName = 'foobar.txt';
|
$attachment->savedName = 'foobar.txt';
|
||||||
$this->heskSettings['attach_dir'] = 'attach-dir';
|
$this->heskSettings['attach_dir'] = 'attach-dir';
|
||||||
$ticket->attachments = array($attachment);
|
$ticket->attachments = array($attachment);
|
||||||
|
$ticket->replies = array();
|
||||||
$this->ticketGateway->method('getTicketById')->willReturn($ticket);
|
$this->ticketGateway->method('getTicketById')->willReturn($ticket);
|
||||||
$this->userToTicketChecker->method('isTicketAccessibleToUser')->willReturn(true);
|
$this->userToTicketChecker->method('isTicketAccessibleToUser')->willReturn(true);
|
||||||
|
|
||||||
@ -289,6 +290,7 @@ class AttachmentHandlerTest extends TestCase {
|
|||||||
//-- Arrange
|
//-- Arrange
|
||||||
$ticketId = 1;
|
$ticketId = 1;
|
||||||
$ticket = new Ticket();
|
$ticket = new Ticket();
|
||||||
|
$ticket->replies = array();
|
||||||
$attachment = new Attachment();
|
$attachment = new Attachment();
|
||||||
$attachment->id = 5;
|
$attachment->id = 5;
|
||||||
$attachment->savedName = 'foobar.txt';
|
$attachment->savedName = 'foobar.txt';
|
||||||
@ -309,17 +311,18 @@ class AttachmentHandlerTest extends TestCase {
|
|||||||
$ticketId = 1;
|
$ticketId = 1;
|
||||||
$ticket = new Ticket();
|
$ticket = new Ticket();
|
||||||
$reply = new Reply();
|
$reply = new Reply();
|
||||||
|
$reply->id = 10;
|
||||||
$attachment = new Attachment();
|
$attachment = new Attachment();
|
||||||
$attachment->id = 5;
|
$attachment->id = 5;
|
||||||
$attachment->savedName = 'foobar.txt';
|
$attachment->savedName = 'foobar.txt';
|
||||||
$this->heskSettings['attach_dir'] = 'attach-dir';
|
$this->heskSettings['attach_dir'] = 'attach-dir';
|
||||||
$reply->attachments = array($attachment);
|
$reply->attachments = array($attachment);
|
||||||
$ticket->replies = array($reply);
|
$ticket->replies = array(10 => $reply);
|
||||||
$this->ticketGateway->method('getTicketById')->willReturn($ticket);
|
$this->ticketGateway->method('getTicketById')->willReturn($ticket);
|
||||||
$this->userToTicketChecker->method('isTicketAccessibleToUser')->willReturn(true);
|
$this->userToTicketChecker->method('isTicketAccessibleToUser')->willReturn(true);
|
||||||
|
|
||||||
//-- Assert
|
//-- Assert
|
||||||
$this->ticketGateway->expects($this->once())->method('updateAttachmentsForTicket');
|
$this->ticketGateway->expects($this->once())->method('updateAttachmentsForReply');
|
||||||
|
|
||||||
//-- Act
|
//-- Act
|
||||||
$this->attachmentHandler->deleteAttachmentFromTicket($ticketId, 5, $this->userContext, $this->heskSettings);
|
$this->attachmentHandler->deleteAttachmentFromTicket($ticketId, 5, $this->userContext, $this->heskSettings);
|
||||||
|
@ -58,6 +58,7 @@ class TicketDeleterTest extends TestCase {
|
|||||||
$attachmentTwo->id = 2;
|
$attachmentTwo->id = 2;
|
||||||
$attachments = array($attachmentOne, $attachmentTwo);
|
$attachments = array($attachmentOne, $attachmentTwo);
|
||||||
$ticket->attachments = $attachments;
|
$ticket->attachments = $attachments;
|
||||||
|
$ticket->replies = array();
|
||||||
$this->ticketGateway->method('getTicketById')->willReturn($ticket);
|
$this->ticketGateway->method('getTicketById')->willReturn($ticket);
|
||||||
$this->userToTicketChecker->method('isTicketAccessibleToUser')->willReturn(true);
|
$this->userToTicketChecker->method('isTicketAccessibleToUser')->willReturn(true);
|
||||||
|
|
||||||
@ -70,16 +71,57 @@ class TicketDeleterTest extends TestCase {
|
|||||||
|
|
||||||
function testItDeletesAllRepliesForTheTicket() {
|
function testItDeletesAllRepliesForTheTicket() {
|
||||||
//-- Arrange
|
//-- Arrange
|
||||||
|
$ticket = new Ticket();
|
||||||
//-- Act
|
$ticket->attachments = array();
|
||||||
|
$ticket->replies = array();
|
||||||
|
$ticket->id = 1;
|
||||||
|
$this->ticketGateway->method('getTicketById')->willReturn($ticket);
|
||||||
|
$this->userToTicketChecker->method('isTicketAccessibleToUser')->willReturn(true);
|
||||||
|
|
||||||
//-- Assert
|
//-- Assert
|
||||||
|
$this->ticketGateway->expects($this->once())->method('deleteRepliesForTicket')->with(1, $this->heskSettings);
|
||||||
|
|
||||||
|
//-- Act
|
||||||
|
$this->ticketDeleter->deleteTicket(1, $this->userContext, $this->heskSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testItDeleteAllReplyDrafts() {
|
||||||
|
//-- Arrange
|
||||||
|
$ticket = new Ticket();
|
||||||
|
$ticket->attachments = array();
|
||||||
|
$ticket->replies = array();
|
||||||
|
$ticket->id = 1;
|
||||||
|
$this->ticketGateway->method('getTicketById')->willReturn($ticket);
|
||||||
|
$this->userToTicketChecker->method('isTicketAccessibleToUser')->willReturn(true);
|
||||||
|
|
||||||
|
//-- Assert
|
||||||
|
$this->ticketGateway->expects($this->once())->method('deleteReplyDraftsForTicket')->with(1, $this->heskSettings);
|
||||||
|
|
||||||
|
//-- Act
|
||||||
|
$this->ticketDeleter->deleteTicket(1, $this->userContext, $this->heskSettings);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testItDeletesTheTicketNotes() {
|
||||||
|
//-- Arrange
|
||||||
|
$ticket = new Ticket();
|
||||||
|
$ticket->attachments = array();
|
||||||
|
$ticket->replies = array();
|
||||||
|
$ticket->id = 1;
|
||||||
|
$this->ticketGateway->method('getTicketById')->willReturn($ticket);
|
||||||
|
$this->userToTicketChecker->method('isTicketAccessibleToUser')->willReturn(true);
|
||||||
|
|
||||||
|
//-- Assert
|
||||||
|
$this->ticketGateway->expects($this->once())->method('deleteNotesForTicket')->with(1, $this->heskSettings);
|
||||||
|
|
||||||
|
//-- Act
|
||||||
|
$this->ticketDeleter->deleteTicket(1, $this->userContext, $this->heskSettings);
|
||||||
}
|
}
|
||||||
|
|
||||||
function testItDeletesTheTicket() {
|
function testItDeletesTheTicket() {
|
||||||
//-- Arrange
|
//-- Arrange
|
||||||
$ticket = new Ticket();
|
$ticket = new Ticket();
|
||||||
$ticket->attachments = array();
|
$ticket->attachments = array();
|
||||||
|
$ticket->replies = array();
|
||||||
$ticket->id = 1;
|
$ticket->id = 1;
|
||||||
$this->ticketGateway->method('getTicketById')->willReturn($ticket);
|
$this->ticketGateway->method('getTicketById')->willReturn($ticket);
|
||||||
$this->userToTicketChecker->method('isTicketAccessibleToUser')->willReturn(true);
|
$this->userToTicketChecker->method('isTicketAccessibleToUser')->willReturn(true);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user