More work on ticket stuff
This commit is contained in:
parent
8968be1ffd
commit
a4af2e668f
@ -35,9 +35,11 @@ require_once(__DIR__ . '/businesslogic/security/BannedEmail.php');
|
||||
require_once(__DIR__ . '/businesslogic/security/BannedIp.php');
|
||||
|
||||
// Exceptions
|
||||
require_once(__DIR__ . '/businesslogic/exception/ApiFriendlyException.php');
|
||||
require_once(__DIR__ . '/businesslogic/exception/InvalidAuthenticationTokenException.php');
|
||||
require_once(__DIR__ . '/businesslogic/exception/MissingAuthenticationTokenException.php');
|
||||
require_once(__DIR__ . '/businesslogic/exception/ValidationException.php');
|
||||
require_once(__DIR__ . '/core/SQLException.php');
|
||||
|
||||
hesk_load_api_database_functions();
|
||||
|
||||
|
25
api/businesslogic/exception/ApiFriendlyException.php
Normal file
25
api/businesslogic/exception/ApiFriendlyException.php
Normal file
@ -0,0 +1,25 @@
|
||||
<?php
|
||||
|
||||
namespace BusinessLogic\Exceptions;
|
||||
|
||||
|
||||
use Exception;
|
||||
|
||||
class ApiFriendlyException extends Exception {
|
||||
public $title;
|
||||
public $httpResponseCode;
|
||||
|
||||
/**
|
||||
* ApiFriendlyException constructor.
|
||||
* @param string $message
|
||||
* @param string $title
|
||||
* @param int $httpResponseCode
|
||||
*/
|
||||
function __construct($message, $title, $httpResponseCode) {
|
||||
$this->title = $title;
|
||||
$this->httpResponseCode = $httpResponseCode;
|
||||
|
||||
parent::__construct($message);
|
||||
}
|
||||
|
||||
}
|
@ -2,10 +2,11 @@
|
||||
|
||||
namespace BusinessLogic\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class InvalidAuthenticationTokenException extends Exception {
|
||||
class InvalidAuthenticationTokenException extends ApiFriendlyException {
|
||||
public function __construct() {
|
||||
parent::__construct('The X-Auth-Token is invalid. The token must be for an active helpdesk user.');
|
||||
parent::__construct('The X-Auth-Token is invalid. The token must be for an active helpdesk user.',
|
||||
'Security Exception',
|
||||
401);
|
||||
}
|
||||
}
|
@ -1,17 +1,11 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: mkoch
|
||||
* Date: 1/28/2017
|
||||
* Time: 9:55 PM
|
||||
*/
|
||||
|
||||
namespace BusinessLogic\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class MissingAuthenticationTokenException extends Exception {
|
||||
class MissingAuthenticationTokenException extends ApiFriendlyException {
|
||||
function __construct() {
|
||||
parent::__construct("An 'X-Auth-Token' is required for all requests");
|
||||
parent::__construct("An 'X-Auth-Token' is required for all requests",
|
||||
'Security Exception',
|
||||
400);
|
||||
}
|
||||
}
|
191
api/businesslogic/ticket/Ticket.php
Normal file
191
api/businesslogic/ticket/Ticket.php
Normal file
@ -0,0 +1,191 @@
|
||||
<?php
|
||||
|
||||
namespace BusinessLogic\Tickets;
|
||||
|
||||
|
||||
class Ticket {
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $id;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $trackingId;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $name;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $email;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $category;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $priority;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $subject;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $message;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $dateCreated;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $lastChanged;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
public $firstReplyDate;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
public $closedDate;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
public $suggestedArticles;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $ipAddress;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
public $language;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $statusId;
|
||||
|
||||
/**
|
||||
* @var int (convert to enum)
|
||||
*/
|
||||
public $openedByUserId;
|
||||
|
||||
/**
|
||||
* @var int|null
|
||||
*/
|
||||
public $firstReplyByUserId;
|
||||
|
||||
/**
|
||||
* @var int|null
|
||||
*/
|
||||
public $closedByUserId;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $numberOfReplies;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $numberOfStaffReplies;
|
||||
|
||||
/**
|
||||
* @var int
|
||||
*/
|
||||
public $ownerId;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $timeWorked;
|
||||
|
||||
/**
|
||||
* @var int (convert to enum)
|
||||
*/
|
||||
public $lastReplier;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $archived;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $locked;
|
||||
|
||||
/**
|
||||
* @var array|null (TODO clarify this later)
|
||||
*/
|
||||
public $attachments;
|
||||
|
||||
/**
|
||||
* @var int[]|null
|
||||
*/
|
||||
public $mergedTicketIds;
|
||||
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
public $auditTrailHtml;
|
||||
|
||||
/**
|
||||
* @var array (TODO clarify this later)
|
||||
*/
|
||||
public $customFields;
|
||||
|
||||
/**
|
||||
* @var int[]
|
||||
*/
|
||||
public $linkedTicketIds;
|
||||
|
||||
/**
|
||||
* @var float[2]|null
|
||||
*/
|
||||
public $location;
|
||||
|
||||
/**
|
||||
* @var bool
|
||||
*/
|
||||
public $usesHtml;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
public $userAgent;
|
||||
|
||||
/**
|
||||
* @var int[2]|null
|
||||
*/
|
||||
public $screenResolution;
|
||||
|
||||
/**
|
||||
* @var string|null
|
||||
*/
|
||||
public $dueDate;
|
||||
|
||||
/**
|
||||
* @var bool|null
|
||||
*/
|
||||
public $dueDateOverdueEmailSent;
|
||||
}
|
12
api/businesslogic/ticket/TicketValidators.php
Normal file
12
api/businesslogic/ticket/TicketValidators.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
namespace BusinessLogic\Tickets;
|
||||
|
||||
|
||||
class TicketValidators {
|
||||
/**
|
||||
* @param $customerEmail string
|
||||
*/
|
||||
function isCustomerAtMaxTickets($customerEmail) {
|
||||
|
||||
}
|
||||
}
|
18
api/core/SQLException.php
Normal file
18
api/core/SQLException.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace Core\Exceptions;
|
||||
|
||||
use Exception;
|
||||
|
||||
class SQLException extends Exception {
|
||||
/**
|
||||
* @var $failingQuery string
|
||||
*/
|
||||
public $failingQuery;
|
||||
|
||||
function __construct($failingQuery) {
|
||||
$this->failingQuery = $failingQuery;
|
||||
|
||||
parent::__construct('A SQL exception occurred. Check the logs for more information.');
|
||||
}
|
||||
}
|
@ -112,30 +112,15 @@ function hesk_dbConnect()
|
||||
// Errors?
|
||||
if ( ! $hesk_db_link)
|
||||
{
|
||||
if ($hesk_settings['debug_mode'])
|
||||
{
|
||||
$message = $hesklang['mysql_said'] . ': ' . mysql_error();
|
||||
}
|
||||
else
|
||||
{
|
||||
$message = $hesklang['contact_webmaster'] . $hesk_settings['webmaster_email'];
|
||||
}
|
||||
//TODO Throw exception
|
||||
//print_error($hesklang['cant_connect_db'], $message);
|
||||
$message = $hesklang['mysql_said'] . ': ' . mysql_error();
|
||||
|
||||
throw new \Core\Exceptions\SQLException($message);
|
||||
}
|
||||
|
||||
if ( ! @mysql_select_db($hesk_settings['db_name'], $hesk_db_link))
|
||||
{
|
||||
if ($hesk_settings['debug_mode'])
|
||||
{
|
||||
$message = $hesklang['mysql_said'] . ': ' . mysql_error();
|
||||
}
|
||||
else
|
||||
{
|
||||
$message = $hesklang['contact_webmaster'] . $hesk_settings['webmaster_email'];
|
||||
}
|
||||
//TODO Throw exception
|
||||
//print_error($hesklang['cant_connect_db'], $message);
|
||||
if ( ! @mysql_select_db($hesk_settings['db_name'], $hesk_db_link)) {
|
||||
$message = $hesklang['mysql_said'] . ': ' . mysql_error();
|
||||
|
||||
throw new \Core\Exceptions\SQLException($message);
|
||||
}
|
||||
|
||||
// Check MySQL/PHP version and set encoding to utf8
|
||||
@ -168,21 +153,12 @@ function hesk_dbQuery($query)
|
||||
|
||||
$hesk_last_query = $query;
|
||||
|
||||
if ($res = @mysql_query($query, $hesk_db_link))
|
||||
{
|
||||
if ($res = @mysql_query($query, $hesk_db_link)) {
|
||||
return $res;
|
||||
}
|
||||
elseif ($hesk_settings['debug_mode'])
|
||||
{
|
||||
$message = $hesklang['mysql_said'] . mysql_error();
|
||||
}
|
||||
else
|
||||
{
|
||||
$message = $hesklang['contact_webmaster'] . $hesk_settings['webmaster_email'];
|
||||
}
|
||||
//TODO Throw exception
|
||||
//print_error($hesklang['cant_sql'], $message);
|
||||
return null;
|
||||
|
||||
$message = $hesklang['mysql_said'] . mysql_error();
|
||||
throw new \Core\Exceptions\SQLException($message);
|
||||
} // END hesk_dbQuery()
|
||||
|
||||
|
||||
@ -219,6 +195,7 @@ function hesk_dbInsertID()
|
||||
return $lastid;
|
||||
}
|
||||
|
||||
return null;
|
||||
} // END hesk_dbInsertID()
|
||||
|
||||
|
||||
|
@ -120,17 +120,9 @@ function hesk_dbConnect()
|
||||
// Errors?
|
||||
if ( ! $hesk_db_link)
|
||||
{
|
||||
if ($hesk_settings['debug_mode'])
|
||||
{
|
||||
$message = $hesklang['mysql_said'] . ': (' . mysqli_connect_errno() . ') ' . mysqli_connect_error();
|
||||
}
|
||||
else
|
||||
{
|
||||
$message = $hesklang['contact_webmaster'] . $hesk_settings['webmaster_email'];
|
||||
}
|
||||
$message = $hesklang['mysql_said'] . ': (' . mysqli_connect_errno() . ') ' . mysqli_connect_error();
|
||||
|
||||
//TODO Throw exception instead
|
||||
//print_error($hesklang['cant_connect_db'], $message);
|
||||
throw new \Core\Exceptions\SQLException($message);
|
||||
}
|
||||
|
||||
// Check MySQL/PHP version and set encoding to utf8
|
||||
@ -169,18 +161,9 @@ function hesk_dbQuery($query)
|
||||
{
|
||||
return $res;
|
||||
}
|
||||
elseif ($hesk_settings['debug_mode'])
|
||||
{
|
||||
$message = $hesklang['mysql_said'] . ': ' . mysqli_error($hesk_db_link);
|
||||
}
|
||||
else
|
||||
{
|
||||
$message = $hesklang['contact_webmaster'] . $hesk_settings['webmaster_email'];
|
||||
}
|
||||
|
||||
//TODO Throw exception instead
|
||||
//print_error($hesklang['cant_sql'], $message);
|
||||
return null;
|
||||
$message = $hesklang['mysql_said'] . ': ' . mysqli_error($hesk_db_link);
|
||||
throw new \Core\Exceptions\SQLException($message);
|
||||
} // END hesk_dbQuery()
|
||||
|
||||
|
||||
|
@ -1,11 +1,4 @@
|
||||
<?php
|
||||
/**
|
||||
* Created by PhpStorm.
|
||||
* User: user
|
||||
* Date: 1/21/17
|
||||
* Time: 4:23 PM
|
||||
*/
|
||||
|
||||
namespace DataAccess\Security;
|
||||
|
||||
|
||||
@ -23,9 +16,9 @@ class UserGateway extends CommonDao {
|
||||
$this->init();
|
||||
|
||||
$rs = hesk_dbQuery("SELECT * FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "users` WHERE `id` = (
|
||||
SELECT ``
|
||||
SELECT `user_id`
|
||||
FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "user_api_tokens`
|
||||
WHERE `tokens`.`token` = " . hesk_dbEscape($hashedToken) . "
|
||||
WHERE `token` = '" . hesk_dbEscape($hashedToken) . "'
|
||||
) AND `active` = '1'");
|
||||
|
||||
if (hesk_dbNumRows($rs) === 0) {
|
||||
|
13
api/dao/ticket/TicketGateway.php
Normal file
13
api/dao/ticket/TicketGateway.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace DataAccess\Tickets;
|
||||
|
||||
|
||||
class TicketGateway {
|
||||
function getTicketsByEmail($emailAddress, $heskSettings) {
|
||||
$rs = hesk_dbQuery("SELECT * FROM `" . hesk_dbEscape($heskSettings['db_pfix']) . "tickets`
|
||||
WHERE `email` = '" . hesk_dbEscape($emailAddress) . "'");
|
||||
|
||||
|
||||
}
|
||||
}
|
@ -41,12 +41,20 @@ function errorHandler($errorNumber, $errorMessage, $errorFile, $errorLine) {
|
||||
* @param $exception Exception
|
||||
*/
|
||||
function exceptionHandler($exception) {
|
||||
if (exceptionIsOfType($exception, 'MissingAuthenticationTokenException')) {
|
||||
print_error("Security Exception", $exception->getMessage(), 400);
|
||||
} elseif (exceptionIsOfType($exception, 'InvalidAuthenticationTokenException')) {
|
||||
print_error("Security Exception", $exception->getMessage(), 401);
|
||||
if (exceptionIsOfType($exception, 'ApiFriendlyException')) {
|
||||
/* @var $castedException \BusinessLogic\Exceptions\ApiFriendlyException */
|
||||
$castedException = $exception;
|
||||
|
||||
print_error($castedException->title, $castedException->getMessage(), $castedException->httpResponseCode);
|
||||
} else {
|
||||
print_error("Fought an uncaught exception", sprintf("%s\n\n%s", $exception->getMessage(), $exception->getTraceAsString()));
|
||||
if (exceptionIsOfType($exception, 'SQLException')) {
|
||||
/* @var $castedException \Core\Exceptions\SQLException */
|
||||
$castedException = $exception;
|
||||
print_error("Fought an uncaught exception", sprintf("%s\n\n%s", $castedException->failingQuery, $exception->getTraceAsString()));
|
||||
} else {
|
||||
print_error("Fought an uncaught exception", sprintf("%s\n\n%s", $exception->getMessage(), $exception->getTraceAsString()));
|
||||
}
|
||||
|
||||
}
|
||||
// Log more stuff to logging table if possible; we'll catch any exceptions from this
|
||||
die();
|
||||
|
@ -1,11 +0,0 @@
|
||||
<?php
|
||||
define('IN_SCRIPT', 1);
|
||||
define('HESK_PATH', '../');
|
||||
|
||||
require_once(__DIR__ . '/core/common.php');
|
||||
require_once(__DIR__ . '/controllers/CategoryController.php');
|
||||
hesk_load_api_database_functions();
|
||||
|
||||
$categories = \Controllers\Category\CategoryController::getAllCategories($hesk_settings);
|
||||
|
||||
output($categories);
|
Loading…
x
Reference in New Issue
Block a user