diff --git a/api/ApplicationContext.php b/api/ApplicationContext.php index 40f8d002..8dbb6079 100644 --- a/api/ApplicationContext.php +++ b/api/ApplicationContext.php @@ -51,66 +51,51 @@ class ApplicationContext { function __construct() { $this->get = array(); - // Permissions $this->get[PermissionChecker::class] = new PermissionChecker(); - - // Settings $this->get[ModsForHeskSettingsGateway::class] = new ModsForHeskSettingsGateway(); - - // API Checker - $this->get[ApiChecker::class] = new ApiChecker($this->get[ModsForHeskSettingsGateway::class]); - - // Custom Navigation $this->get[CustomNavElementGateway::class] = new CustomNavElementGateway(); - $this->get[CustomNavElementHandler::class] = new CustomNavElementHandler($this->get[CustomNavElementGateway::class]); - - // Logging $this->get[LoggingGateway::class] = new LoggingGateway(); - - // 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]); - - // Categories $this->get[CategoryGateway::class] = new CategoryGateway(); + $this->get[BanGateway::class] = new BanGateway(); + $this->get[StatusGateway::class] = new StatusGateway(); + $this->get[BasicEmailSender::class] = new BasicEmailSender(); + $this->get[MailgunEmailSender::class] = new MailgunEmailSender(); + $this->get[EmailTemplateRetriever::class] = new EmailTemplateRetriever(); + $this->get[TicketGateway::class] = new TicketGateway(); + $this->get[FileWriter::class] = new FileWriter(); + $this->get[FileReader::class] = new FileReader(); + $this->get[FileDeleter::class] = new FileDeleter(); + $this->get[AttachmentGateway::class] = new AttachmentGateway(); + + $this->get[ApiChecker::class] = new ApiChecker($this->get[ModsForHeskSettingsGateway::class]); + $this->get[CustomNavElementHandler::class] = new CustomNavElementHandler($this->get[CustomNavElementGateway::class]); + $this->get[VerifiedEmailChecker::class] = new VerifiedEmailChecker($this->get[VerifiedEmailGateway::class]); + $this->get[UserContextBuilder::class] = new UserContextBuilder($this->get[UserGateway::class]); + $this->get[BanRetriever::class] = new BanRetriever($this->get[BanGateway::class]); + $this->get[UserToTicketChecker::class] = new UserToTicketChecker($this->get[UserGateway::class]); + $this->get[StatusRetriever::class] = new StatusRetriever($this->get[StatusGateway::class]); + $this->get[SettingsRetriever::class] = new SettingsRetriever($this->get[ModsForHeskSettingsGateway::class]); + $this->get[TicketValidators::class] = new TicketValidators($this->get[TicketGateway::class]); + $this->get[TrackingIdGenerator::class] = new TrackingIdGenerator($this->get[TicketGateway::class]); + $this->get[Autoassigner::class] = new Autoassigner($this->get[CategoryGateway::class], $this->get[UserGateway::class]); $this->get[CategoryRetriever::class] = new CategoryRetriever($this->get[CategoryGateway::class], $this->get[ModsForHeskSettingsGateway::class]); $this->get[CategoryHandler::class] = new CategoryHandler( $this->get[CategoryGateway::class], + $this->get[TicketGateway::class], $this->get[PermissionChecker::class], $this->get[ModsForHeskSettingsGateway::class]); - - // Bans - $this->get[BanGateway::class] = new BanGateway(); - $this->get[BanRetriever::class] = new BanRetriever($this->get[BanGateway::class]); - - // 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[UserToTicketChecker::class] = new UserToTicketChecker($this->get[UserGateway::class]); - $this->get[TicketGateway::class] = new TicketGateway(); $this->get[TicketRetriever::class] = new TicketRetriever($this->get[TicketGateway::class], $this->get[UserToTicketChecker::class]); - $this->get[TicketValidators::class] = new TicketValidators($this->get[TicketGateway::class]); - $this->get[TrackingIdGenerator::class] = new TrackingIdGenerator($this->get[TicketGateway::class]); - $this->get[Autoassigner::class] = new Autoassigner($this->get[CategoryGateway::class], $this->get[UserGateway::class]); $this->get[NewTicketValidator::class] = new NewTicketValidator($this->get[CategoryRetriever::class], $this->get[BanRetriever::class], $this->get[TicketValidators::class]); @@ -123,10 +108,6 @@ class ApplicationContext { $this->get[EmailSenderHelper::class], $this->get[UserGateway::class], $this->get[ModsForHeskSettingsGateway::class]); - $this->get[FileWriter::class] = new FileWriter(); - $this->get[FileReader::class] = new FileReader(); - $this->get[FileDeleter::class] = new FileDeleter(); - $this->get[AttachmentGateway::class] = new AttachmentGateway(); $this->get[AttachmentHandler::class] = new AttachmentHandler($this->get[TicketGateway::class], $this->get[AttachmentGateway::class], $this->get[FileWriter::class], @@ -142,11 +123,5 @@ class ApplicationContext { $this->get[AttachmentHandler::class]); $this->get[TicketEditor::class] = new TicketEditor($this->get[TicketGateway::class], $this->get[UserToTicketChecker::class]); - - // Statuses - $this->get[StatusRetriever::class] = new StatusRetriever($this->get[StatusGateway::class]); - - // Settings - $this->get[SettingsRetriever::class] = new SettingsRetriever($this->get[ModsForHeskSettingsGateway::class]); } } \ No newline at end of file diff --git a/api/BusinessLogic/Categories/CategoryHandler.php b/api/BusinessLogic/Categories/CategoryHandler.php index 2df16882..8c6c42ca 100644 --- a/api/BusinessLogic/Categories/CategoryHandler.php +++ b/api/BusinessLogic/Categories/CategoryHandler.php @@ -11,19 +11,24 @@ use BusinessLogic\Security\UserPrivilege; use BusinessLogic\ValidationModel; use DataAccess\Categories\CategoryGateway; use DataAccess\Settings\ModsForHeskSettingsGateway; +use DataAccess\Tickets\TicketGateway; class CategoryHandler { /* @var $categoryGateway CategoryGateway */ private $categoryGateway; + /* @var $ticketGateway TicketGateway */ + private $ticketGateway; + /* @var $permissionChecker PermissionChecker */ private $permissionChecker; /* @var $modsForHeskSettingsGateway ModsForHeskSettingsGateway */ private $modsForHeskSettingsGateway; - function __construct($categoryGateway, $permissionChecker, $modsForHeskSettingsGateway) { + function __construct($categoryGateway, $ticketGateway, $permissionChecker, $modsForHeskSettingsGateway) { $this->categoryGateway = $categoryGateway; + $this->ticketGateway = $ticketGateway; $this->permissionChecker = $permissionChecker; $this->modsForHeskSettingsGateway = $modsForHeskSettingsGateway; } @@ -149,6 +154,11 @@ class CategoryHandler { throw new AccessViolationException('User cannot manage categories!'); } + if ($id === 1) { + throw new \Exception("Category 1 cannot be deleted!"); + } + + $this->ticketGateway->moveTicketsToDefaultCategory($id, $heskSettings); $this->categoryGateway->deleteCategory($id, $heskSettings); $this->categoryGateway->resortAllCategories($heskSettings); } diff --git a/api/DataAccess/Tickets/TicketGateway.php b/api/DataAccess/Tickets/TicketGateway.php index 1645618b..a14d623e 100644 --- a/api/DataAccess/Tickets/TicketGateway.php +++ b/api/DataAccess/Tickets/TicketGateway.php @@ -358,4 +358,14 @@ class TicketGateway extends CommonDao { $this->close(); } + + function moveTicketsToDefaultCategory($oldCategoryId, $heskSettings) { + $this->init(); + + hesk_dbQuery("UPDATE `" . hesk_dbEscape($heskSettings['db_pfix']) . "tickets` + SET `category` = 1 + WHERE `category` = " . intval($oldCategoryId)); + + $this->close(); + } } \ No newline at end of file diff --git a/internal-api/js/manage-categories.js b/internal-api/js/manage-categories.js index 521198d8..853e06e1 100644 --- a/internal-api/js/manage-categories.js +++ b/internal-api/js/manage-categories.js @@ -119,6 +119,10 @@ function loadTable() { .attr('title', mfhLang.text('geco')); } + if (this.id === 1) { + $template.find('[data-action="delete"]').hide(); + } + $tableBody.append($template); categories[this.id] = this;