feat(helpdesk): add software updates tracking with BC ticket integration
New Updates page in the Helpdesk module that fetches UPDATE/UPDATE-HF tickets from Business Central (PBI_LV_Tickets) and allows assigning a domain and Gitea link via a dialog. Ticket status (from BC) and assignment status (local) are shown as separate columns with filters for both plus type and free-text search. Assigned updates also appear on the domain detail page. Includes session-cached BC fetch with refresh button, admin permissions, migration, and 16 unit tests. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -16,6 +16,10 @@ final class HelpdeskAuthorizationPolicy implements AuthorizationPolicyInterface
|
||||
public const ABILITY_HANDOVERS_VIEW = 'helpdesk.handovers.view';
|
||||
public const ABILITY_HANDOVERS_CREATE = 'helpdesk.handovers.create';
|
||||
public const ABILITY_HANDOVERS_MANAGE = 'helpdesk.handovers.manage';
|
||||
/** @api Used in pages/helpdesk/updates action files */
|
||||
public const ABILITY_UPDATES_VIEW = 'helpdesk.updates.view';
|
||||
/** @api Used in pages/helpdesk/updates action files */
|
||||
public const ABILITY_UPDATES_MANAGE = 'helpdesk.updates.manage';
|
||||
|
||||
public const PERMISSION_ACCESS = 'helpdesk.access';
|
||||
public const PERMISSION_SETTINGS_MANAGE = 'helpdesk.settings.manage';
|
||||
@@ -29,6 +33,10 @@ final class HelpdeskAuthorizationPolicy implements AuthorizationPolicyInterface
|
||||
public const PERMISSION_HANDOVERS_CREATE = 'helpdesk.handovers.create';
|
||||
/** @api Used in authorize() match for ability resolution */
|
||||
public const PERMISSION_HANDOVERS_MANAGE = 'helpdesk.handovers.manage';
|
||||
/** @api Used in authorize() match */
|
||||
public const PERMISSION_UPDATES_VIEW = 'helpdesk.updates.view';
|
||||
/** @api Used in authorize() match */
|
||||
public const PERMISSION_UPDATES_MANAGE = 'helpdesk.updates.manage';
|
||||
|
||||
public function __construct(
|
||||
private readonly PermissionService $permissionService
|
||||
@@ -37,7 +45,7 @@ final class HelpdeskAuthorizationPolicy implements AuthorizationPolicyInterface
|
||||
|
||||
public function supports(string $ability): bool
|
||||
{
|
||||
return in_array($ability, [self::ABILITY_ACCESS, self::ABILITY_SETTINGS_MANAGE, self::ABILITY_TEAM_WORKLOAD, self::ABILITY_RISK_RADAR, self::ABILITY_SOFTWARE_PRODUCTS_MANAGE, self::ABILITY_HANDOVERS_VIEW, self::ABILITY_HANDOVERS_CREATE, self::ABILITY_HANDOVERS_MANAGE], true);
|
||||
return in_array($ability, [self::ABILITY_ACCESS, self::ABILITY_SETTINGS_MANAGE, self::ABILITY_TEAM_WORKLOAD, self::ABILITY_RISK_RADAR, self::ABILITY_SOFTWARE_PRODUCTS_MANAGE, self::ABILITY_HANDOVERS_VIEW, self::ABILITY_HANDOVERS_CREATE, self::ABILITY_HANDOVERS_MANAGE, self::ABILITY_UPDATES_VIEW, self::ABILITY_UPDATES_MANAGE], true);
|
||||
}
|
||||
|
||||
public function authorize(string $ability, array $context = []): AuthorizationDecision
|
||||
@@ -56,6 +64,8 @@ final class HelpdeskAuthorizationPolicy implements AuthorizationPolicyInterface
|
||||
self::ABILITY_HANDOVERS_VIEW => self::PERMISSION_HANDOVERS_VIEW,
|
||||
self::ABILITY_HANDOVERS_CREATE => self::PERMISSION_HANDOVERS_CREATE,
|
||||
self::ABILITY_HANDOVERS_MANAGE => self::PERMISSION_HANDOVERS_MANAGE,
|
||||
self::ABILITY_UPDATES_VIEW => self::PERMISSION_UPDATES_VIEW,
|
||||
self::ABILITY_UPDATES_MANAGE => self::PERMISSION_UPDATES_MANAGE,
|
||||
default => null,
|
||||
};
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ use MintyPHP\Module\Helpdesk\Service\BcODataGateway;
|
||||
use MintyPHP\Module\Helpdesk\Service\BcSoapGateway;
|
||||
use MintyPHP\Module\Helpdesk\Service\DebitorDetailService;
|
||||
use MintyPHP\Module\Helpdesk\Service\DebitorSearchService;
|
||||
use MintyPHP\Module\Helpdesk\Service\DomainDetailService;
|
||||
use MintyPHP\Module\Helpdesk\Service\EffectiveHelpdeskSettingsService;
|
||||
use MintyPHP\Module\Helpdesk\Service\HelpdeskOAuthTokenService;
|
||||
use MintyPHP\Module\Helpdesk\Service\HelpdeskSettingsGateway;
|
||||
@@ -23,8 +24,10 @@ use MintyPHP\Module\Helpdesk\Handler\SoftwareProductSyncJobHandler;
|
||||
use MintyPHP\Module\Helpdesk\Repository\HandoverRepository;
|
||||
use MintyPHP\Module\Helpdesk\Repository\HandoverRevisionRepository;
|
||||
use MintyPHP\Module\Helpdesk\Repository\SoftwareProductRepository;
|
||||
use MintyPHP\Module\Helpdesk\Repository\UpdateRepository;
|
||||
use MintyPHP\Module\Helpdesk\Service\HandoverRevisionService;
|
||||
use MintyPHP\Module\Helpdesk\Service\HandoverService;
|
||||
use MintyPHP\Module\Helpdesk\Service\UpdateService;
|
||||
use MintyPHP\Service\Access\PermissionService;
|
||||
use MintyPHP\Service\Settings\SettingServicesFactory;
|
||||
use MintyPHP\Service\Settings\SettingsMetadataGateway;
|
||||
@@ -86,6 +89,13 @@ final class HelpdeskContainerRegistrar implements ContainerRegistrar
|
||||
$c->get(EffectiveHelpdeskSettingsService::class)
|
||||
));
|
||||
|
||||
$container->set(DomainDetailService::class, static fn (AppContainer $c): DomainDetailService => new DomainDetailService(
|
||||
$c->get(BcODataGateway::class),
|
||||
$c->get(EffectiveHelpdeskSettingsService::class),
|
||||
$c->get(HandoverRepository::class),
|
||||
$c->get(UpdateRepository::class)
|
||||
));
|
||||
|
||||
$container->set(TicketCommunicationService::class, static fn (AppContainer $c): TicketCommunicationService => new TicketCommunicationService(
|
||||
$c->get(BcSoapGateway::class),
|
||||
$c->get(BcODataGateway::class)
|
||||
@@ -123,5 +133,12 @@ final class HelpdeskContainerRegistrar implements ContainerRegistrar
|
||||
$c->get(SoftwareProductService::class),
|
||||
$c->get(HandoverRevisionService::class)
|
||||
));
|
||||
|
||||
$container->set(UpdateRepository::class, static fn (): UpdateRepository => new UpdateRepository());
|
||||
|
||||
$container->set(UpdateService::class, static fn (AppContainer $c): UpdateService => new UpdateService(
|
||||
$c->get(UpdateRepository::class),
|
||||
$c->get(BcODataGateway::class)
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,7 @@ final class HelpdeskLayoutProvider implements LayoutContextProvider
|
||||
$canViewHandovers = $authorizationService->authorize('helpdesk.handovers.view', $actorContext)->isAllowed();
|
||||
$canCreateHandovers = $authorizationService->authorize('helpdesk.handovers.create', $actorContext)->isAllowed();
|
||||
$canManageHandovers = $authorizationService->authorize('helpdesk.handovers.manage', $actorContext)->isAllowed();
|
||||
$canViewUpdates = $authorizationService->authorize('helpdesk.updates.view', $actorContext)->isAllowed();
|
||||
} catch (\Throwable) {
|
||||
$canManageSettings = false;
|
||||
$canViewTeam = false;
|
||||
@@ -33,6 +34,7 @@ final class HelpdeskLayoutProvider implements LayoutContextProvider
|
||||
$canViewHandovers = false;
|
||||
$canCreateHandovers = false;
|
||||
$canManageHandovers = false;
|
||||
$canViewUpdates = false;
|
||||
}
|
||||
|
||||
return ['helpdesk.nav' => [
|
||||
@@ -43,6 +45,7 @@ final class HelpdeskLayoutProvider implements LayoutContextProvider
|
||||
'can_view_handovers' => $canViewHandovers,
|
||||
'can_create_handovers' => $canCreateHandovers,
|
||||
'can_manage_handovers' => $canManageHandovers,
|
||||
'can_view_updates' => $canViewUpdates,
|
||||
]];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,179 @@
|
||||
<?php
|
||||
|
||||
namespace MintyPHP\Module\Helpdesk\Repository;
|
||||
|
||||
use MintyPHP\DB;
|
||||
use MintyPHP\Repository\Support\RepoQuery;
|
||||
|
||||
class UpdateRepository
|
||||
{
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
* @return int|null Inserted ID or null on failure
|
||||
*/
|
||||
public function insert(array $data): ?int
|
||||
{
|
||||
$result = DB::insert(
|
||||
'INSERT INTO helpdesk_updates '
|
||||
. '(tenant_id, ticket_no, category_code, debitor_no, debitor_name, domain_no, domain_url, gitea_path, notes, status, created_by) '
|
||||
. 'VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
|
||||
(string) ($data['tenant_id'] ?? 0),
|
||||
(string) ($data['ticket_no'] ?? ''),
|
||||
(string) ($data['category_code'] ?? ''),
|
||||
(string) ($data['debitor_no'] ?? ''),
|
||||
(string) ($data['debitor_name'] ?? ''),
|
||||
(string) ($data['domain_no'] ?? ''),
|
||||
(string) ($data['domain_url'] ?? ''),
|
||||
(string) ($data['gitea_path'] ?? ''),
|
||||
$data['notes'] ?? null,
|
||||
(string) ($data['status'] ?? 'open'),
|
||||
(string) ($data['created_by'] ?? 0)
|
||||
);
|
||||
|
||||
if ($result === false) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (int) $result;
|
||||
}
|
||||
|
||||
public function findById(int $tenantId, int $id): ?array
|
||||
{
|
||||
if ($id <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$row = DB::selectOne(
|
||||
'SELECT u.*,'
|
||||
. ' uc.display_name AS created_by_label, uc.uuid AS created_by_uuid,'
|
||||
. ' uu.display_name AS updated_by_label, uu.uuid AS updated_by_uuid'
|
||||
. ' FROM helpdesk_updates u'
|
||||
. ' LEFT JOIN users uc ON uc.id = u.created_by'
|
||||
. ' LEFT JOIN users uu ON uu.id = u.updated_by'
|
||||
. ' WHERE u.id = ? AND u.tenant_id = ? LIMIT 1',
|
||||
(string) $id,
|
||||
(string) $tenantId
|
||||
);
|
||||
|
||||
return $this->normalizeRow($row);
|
||||
}
|
||||
|
||||
public function findByTicketNo(int $tenantId, string $ticketNo): ?array
|
||||
{
|
||||
if ($ticketNo === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$row = DB::selectOne(
|
||||
'SELECT u.*,'
|
||||
. ' uc.display_name AS created_by_label'
|
||||
. ' FROM helpdesk_updates u'
|
||||
. ' LEFT JOIN users uc ON uc.id = u.created_by'
|
||||
. ' WHERE u.tenant_id = ? AND u.ticket_no = ? LIMIT 1',
|
||||
(string) $tenantId,
|
||||
$ticketNo
|
||||
);
|
||||
|
||||
return $this->normalizeRow($row);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array<string, mixed>>
|
||||
*/
|
||||
public function findByDomainNo(int $tenantId, string $domainNo): array
|
||||
{
|
||||
if ($domainNo === '') {
|
||||
return [];
|
||||
}
|
||||
|
||||
$rows = DB::select(
|
||||
'SELECT u.*,'
|
||||
. ' uc.display_name AS created_by_label'
|
||||
. ' FROM helpdesk_updates u'
|
||||
. ' LEFT JOIN users uc ON uc.id = u.created_by'
|
||||
. ' WHERE u.tenant_id = ? AND u.domain_no = ?'
|
||||
. ' ORDER BY u.created_at DESC',
|
||||
(string) $tenantId,
|
||||
$domainNo
|
||||
);
|
||||
|
||||
return $this->normalizeRows($rows);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array<string, mixed>>
|
||||
*/
|
||||
public function findAllByTenant(int $tenantId): array
|
||||
{
|
||||
$rows = DB::select(
|
||||
'SELECT u.ticket_no, u.domain_no, u.domain_url, u.gitea_path, u.notes, u.status,'
|
||||
. ' u.category_code, u.debitor_no, u.id'
|
||||
. ' FROM helpdesk_updates u'
|
||||
. ' WHERE u.tenant_id = ?',
|
||||
(string) $tenantId
|
||||
);
|
||||
|
||||
return $this->normalizeRows($rows);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, mixed> $data
|
||||
*/
|
||||
public function updateAssignment(int $tenantId, int $id, array $data): bool
|
||||
{
|
||||
$result = DB::update(
|
||||
'UPDATE helpdesk_updates SET domain_no = ?, domain_url = ?, gitea_path = ?, notes = ?, status = ?, updated_by = ? WHERE id = ? AND tenant_id = ?',
|
||||
(string) ($data['domain_no'] ?? ''),
|
||||
(string) ($data['domain_url'] ?? ''),
|
||||
(string) ($data['gitea_path'] ?? ''),
|
||||
$data['notes'] ?? null,
|
||||
(string) ($data['status'] ?? 'assigned'),
|
||||
(string) ($data['updated_by'] ?? 0),
|
||||
(string) $id,
|
||||
(string) $tenantId
|
||||
);
|
||||
|
||||
return $result !== false;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param mixed $rows
|
||||
* @return list<array<string, mixed>>
|
||||
*/
|
||||
private function normalizeRows(mixed $rows): array
|
||||
{
|
||||
$normalized = [];
|
||||
if (is_array($rows)) {
|
||||
foreach ($rows as $row) {
|
||||
$item = $this->normalizeRow($row);
|
||||
if ($item !== null) {
|
||||
$normalized[] = $item;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $normalized;
|
||||
}
|
||||
|
||||
private function normalizeRow(mixed $row): ?array
|
||||
{
|
||||
if (!is_array($row)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$item = [];
|
||||
foreach ($row as $key => $value) {
|
||||
if (is_array($value)) {
|
||||
$item = array_merge($item, $value);
|
||||
} else {
|
||||
$item[$key] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
if (!isset($item['id']) && !isset($item['ticket_no'])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $item;
|
||||
}
|
||||
}
|
||||
@@ -24,6 +24,8 @@ class BcODataGateway
|
||||
public const ENTITY_MEETINGS = 'FS_Debitor_Meetings';
|
||||
/** @api Used by listContractTypes() */
|
||||
public const ENTITY_CONTRACT_TYPES = 'FS_Contract_Types';
|
||||
/** @api Used by handover-domains-data endpoint and domains-data endpoint */
|
||||
public const ENTITY_CONTRACT_DOMAINS = 'FS_Contract_Domains';
|
||||
|
||||
private const CONNECT_TIMEOUT = 10;
|
||||
private const REQUEST_TIMEOUT = 30;
|
||||
@@ -687,6 +689,62 @@ class BcODataGateway
|
||||
return ['tickets' => $allTickets, 'truncated' => $truncated];
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch all update/hotfix tickets across all customers.
|
||||
*
|
||||
* Queries PBI_LV_Tickets with Category_1_Code filter for UPDATE and UPDATE-HF.
|
||||
* Results are cached in session with standard TTL.
|
||||
* Uses pagination via @odata.nextLink (same as risk radar).
|
||||
*
|
||||
* @return array{tickets: array<int, array<string, mixed>>, truncated: bool}
|
||||
*/
|
||||
public function fetchUpdateTickets(): array
|
||||
{
|
||||
$tenantScope = DebitorCacheControl::resolveTenantScope($this->sessionStore->all());
|
||||
$cacheKey = DebitorCacheControl::updateTicketsKey($tenantScope);
|
||||
$cached = $this->sessionStore->get($cacheKey);
|
||||
if (is_array($cached) && isset($cached['fetched_at']) && (time() - (int) $cached['fetched_at']) < DebitorCacheControl::TTL_STANDARD_SECONDS) {
|
||||
$tickets = $cached['tickets'] ?? [];
|
||||
$truncated = (bool) ($cached['truncated'] ?? false);
|
||||
if (is_array($tickets)) {
|
||||
return ['tickets' => $tickets, 'truncated' => $truncated];
|
||||
}
|
||||
}
|
||||
|
||||
$select = 'No,Description,Customer_No,Cust_Name,Category_1_Code,Ticket_State,Created_On,Last_Activity_Date,Support_User_Name';
|
||||
$baseUrl = $this->settingsGateway->buildEntityUrl(self::ENTITY_TICKETS_LV);
|
||||
|
||||
// BC OData often rejects `or` in $filter — fetch each category separately and merge.
|
||||
$allTickets = [];
|
||||
$truncated = false;
|
||||
foreach (['UPDATE', 'UPDATE-HF'] as $category) {
|
||||
$filter = "Category_1_Code eq '" . $category . "'";
|
||||
$url = $baseUrl
|
||||
. '?$top=500'
|
||||
. '&$select=' . rawurlencode($select)
|
||||
. '&$filter=' . rawurlencode($filter)
|
||||
. '&$orderby=' . rawurlencode('Created_On desc');
|
||||
|
||||
$partial = $this->paginateOData($url, 10);
|
||||
foreach ($partial['tickets'] as $ticket) {
|
||||
$allTickets[] = $ticket;
|
||||
}
|
||||
if ($partial['truncated']) {
|
||||
$truncated = true;
|
||||
}
|
||||
}
|
||||
|
||||
$result = ['tickets' => $this->dedupeRowsByNo($allTickets), 'truncated' => $truncated];
|
||||
|
||||
$this->sessionStore->set($cacheKey, [
|
||||
'tickets' => $result['tickets'],
|
||||
'truncated' => $result['truncated'],
|
||||
'fetched_at' => time(),
|
||||
]);
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get contracts for a customer by customer number.
|
||||
*
|
||||
@@ -798,6 +856,116 @@ class BcODataGateway
|
||||
return $this->extractODataValues($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all domains (unfiltered, for the domains list page).
|
||||
*
|
||||
* @api Called from domains-data endpoint
|
||||
* @return array<int, array<string, mixed>>
|
||||
*/
|
||||
public function listDomains(): array
|
||||
{
|
||||
$select = 'No,Customer_No,Customer_Name,URL,State,Administration';
|
||||
$url = $this->settingsGateway->buildEntityUrl(self::ENTITY_CONTRACT_DOMAINS)
|
||||
. '?$top=5000'
|
||||
. '&$select=' . rawurlencode($select)
|
||||
. '&$orderby=' . rawurlencode('Customer_Name asc');
|
||||
|
||||
$response = $this->request('GET', $url);
|
||||
if ($response === null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $this->extractODataValues($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all contract lines of type "Domain".
|
||||
*
|
||||
* Returns contract line metadata for domain-type lines,
|
||||
* keyed by DNS number (No field). Used to enrich the domain
|
||||
* list with contract type information (PI_Header_Type).
|
||||
*
|
||||
* @return array<int, array<string, mixed>>
|
||||
*/
|
||||
public function listDomainContractLines(): array
|
||||
{
|
||||
$filter = "Type eq 'Domain'";
|
||||
$select = 'No,Header_No,PI_Header_Type,PI_Header_Description,PI_Header_State,Line_State';
|
||||
$url = $this->settingsGateway->buildEntityUrl(self::ENTITY_CONTRACT_LINES)
|
||||
. '?$filter=' . rawurlencode($filter)
|
||||
. '&$top=5000'
|
||||
. '&$select=' . rawurlencode($select)
|
||||
. '&$orderby=' . rawurlencode('No asc');
|
||||
|
||||
$response = $this->request('GET', $url);
|
||||
if ($response === null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $this->extractODataValues($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a single domain by its domain number.
|
||||
*
|
||||
* @api Called from domain($id) action
|
||||
* @return array<string, mixed>|null
|
||||
*/
|
||||
public function getDomain(string $domainNo): ?array
|
||||
{
|
||||
$domainNo = trim($domainNo);
|
||||
if ($domainNo === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$escaped = $this->escapeODataStrictUserInput($domainNo);
|
||||
$filter = "No eq '" . $escaped . "'";
|
||||
$select = 'No,Customer_No,Customer_Name,URL,State,Administration';
|
||||
$url = $this->settingsGateway->buildEntityUrl(self::ENTITY_CONTRACT_DOMAINS)
|
||||
. '?$filter=' . rawurlencode($filter)
|
||||
. '&$top=1'
|
||||
. '&$select=' . rawurlencode($select);
|
||||
|
||||
$response = $this->request('GET', $url);
|
||||
if ($response === null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$values = $this->extractODataValues($response);
|
||||
|
||||
return $values[0] ?? null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get active domains for a customer.
|
||||
*
|
||||
* @api Called from handover-domains-data endpoint
|
||||
* @return array<int, array<string, mixed>>
|
||||
*/
|
||||
public function getDomainsForCustomer(string $customerNo): array
|
||||
{
|
||||
$customerNo = trim($customerNo);
|
||||
if ($customerNo === '') {
|
||||
return [];
|
||||
}
|
||||
|
||||
$escaped = $this->escapeODataStrictUserInput($customerNo);
|
||||
$filter = "Customer_No eq '" . $escaped . "' and State eq 'Aktiv'";
|
||||
$select = 'No,Customer_No,URL,State';
|
||||
$url = $this->settingsGateway->buildEntityUrl(self::ENTITY_CONTRACT_DOMAINS)
|
||||
. '?$filter=' . rawurlencode($filter)
|
||||
. '&$top=200'
|
||||
. '&$select=' . rawurlencode($select)
|
||||
. '&$orderby=' . rawurlencode('URL asc');
|
||||
|
||||
$response = $this->request('GET', $url);
|
||||
if ($response === null) {
|
||||
return [];
|
||||
}
|
||||
|
||||
return $this->extractODataValues($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get meetings/appointments for a customer.
|
||||
*
|
||||
|
||||
@@ -97,6 +97,12 @@ final class DebitorCacheControl
|
||||
return 'module.helpdesk.risk-radar.v1.' . $tenantScope . '.' . $periodDays;
|
||||
}
|
||||
|
||||
/** @api Used by BcODataGateway::fetchUpdateTickets() */
|
||||
public static function updateTicketsKey(string $tenantScope): string
|
||||
{
|
||||
return 'module.helpdesk.update-tickets.v1.' . $tenantScope;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, string>
|
||||
*/
|
||||
|
||||
270
modules/helpdesk/lib/Module/Helpdesk/Service/UpdateService.php
Normal file
270
modules/helpdesk/lib/Module/Helpdesk/Service/UpdateService.php
Normal file
@@ -0,0 +1,270 @@
|
||||
<?php
|
||||
|
||||
namespace MintyPHP\Module\Helpdesk\Service;
|
||||
|
||||
use MintyPHP\Module\Helpdesk\Repository\UpdateRepository;
|
||||
|
||||
/** @api Called from pages/helpdesk/updates action files */
|
||||
class UpdateService
|
||||
{
|
||||
public const STATUS_OPEN = 'open';
|
||||
public const STATUS_ASSIGNED = 'assigned';
|
||||
|
||||
public const ALL_STATUSES = [
|
||||
self::STATUS_OPEN,
|
||||
self::STATUS_ASSIGNED,
|
||||
];
|
||||
|
||||
public const CATEGORY_UPDATE = 'UPDATE';
|
||||
public const CATEGORY_HOTFIX = 'UPDATE-HF';
|
||||
|
||||
public const UPDATE_CATEGORIES = [
|
||||
self::CATEGORY_UPDATE,
|
||||
self::CATEGORY_HOTFIX,
|
||||
];
|
||||
|
||||
public function __construct(
|
||||
private readonly UpdateRepository $repository,
|
||||
private readonly BcODataGateway $bcGateway,
|
||||
) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the merged list of BC update tickets with local assignment data.
|
||||
*
|
||||
* Fetches all UPDATE/UPDATE-HF tickets from BC, then left-joins with
|
||||
* local helpdesk_updates records to enrich with domain/gitea assignments.
|
||||
*
|
||||
* @param array<string, mixed> $filters Optional filters: status, category
|
||||
* @return array{rows: list<array<string, mixed>>, truncated: bool}
|
||||
*/
|
||||
public function getUpdatesList(int $tenantId, array $filters = []): array
|
||||
{
|
||||
$bcResult = $this->bcGateway->fetchUpdateTickets();
|
||||
$bcTickets = $bcResult['tickets'];
|
||||
$truncated = $bcResult['truncated'];
|
||||
|
||||
$localRows = $this->repository->findAllByTenant($tenantId);
|
||||
$localByTicketNo = [];
|
||||
foreach ($localRows as $local) {
|
||||
$ticketNo = trim((string) ($local['ticket_no'] ?? ''));
|
||||
if ($ticketNo !== '') {
|
||||
$localByTicketNo[$ticketNo] = $local;
|
||||
}
|
||||
}
|
||||
|
||||
$filterStatus = trim((string) ($filters['status'] ?? ''));
|
||||
$filterCategory = trim((string) ($filters['category'] ?? ''));
|
||||
$filterTicketState = trim((string) ($filters['ticket_state'] ?? ''));
|
||||
$filterSearch = trim((string) ($filters['search'] ?? ''));
|
||||
|
||||
$merged = [];
|
||||
foreach ($bcTickets as $ticket) {
|
||||
$ticketNo = trim((string) ($ticket['No'] ?? ''));
|
||||
if ($ticketNo === '') {
|
||||
continue;
|
||||
}
|
||||
|
||||
$categoryCode = trim((string) ($ticket['Category_1_Code'] ?? ''));
|
||||
if (!in_array($categoryCode, self::UPDATE_CATEGORIES, true)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$local = $localByTicketNo[$ticketNo] ?? null;
|
||||
$status = $local !== null ? (string) ($local['status'] ?? self::STATUS_OPEN) : self::STATUS_OPEN;
|
||||
$ticketState = trim((string) ($ticket['Ticket_State'] ?? ''));
|
||||
|
||||
// Apply filters
|
||||
if ($filterStatus !== '' && $filterStatus !== 'all' && $status !== $filterStatus) {
|
||||
continue;
|
||||
}
|
||||
if ($filterCategory !== '' && $filterCategory !== 'all' && $categoryCode !== $filterCategory) {
|
||||
continue;
|
||||
}
|
||||
if ($filterTicketState !== '' && $filterTicketState !== 'all' && $ticketState !== $filterTicketState) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$debitorNo = trim((string) ($ticket['Customer_No'] ?? ''));
|
||||
$debitorName = trim((string) ($ticket['Cust_Name'] ?? ''));
|
||||
|
||||
// Search filter: match against ticket no, debitor name/no, domain url, gitea path
|
||||
if ($filterSearch !== '') {
|
||||
$searchHaystack = strtolower($ticketNo . ' ' . $debitorName . ' ' . $debitorNo . ' ' . ($local['domain_url'] ?? '') . ' ' . ($local['gitea_path'] ?? ''));
|
||||
if (strpos($searchHaystack, strtolower($filterSearch)) === false) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
$merged[] = [
|
||||
'ticket_no' => $ticketNo,
|
||||
'ticket_description' => trim((string) ($ticket['Description'] ?? '')),
|
||||
'category_code' => $categoryCode,
|
||||
'debitor_no' => $debitorNo,
|
||||
'debitor_name' => $debitorName,
|
||||
'ticket_state' => trim((string) ($ticket['Ticket_State'] ?? '')),
|
||||
'support_user' => trim((string) ($ticket['Support_User_Name'] ?? '')),
|
||||
'created_on' => trim((string) ($ticket['Created_On'] ?? '')),
|
||||
'last_activity' => trim((string) ($ticket['Last_Activity_Date'] ?? '')),
|
||||
'domain_no' => (string) ($local['domain_no'] ?? ''),
|
||||
'domain_url' => (string) ($local['domain_url'] ?? ''),
|
||||
'gitea_path' => (string) ($local['gitea_path'] ?? ''),
|
||||
'notes' => (string) ($local['notes'] ?? ''),
|
||||
'status' => $status,
|
||||
'local_id' => $local !== null ? (int) ($local['id'] ?? 0) : null,
|
||||
];
|
||||
}
|
||||
|
||||
return ['rows' => $merged, 'truncated' => $truncated];
|
||||
}
|
||||
|
||||
/**
|
||||
* Assign a domain and gitea path to an update ticket.
|
||||
*
|
||||
* Creates a new helpdesk_updates record or updates an existing one.
|
||||
*
|
||||
* @return array{ok: bool, id: int|null, errors: array<string, string>}
|
||||
*/
|
||||
public function assignUpdate(
|
||||
int $tenantId,
|
||||
string $ticketNo,
|
||||
string $debitorNo,
|
||||
string $debitorName,
|
||||
string $categoryCode,
|
||||
string $domainNo,
|
||||
string $domainUrl,
|
||||
string $giteaPath,
|
||||
string $notes,
|
||||
int $userId,
|
||||
): array {
|
||||
$errors = [];
|
||||
|
||||
$ticketNo = trim($ticketNo);
|
||||
if ($ticketNo === '') {
|
||||
$errors['ticket_no'] = t('Ticket number is required');
|
||||
}
|
||||
|
||||
$debitorNo = trim($debitorNo);
|
||||
if ($debitorNo === '') {
|
||||
$errors['debitor_no'] = t('Debitor number is required');
|
||||
}
|
||||
|
||||
$categoryCode = trim($categoryCode);
|
||||
if (!in_array($categoryCode, self::UPDATE_CATEGORIES, true)) {
|
||||
$errors['category_code'] = t('Invalid category');
|
||||
}
|
||||
|
||||
if ($errors !== []) {
|
||||
return ['ok' => false, 'id' => null, 'errors' => $errors];
|
||||
}
|
||||
|
||||
$domainNo = trim($domainNo);
|
||||
$domainUrl = trim($domainUrl);
|
||||
$giteaPath = trim($giteaPath);
|
||||
$notes = trim($notes);
|
||||
|
||||
$status = ($domainNo !== '' || $giteaPath !== '') ? self::STATUS_ASSIGNED : self::STATUS_OPEN;
|
||||
|
||||
$existing = $this->repository->findByTicketNo($tenantId, $ticketNo);
|
||||
|
||||
if ($existing !== null) {
|
||||
$existingId = (int) ($existing['id'] ?? 0);
|
||||
if ($existingId <= 0) {
|
||||
return ['ok' => false, 'id' => null, 'errors' => ['general' => t('Failed to save')]];
|
||||
}
|
||||
|
||||
$updated = $this->repository->updateAssignment($tenantId, $existingId, [
|
||||
'domain_no' => $domainNo,
|
||||
'domain_url' => $domainUrl,
|
||||
'gitea_path' => $giteaPath,
|
||||
'notes' => $notes,
|
||||
'status' => $status,
|
||||
'updated_by' => $userId,
|
||||
]);
|
||||
|
||||
if (!$updated) {
|
||||
return ['ok' => false, 'id' => null, 'errors' => ['general' => t('Failed to save')]];
|
||||
}
|
||||
|
||||
return ['ok' => true, 'id' => $existingId, 'errors' => []];
|
||||
}
|
||||
|
||||
$id = $this->repository->insert([
|
||||
'tenant_id' => $tenantId,
|
||||
'ticket_no' => $ticketNo,
|
||||
'category_code' => $categoryCode,
|
||||
'debitor_no' => $debitorNo,
|
||||
'debitor_name' => trim($debitorName),
|
||||
'domain_no' => $domainNo,
|
||||
'domain_url' => $domainUrl,
|
||||
'gitea_path' => $giteaPath,
|
||||
'notes' => $notes,
|
||||
'status' => $status,
|
||||
'created_by' => $userId,
|
||||
]);
|
||||
|
||||
if ($id === null) {
|
||||
return ['ok' => false, 'id' => null, 'errors' => ['general' => t('Failed to save')]];
|
||||
}
|
||||
|
||||
return ['ok' => true, 'id' => $id, 'errors' => []];
|
||||
}
|
||||
|
||||
public static function statusLabel(string $status): string
|
||||
{
|
||||
return match ($status) {
|
||||
self::STATUS_OPEN => t('Unassigned'),
|
||||
self::STATUS_ASSIGNED => t('Assigned'),
|
||||
default => $status,
|
||||
};
|
||||
}
|
||||
|
||||
public static function statusVariant(string $status): string
|
||||
{
|
||||
return match ($status) {
|
||||
self::STATUS_OPEN => 'warning',
|
||||
self::STATUS_ASSIGNED => 'success',
|
||||
default => 'neutral',
|
||||
};
|
||||
}
|
||||
|
||||
public static function ticketStateLabel(string $state): string
|
||||
{
|
||||
return match ($state) {
|
||||
'Offen' => t('Open'),
|
||||
'In Bearbeitung' => t('In progress'),
|
||||
'Erledigt' => t('Resolved'),
|
||||
'Geschlossen' => t('Closed'),
|
||||
default => $state !== '' ? $state : '—',
|
||||
};
|
||||
}
|
||||
|
||||
public static function ticketStateVariant(string $state): string
|
||||
{
|
||||
return match ($state) {
|
||||
'Offen' => 'warning',
|
||||
'In Bearbeitung' => 'info',
|
||||
'Erledigt' => 'success',
|
||||
'Geschlossen' => 'neutral',
|
||||
default => 'neutral',
|
||||
};
|
||||
}
|
||||
|
||||
public static function categoryLabel(string $code): string
|
||||
{
|
||||
return match ($code) {
|
||||
self::CATEGORY_UPDATE => t('Update'),
|
||||
self::CATEGORY_HOTFIX => t('Hotfix'),
|
||||
default => $code,
|
||||
};
|
||||
}
|
||||
|
||||
public static function categoryVariant(string $code): string
|
||||
{
|
||||
return match ($code) {
|
||||
self::CATEGORY_UPDATE => 'neutral',
|
||||
self::CATEGORY_HOTFIX => 'warning',
|
||||
default => 'neutral',
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user