Getting started on attachment retrieval
This commit is contained in:
parent
999cb74865
commit
3cec244e15
24
api/BusinessLogic/Attachments/AttachmentRetriever.php
Normal file
24
api/BusinessLogic/Attachments/AttachmentRetriever.php
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace BusinessLogic\Attachments;
|
||||||
|
|
||||||
|
|
||||||
|
use DataAccess\Attachments\AttachmentGateway;
|
||||||
|
use DataAccess\Files\FileReader;
|
||||||
|
|
||||||
|
class AttachmentRetriever {
|
||||||
|
/* @var $attachmentGateway AttachmentGateway */
|
||||||
|
private $attachmentGateway;
|
||||||
|
|
||||||
|
/* @var $fileReader FileReader */
|
||||||
|
private $fileReader;
|
||||||
|
|
||||||
|
function __construct($attachmentGateway, $fileReader) {
|
||||||
|
$this->attachmentGateway = $attachmentGateway;
|
||||||
|
$this->fileReader = $fileReader;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getAttachmentContentsForTicket($id, $heskSettings) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -10,12 +10,22 @@ use BusinessLogic\Helpers;
|
|||||||
use Controllers\JsonRetriever;
|
use Controllers\JsonRetriever;
|
||||||
|
|
||||||
class StaffTicketAttachmentsController {
|
class StaffTicketAttachmentsController {
|
||||||
|
function get($attachmentId) {
|
||||||
|
global $hesk_settings, $applicationContext;
|
||||||
|
|
||||||
|
$this->verifyAttachmentsAreEnabled($hesk_settings);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function verifyAttachmentsAreEnabled($heskSettings) {
|
||||||
|
if (!$heskSettings['attachments']['use']) {
|
||||||
|
throw new ApiFriendlyException('Attachments are disabled on this server', 'Attachments Disabled', 404);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
function post($ticketId) {
|
function post($ticketId) {
|
||||||
global $hesk_settings, $applicationContext;
|
global $hesk_settings, $applicationContext;
|
||||||
|
|
||||||
if (!$hesk_settings['attachments']['use']) {
|
$this->verifyAttachmentsAreEnabled($hesk_settings);
|
||||||
throw new ApiFriendlyException('Attachments are disabled on this server', 'Attachments Disabled', 404);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* @var $attachmentHandler AttachmentHandler */
|
/* @var $attachmentHandler AttachmentHandler */
|
||||||
$attachmentHandler = $applicationContext->get[AttachmentHandler::class];
|
$attachmentHandler = $applicationContext->get[AttachmentHandler::class];
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
namespace DataAccess\Attachments;
|
namespace DataAccess\Attachments;
|
||||||
|
|
||||||
|
|
||||||
|
use BusinessLogic\Attachments\Attachment;
|
||||||
use BusinessLogic\Attachments\TicketAttachment;
|
use BusinessLogic\Attachments\TicketAttachment;
|
||||||
use DataAccess\CommonDao;
|
use DataAccess\CommonDao;
|
||||||
|
|
||||||
@ -27,4 +28,29 @@ class AttachmentGateway extends CommonDao {
|
|||||||
|
|
||||||
return $attachmentId;
|
return $attachmentId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getAttachmentById($id, $heskSettings) {
|
||||||
|
$this->init();
|
||||||
|
|
||||||
|
$rs = hesk_dbQuery("SELECT *
|
||||||
|
FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "attachments`
|
||||||
|
WHERE `att_id` = " . intval($id));
|
||||||
|
|
||||||
|
if (hesk_dbNumRows($rs) === 0) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
$row = hesk_dbFetchAssoc($rs);
|
||||||
|
|
||||||
|
$attachment = new Attachment();
|
||||||
|
$attachment->id = $row['att_id'];
|
||||||
|
$attachment->savedName = $row['saved_name'];
|
||||||
|
$attachment->displayName = $row['real_name'];
|
||||||
|
$attachment->downloadCount = $row['download_count'];
|
||||||
|
$attachment->fileSize = $row['size'];
|
||||||
|
|
||||||
|
$this->close();
|
||||||
|
|
||||||
|
return $attachment;
|
||||||
|
}
|
||||||
}
|
}
|
25
api/DataAccess/Files/FileReader.php
Normal file
25
api/DataAccess/Files/FileReader.php
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace DataAccess\Files;
|
||||||
|
|
||||||
|
|
||||||
|
class FileReader {
|
||||||
|
/**
|
||||||
|
* @param $name string - The file name (including extension)
|
||||||
|
* @param $folder - The folder name (relative to the ROOT of the helpdesk)
|
||||||
|
* @param $contents string - The contents of the file to write
|
||||||
|
* @return int The file size, in bytes
|
||||||
|
* @throws \Exception When the file fails to save
|
||||||
|
*/
|
||||||
|
function readFromFile($name, $folder, $contents) {
|
||||||
|
// __DIR__ === '/{ROOT}/api/DataAccess/Files
|
||||||
|
$location = __DIR__ . "/../../../{$folder}/{$name}";
|
||||||
|
$fileContents = file_get_contents($location);
|
||||||
|
|
||||||
|
if ($fileContents === false) {
|
||||||
|
throw new \Exception("Failed to read the file!");
|
||||||
|
}
|
||||||
|
|
||||||
|
return $fileContents;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
|
||||||
|
namespace BusinessLogic\Attachments;
|
||||||
|
|
||||||
|
|
||||||
|
use DataAccess\Attachments\AttachmentGateway;
|
||||||
|
use DataAccess\Files\FileReader;
|
||||||
|
use PHPUnit\Framework\TestCase;
|
||||||
|
|
||||||
|
class AttachmentRetrieverTest extends TestCase {
|
||||||
|
/* @var $attachmentGateway \PHPUnit_Framework_MockObject_MockObject */
|
||||||
|
private $attachmentGateway;
|
||||||
|
|
||||||
|
/* @var $fileReader \PHPUnit_Framework_MockObject_MockObject */
|
||||||
|
private $fileReader;
|
||||||
|
|
||||||
|
/* @var $attachmentRetriever AttachmentRetriever */
|
||||||
|
private $attachmentRetriever;
|
||||||
|
|
||||||
|
protected function setUp() {
|
||||||
|
$this->attachmentGateway = $this->createMock(AttachmentGateway::class);
|
||||||
|
$this->fileReader = $this->createMock(FileReader::class);
|
||||||
|
|
||||||
|
$this->attachmentRetriever = new AttachmentRetriever($this->attachmentGateway, $this->fileReader);
|
||||||
|
}
|
||||||
|
|
||||||
|
function testItGetsTheAttachmentFromTheFilesystem() {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -155,6 +155,7 @@ Link::all(array(
|
|||||||
|
|
||||||
// Attachments
|
// Attachments
|
||||||
'/v1/staff/tickets/{i}/attachments' => \Controllers\Attachments\StaffTicketAttachmentsController::class,
|
'/v1/staff/tickets/{i}/attachments' => \Controllers\Attachments\StaffTicketAttachmentsController::class,
|
||||||
|
'/v1/staff/attachments/{i}' => \Controllers\Attachments\StaffTicketAttachmentsController::class,
|
||||||
|
|
||||||
// Any URL that doesn't match goes to the 404 handler
|
// Any URL that doesn't match goes to the 404 handler
|
||||||
'404' => 'handle404'
|
'404' => 'handle404'
|
||||||
|
Loading…
x
Reference in New Issue
Block a user