Attachments can now be uploaded for a ticket. Still need to handle updating the reply's property

remotes/upstream/api-rewrite
Mike Koch 7 years ago
parent 8d484f62ea
commit 0556d07a56

@ -4,6 +4,8 @@ namespace BusinessLogic\Attachments;
use BusinessLogic\Exceptions\ValidationException;
use BusinessLogic\Tickets\Attachment;
use BusinessLogic\Tickets\Ticket;
use BusinessLogic\ValidationModel;
use DataAccess\Attachments\AttachmentGateway;
use DataAccess\Files\FileWriter;
@ -52,6 +54,9 @@ class AttachmentHandler {
$this->fileWriter->writeToFile($ticketAttachment->savedName, $heskSettings['attach_dir'], $decodedAttachment);
$attachmentId = $this->attachmentGateway->createAttachmentForTicket($ticketAttachment, $heskSettings);
$this->updateAttachmentsOnTicket($ticket, $ticketAttachment, $attachmentId, $heskSettings);
$ticketAttachment->id = $attachmentId;
return $ticketAttachment;
@ -366,4 +371,20 @@ class AttachmentHandler {
}
return true;
}
/**
* @param $ticket Ticket
* @param $ticketAttachment TicketAttachment
* @param $attachmentId int
* @param $heskSettings array
*/
private function updateAttachmentsOnTicket($ticket, $ticketAttachment, $attachmentId, $heskSettings) {
$attachments = $ticket->attachments === null ? array() : $ticket->attachments;
$newAttachment = new Attachment();
$newAttachment->savedName = $ticketAttachment->savedName;
$newAttachment->fileName = $ticketAttachment->displayName;
$newAttachment->id = $attachmentId;
$attachments[] = $newAttachment;
$this->ticketGateway->updateAttachmentsForTicket($ticket->id, $attachments, $heskSettings);
}
}

@ -3,6 +3,7 @@
namespace DataAccess\Tickets;
use BusinessLogic\Tickets\Attachment;
use BusinessLogic\Tickets\Ticket;
use BusinessLogic\Tickets\TicketGatewayGeneratedFields;
use DataAccess\CommonDao;
@ -205,4 +206,25 @@ class TicketGateway extends CommonDao {
return $generatedFields;
}
/**
* @param $ticketId int
* @param $attachments Attachment[]
* @param $heskSettings array
*
* Crappy logic that should just be pulled from the attachments table, but using for backwards compatibility
*/
function updateAttachmentsForTicket($ticketId, $attachments, $heskSettings) {
$this->init();
$attachmentStrings = array();
foreach ($attachments as $attachment) {
$attachmentStrings[] = "{$attachment->id}#{$attachment->fileName}#{$attachment->savedName}";
}
$attachmentStringToSave = implode(',', $attachmentStrings);
hesk_dbQuery("UPDATE `" . hesk_dbEscape($heskSettings['db_pfix']) . "tickets`
SET `attachments` = '" . hesk_dbEscape($attachmentStringToSave) . "'
WHERE `id` = " . intval($ticketId));
}
}

@ -147,11 +147,14 @@ Link::before('before');
Link::all(array(
// Categories
'/v1/categories' => '\Controllers\Categories\CategoryController::printAllCategories',
'/v1/categories/{i}' => '\Controllers\Categories\CategoryController',
'/v1/categories' => \Controllers\Categories\CategoryController::class . '::printAllCategories',
'/v1/categories/{i}' => \Controllers\Categories\CategoryController::class,
// Tickets
'/v1/tickets/{i}' => '\Controllers\Tickets\TicketController',
'/v1/tickets' => '\Controllers\Tickets\TicketController',
'/v1/tickets/{i}' => \Controllers\Tickets\TicketController::class,
'/v1/tickets' => \Controllers\Tickets\TicketController::class,
// Attachments
'/v1/staff/attachments' => \Controllers\Attachments\StaffTicketAttachmentsController::class,
// Any URL that doesn't match goes to the 404 handler
'404' => 'handle404'

Loading…
Cancel
Save