diff --git a/api/ApplicationContext.php b/api/ApplicationContext.php index 76de8849..3f13facf 100644 --- a/api/ApplicationContext.php +++ b/api/ApplicationContext.php @@ -2,6 +2,11 @@ // Responsible for loading in all necessary classes. AKA a poor man's DI solution. use BusinessLogic\Categories\CategoryRetriever; +use BusinessLogic\Emails\BasicEmailSender; +use BusinessLogic\Emails\EmailSenderHelper; +use BusinessLogic\Emails\EmailTemplateParser; +use BusinessLogic\Emails\EmailTemplateRetriever; +use BusinessLogic\Emails\MailgunEmailSender; use BusinessLogic\Security\BanRetriever; use BusinessLogic\Security\UserContextBuilder; use BusinessLogic\Tickets\Autoassigner; @@ -10,11 +15,13 @@ use BusinessLogic\Tickets\TicketCreator; use BusinessLogic\Tickets\NewTicketValidator; use BusinessLogic\Tickets\TicketValidators; use BusinessLogic\Tickets\TrackingIdGenerator; +use BusinessLogic\Tickets\VerifiedEmailChecker; use DataAccess\Categories\CategoryGateway; use DataAccess\Security\BanGateway; use DataAccess\Security\UserGateway; use DataAccess\Statuses\StatusGateway; use DataAccess\Tickets\TicketGateway; +use DataAccess\Tickets\VerifiedEmailGateway; class ApplicationContext { @@ -23,7 +30,11 @@ class ApplicationContext { function __construct() { $this->get = array(); - // User Context + // Verified Email Checker + $this->get[VerifiedEmailGateway::class] = new VerifiedEmailGateway(); + $this->get[VerifiedEmailChecker::class] = new VerifiedEmailChecker($this->get[VerifiedEmailGateway::class]); + + // Users $this->get[UserGateway::class] = new UserGateway(); $this->get[UserContextBuilder::class] = new UserContextBuilder($this->get[UserGateway::class]); @@ -35,8 +46,22 @@ class ApplicationContext { $this->get[BanGateway::class] = new BanGateway(); $this->get[BanRetriever::class] = new BanRetriever($this->get[BanGateway::class]); - // Tickets + // Statuses $this->get[StatusGateway::class] = new StatusGateway(); + + // Email Sender + $this->get[EmailTemplateRetriever::class] = new EmailTemplateRetriever(); + $this->get[EmailTemplateParser::class] = new EmailTemplateParser($this->get[StatusGateway::class], + $this->get[CategoryGateway::class], + $this->get[UserGateway::class], + $this->get[EmailTemplateRetriever::class]); + $this->get[BasicEmailSender::class] = new BasicEmailSender(); + $this->get[MailgunEmailSender::class] = new MailgunEmailSender(); + $this->get[EmailSenderHelper::class] = new EmailSenderHelper($this->get[EmailTemplateParser::class], + $this->get[BasicEmailSender::class], + $this->get[MailgunEmailSender::class]); + + // Tickets $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]); @@ -49,6 +74,9 @@ class ApplicationContext { $this->get[TrackingIdGenerator::class], $this->get[Autoassigner::class], $this->get[StatusGateway::class], - $this->get[TicketGateway::class]); + $this->get[TicketGateway::class], + $this->get[VerifiedEmailChecker::class], + $this->get[EmailSenderHelper::class], + $this->get[UserGateway::class]); } } \ No newline at end of file diff --git a/api/BusinessLogic/Tickets/TicketCreator.php b/api/BusinessLogic/Tickets/TicketCreator.php index 46a17589..a6d1225f 100644 --- a/api/BusinessLogic/Tickets/TicketCreator.php +++ b/api/BusinessLogic/Tickets/TicketCreator.php @@ -148,6 +148,8 @@ class TicketCreator { $addressees = new Addressees(); $addressees->to = array($ownerEmail); $this->emailSenderHelper->sendEmailForTicket(EmailTemplateRetriever::TICKET_ASSIGNED_TO_YOU, $ticketRequest->language, $addressees, $ticket, $heskSettings, $modsForHeskSettings); + } else { + // TODO email all users who should be notified } return $ticket; diff --git a/api/DataAccess/Entities/BaseEntity.php b/api/DataAccess/Entities/BaseEntity.php deleted file mode 100644 index ccc77d62..00000000 --- a/api/DataAccess/Entities/BaseEntity.php +++ /dev/null @@ -1,14 +0,0 @@ - ['type' => 'integer', 'primary' => true, 'autoincrement' => true], - 'user' => ['type' => 'string', 'required' => true, 'default' => ''], - 'pass' => ['type' => 'string', 'required' => true], - 'isadmin' => ['type' => 'string', 'required' => true, 'default' => '0'], - 'name' => ['type' => 'string', 'required' => true, 'default' => ''], - 'email' => ['type' => 'string', 'required' => true, 'default' => ''], - 'signature' => ['type' => 'string', 'required' => true, 'default' => ''], - 'language' => ['type' => 'string', 'required' => false], - 'categories' => ['type' => 'string', 'required' => true, 'default' => ''], - 'afterreply' => ['type' => 'string', 'required' => true, 'default' => '0'], - 'autostart' => ['type' => 'string', 'required' => true, 'default' => '1'], - 'autoreload' => ['type' => 'smallint', 'required' => true, 'default' => 0], - 'notify_customer_new' => ['type' => 'string', 'required' => true, 'default' => '1'], - 'notify_customer_reply' => ['type' => 'string', 'required' => true, 'default' => '1'], - 'show_suggested' => ['type' => 'string', 'required' => true, 'default' => '1'], - 'notify_new_unassigned' => ['type' => 'string', 'required' => true, 'default' => '1'], - 'notify_new_my' => ['type' => 'string', 'required' => true, 'default' => '1'], - 'notify_reply_unassigned' => ['type' => 'string', 'required' => true, 'default' => '1'], - 'notify_reply_my' => ['type' => 'string', 'required' => true, 'default' => '1'], - 'notify_assigned' => ['type' => 'string', 'required' => true, 'default' => '1'], - 'notify_pm' => ['type' => 'string', 'required' => true, 'default' => '1'], - 'notify_note' => ['type' => 'string', 'required' => true, 'default' => '1'], - 'notify_note_unassigned' => ['type' => 'string', 'required' => false, 'default' => '0'], - 'default_calendar_view' => ['type' => 'integer', 'required' => true, 'default' => '0'], - 'notify_overdue_unassigned' => ['type' => 'string', 'required' => true, 'default' => '0'], - 'default_list' => ['type' => 'string', 'required' => true, 'default' => ''], - 'autoassign' => ['type' => 'string', 'required' => true, 'default' => '1'], - 'heskprivileges' => ['type' => 'string', 'required' => false], - 'ratingneg' => ['type' => 'integer', 'required' => true, 'default' => 0], - 'ratingpos' => ['type' => 'integer', 'required' => true, 'default' => 0], - 'rating' => ['type' => 'float', 'required' => true, 'default' => 0], - 'replies' => ['type' => 'integer', 'required' => true, 'default' => 0], - 'active' => ['type' => 'string', 'required' => true, 'default' => '1'], - 'permission_template' => ['type' => 'integer', 'required' => false] - ]; - //@formatter:on - } -} \ No newline at end of file diff --git a/api/autoload.php b/api/autoload.php index acdb59e9..e06961f9 100644 --- a/api/autoload.php +++ b/api/autoload.php @@ -4,7 +4,7 @@ // Core requirements define('IN_SCRIPT', 1); define('HESK_PATH', '../'); -require_once(__DIR__ . 'vendor/autoload.php'); +require_once(__DIR__ . '/vendor/autoload.php'); require_once(__DIR__ . '/bootstrap.php'); require_once(__DIR__ . '/../hesk_settings.inc.php'); require_once(__DIR__ . '/../inc/common.inc.php'); @@ -19,11 +19,6 @@ global $hesk_settings; // HESK files that require database access require_once(__DIR__ . '/../inc/custom_fields.inc.php'); -// Load Spot ORM -$config = new \Spot\Config(); -$config->addConnection('mysql', "mysql://{$hesk_settings['db_user']}:{$hesk_settings['db_pass']}@{$hesk_settings['db_host']}/{$hesk_settings['db_name']}"); -$spot = new \Spot\Locator($config); - // Load the ApplicationContext $applicationContext = new \ApplicationContext(); //$modsForHeskSettings = mfh_getSettings(); \ No newline at end of file diff --git a/api/composer.json b/api/composer.json index 3c793199..8b3f0002 100644 --- a/api/composer.json +++ b/api/composer.json @@ -16,7 +16,6 @@ "php-http/guzzle6-adapter": "^1.1", "php-http/message": "^1.5", "php-http/curl-client": "^1.7", - "guzzlehttp/psr7": "^1.3", - "vlucas/spot2": "~2.0" + "guzzlehttp/psr7": "^1.3" } } diff --git a/api/index.php b/api/index.php index d6932a50..3010cddf 100644 --- a/api/index.php +++ b/api/index.php @@ -34,13 +34,20 @@ function buildUserContext($xAuthToken) { } function errorHandler($errorNumber, $errorMessage, $errorFile, $errorLine) { - exceptionHandler(new Exception(sprintf("%s:%d\n\n%s", $errorFile, $errorLine, $errorMessage))); + if ($errorNumber === E_WARNING) { + //-- TODO log a warning + } elseif ($errorNumber === E_NOTICE || $errorNumber === E_USER_NOTICE) { + //-- TODO log an info + } else { + exceptionHandler(new Exception(sprintf("%s:%d\n\n%s", $errorFile, $errorLine, $errorMessage))); + } } /** * @param $exception Exception */ function exceptionHandler($exception) { + //-- TODO Log an error if (exceptionIsOfType($exception, \BusinessLogic\Exceptions\ApiFriendlyException::class)) { /* @var $castedException \BusinessLogic\Exceptions\ApiFriendlyException */ $castedException = $exception;