Fixed a couple issues with deleting tickets

remotes/upstream/api-rewrite
Mike Koch 7 years ago
parent 2ff27e197b
commit b03312f73c

@ -14,6 +14,7 @@ use BusinessLogic\Security\UserContextBuilder;
use BusinessLogic\Security\UserToTicketChecker;
use BusinessLogic\Settings\ApiChecker;
use BusinessLogic\Tickets\Autoassigner;
use BusinessLogic\Tickets\TicketDeleter;
use BusinessLogic\Tickets\TicketRetriever;
use BusinessLogic\Tickets\TicketCreator;
use BusinessLogic\Tickets\NewTicketValidator;
@ -81,6 +82,7 @@ class ApplicationContext {
$this->get[MailgunEmailSender::class]);
// Tickets
$this->get[UserToTicketChecker::class] = new UserToTicketChecker($this->get[UserGateway::class]);
$this->get[TicketGateway::class] = new TicketGateway();
$this->get[TicketRetriever::class] = new TicketRetriever($this->get[TicketGateway::class]);
$this->get[TicketValidators::class] = new TicketValidators($this->get[TicketGateway::class]);
@ -98,9 +100,6 @@ class ApplicationContext {
$this->get[EmailSenderHelper::class],
$this->get[UserGateway::class],
$this->get[ModsForHeskSettingsGateway::class]);
// Attachments
$this->get[UserToTicketChecker::class] = new UserToTicketChecker($this->get[UserGateway::class]);
$this->get[FileWriter::class] = new FileWriter();
$this->get[FileReader::class] = new FileReader();
$this->get[FileDeleter::class] = new FileDeleter();
@ -114,5 +113,9 @@ class ApplicationContext {
$this->get[FileReader::class],
$this->get[TicketGateway::class],
$this->get[UserToTicketChecker::class]);
$this->get[TicketDeleter::class] =
new TicketDeleter($this->get[TicketGateway::class],
$this->get[UserToTicketChecker::class],
$this->get[AttachmentHandler::class]);
}
}

@ -111,6 +111,7 @@ class AttachmentHandler {
if ($attachment->id === $attachmentId) {
$indexToRemove = $i;
$this->fileDeleter->deleteFile($attachment->savedName, $heskSettings['attach_dir']);
$this->attachmentGateway->deleteAttachment($attachment->id, $heskSettings);
}
}
@ -122,6 +123,7 @@ class AttachmentHandler {
$replyId = $reply->id;
$attachmentType = AttachmentType::REPLY;
$this->fileDeleter->deleteFile($attachment->savedName, $heskSettings['attach_dir']);
$this->attachmentGateway->deleteAttachment($attachment->id, $heskSettings);
}
}
}

@ -37,6 +37,7 @@ class Ticket {
$ticket->lastReplier = $row['replierid'] === null ? null : intval($row['replierid']);
$ticket->archived = intval($row['archive']) === 1;
$ticket->locked = intval($row['locked']) === 1;
$ticket->attachments = array();
if (trim($row['attachments']) !== '') {
$attachments = explode(',', $row['attachments']);
@ -110,6 +111,10 @@ class Ticket {
$attachments = explode(',', $replyRow['attachments']);
$attachmentArray = array();
foreach ($attachments as $attachment) {
if (trim($attachment) === '') {
continue;
}
$attachmentRow = explode('#', $attachment);
$attachmentModel = new Attachment();

@ -36,6 +36,12 @@ class TicketDeleter {
$this->attachmentHandler->deleteAttachmentFromTicket($ticketId, $attachment->id, $userContext, $heskSettings);
}
foreach ($ticket->replies as $reply) {
foreach ($reply->attachments as $attachment) {
$this->attachmentHandler->deleteAttachmentFromTicket($ticketId, $attachment->id, $userContext, $heskSettings);
}
}
$this->ticketGateway->deleteReplyDraftsForTicket($ticketId, $heskSettings);
$this->ticketGateway->deleteRepliesForTicket($ticketId, $heskSettings);

@ -0,0 +1,17 @@
<?php
namespace Controllers\Tickets;
use BusinessLogic\Tickets\TicketDeleter;
class StaffTicketController {
function delete($id) {
global $applicationContext, $userContext, $hesk_settings;
/* @var $ticketDeleter TicketDeleter */
$ticketDeleter = $applicationContext->get[TicketDeleter::class];
$ticketDeleter->deleteTicket($id, $userContext, $hesk_settings);
}
}

@ -53,4 +53,13 @@ class AttachmentGateway extends CommonDao {
return $attachment;
}
function deleteAttachment($attachmentId, $heskSettings) {
$this->init();
hesk_dbQuery("DELETE FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "attachments`
WHERE `att_id` = " . intval($attachmentId));
$this->close();
}
}

@ -279,6 +279,10 @@ class TicketGateway extends CommonDao {
* @param $heskSettings array
*/
function deleteTicket($ticketId, $heskSettings) {
$this->init();
hesk_dbQuery("DELETE FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "tickets` WHERE `id` = " . intval($ticketId));
$this->close();
}
}

@ -153,7 +153,7 @@ Link::all(array(
'/v1/tickets/{i}' => \Controllers\Tickets\CustomerTicketController::class,
'/v1/tickets' => \Controllers\Tickets\CustomerTicketController::class,
// Tickets - Staff
'/v1/staff/tickets/{i}' => null,
'/v1/staff/tickets/{i}' => \Controllers\Tickets\StaffTicketController::class,
// Attachments
'/v1/staff/tickets/{i}/attachments' => \Controllers\Attachments\StaffTicketAttachmentsController::class,
'/v1/staff/tickets/{i}/attachments/{i}' => \Controllers\Attachments\StaffTicketAttachmentsController::class,

Loading…
Cancel
Save