Create ticket endpoint now working, but needs some changes

This commit is contained in:
Mike Koch 2017-02-14 12:45:02 -05:00
parent 1cb4209be2
commit 1b6cca8ddf
6 changed files with 21 additions and 18 deletions

View File

@ -5,19 +5,17 @@ namespace BusinessLogic\Exceptions;
use BusinessLogic\ValidationModel;
use Exception;
class ValidationException extends Exception {
public $validationModel;
class ValidationException extends ApiFriendlyException {
/**
* ValidationException constructor.
* @param ValidationModel $validationModel The validation model
* @throws Exception If the validationModel's errorKeys is empty
*/
function __construct($validationModel) {
if (count($validationModel->errorKeys) === 0) {
throw new Exception('Tried to throw a ValidationException, but the validation model was valid!');
if (count($validationModel->errorKeys) === 0 || $validationModel->valid) {
throw new Exception('Tried to throw a ValidationException, but the validation model was valid or had 0 error keys!');
}
$this->validationModel = $validationModel;
parent::__construct(implode(",", $validationModel->errorKeys), "Validation Failed. Error keys are available in the message section.", 400);
}
}

View File

@ -238,9 +238,12 @@ class Ticket {
function getAttachmentsForDatabase() {
$attachmentArray = array();
if ($this->attachments !== null) {
foreach ($this->attachments as $attachment) {
$attachmentArray[] = $attachment->id . '#' . $attachment->fileName . '#' . $attachment->savedName;
}
}
return implode(',', $attachmentArray);
}

View File

@ -17,6 +17,6 @@ class JsonRetriever {
*/
static function getJsonData() {
$json = file_get_contents('php://input');
return json_decode($json);
return json_decode($json, true);
}
}

View File

@ -27,7 +27,9 @@ class TicketController {
$jsonRequest = JsonRetriever::getJsonData();
$ticketCreator->createTicketByCustomer($this->buildTicketRequestFromJson($jsonRequest), $hesk_settings, $modsForHeskSettings, $userContext);
$ticket = $ticketCreator->createTicketByCustomer($this->buildTicketRequestFromJson($jsonRequest), $hesk_settings, $modsForHeskSettings, $userContext);
return output($ticket);
}
/**

View File

@ -124,10 +124,10 @@ class TicketGateway extends CommonDao {
$userAgent = $ticket->userAgent !== null ? $ticket->userAgent : '';
$screenResolutionWidth = $ticket->screenResolution !== null
&& isset($ticket->screenResolution[0])
&& $ticket->screenResolution[0] !== null ? intval($ticket->screenResolution[0]) : '';
&& $ticket->screenResolution[0] !== null ? intval($ticket->screenResolution[0]) : 'NULL';
$screenResolutionHeight = $ticket->screenResolution !== null
&& isset($ticket->screenResolution[1])
&& $ticket->screenResolution[1] !== null ? intval($ticket->screenResolution[1]) : '';
&& $ticket->screenResolution[1] !== null ? intval($ticket->screenResolution[1]) : 'NULL';
$sql = "INSERT INTO `" . hesk_dbEscape($heskSettings['db_pfix']) . "tickets`
(
@ -169,14 +169,14 @@ class TicketGateway extends CommonDao {
'" . hesk_dbEscape($ticket->message) . "',
NOW(),
NOW(),
" . $suggestedArticles . ",
'" . $suggestedArticles . "',
'" . hesk_dbEscape($ticket->ipAddress) . "',
'" . hesk_dbEscape($language) . "',
'" . intval($ticket->openedBy) . "',
'" . intval($ticket->ownerId) . "',
'" . hesk_dbEscape($ticket->getAttachmentsForDatabase()) . "',
'',
'" . intval($ticket->statusId) . "',
" . intval($ticket->statusId) . ",
'" . hesk_dbEscape($latitude) . "',
'" . hesk_dbEscape($longitude) . "',
'" . hesk_dbEscape($ticket->usesHtml) . "',
@ -192,7 +192,7 @@ class TicketGateway extends CommonDao {
hesk_dbQuery($sql);
$rs = hesk_dbQuery('SELECT `dt`, `lastchange` FROM `' . hesk_dbEscape($heskSettings['db_pfix']) . 'tickets` WHERE `id` = ' . intval(hesk_dbInsertID()));
$row = hesk_dbFetchRow($rs);
$row = hesk_dbFetchAssoc($rs);
$generatedFields = new TicketGatewayGeneratedFields();
$generatedFields->dateCreated = $row['dt'];

View File

@ -41,13 +41,13 @@ function errorHandler($errorNumber, $errorMessage, $errorFile, $errorLine) {
* @param $exception Exception
*/
function exceptionHandler($exception) {
if (exceptionIsOfType($exception, 'ApiFriendlyException')) {
if (exceptionIsOfType($exception, \BusinessLogic\Exceptions\ApiFriendlyException::class)) {
/* @var $castedException \BusinessLogic\Exceptions\ApiFriendlyException */
$castedException = $exception;
print_error($castedException->title, $castedException->getMessage(), $castedException->httpResponseCode);
} else {
if (exceptionIsOfType($exception, 'SQLException')) {
if (exceptionIsOfType($exception, \Core\Exceptions\SQLException::class)) {
/* @var $castedException \Core\Exceptions\SQLException */
$castedException = $exception;
print_error("Fought an uncaught exception", sprintf("%s\n\n%s", $castedException->failingQuery, $exception->getTraceAsString()));
@ -66,7 +66,7 @@ function exceptionHandler($exception) {
* @return bool
*/
function exceptionIsOfType($exception, $class) {
return strpos(get_class($exception), $class) !== false;
return is_a($exception, $class);
}
function fatalErrorShutdownHandler() {