Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,18 @@ function plugin_init_moreoptions(): void
$PLUGIN_HOOKS[Hooks::ITEM_UPDATE]['moreoptions'][Problem::class] = [
Controller::class, 'updateItemActors',
];

$PLUGIN_HOOKS[Hooks::ITEM_ADD]['moreoptions'][TicketTask::class] = [
Controller::class, 'assignTechnicianFromTask',
];

$PLUGIN_HOOKS[Hooks::ITEM_ADD]['moreoptions'][ChangeTask::class] = [
Controller::class, 'assignTechnicianFromTask',
];

$PLUGIN_HOOKS[Hooks::ITEM_ADD]['moreoptions'][ProblemTask::class] = [
Controller::class, 'assignTechnicianFromTask',
];
}

/**
Expand Down
77 changes: 77 additions & 0 deletions src/Controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -535,4 +535,81 @@
}
return $item;
}

/**
* Assign technician from task to parent ITIL object
* When a task is created with a technician assigned, this method will
* automatically assign that technician to the parent ticket/change/problem
*
* @param CommonITILTask $item The task item (TicketTask, ChangeTask, or ProblemTask)
* @return void
*/
public static function assignTechnicianFromTask(CommonITILTask $item): void

Check failure on line 547 in src/Controller.php

View workflow job for this annotation

GitHub Actions / GLPI 11.0.x - php:8.4 - mariadb:11.4 / Continuous integration

Parameter $item of method GlpiPlugin\Moreoptions\Controller::assignTechnicianFromTask() has invalid type GlpiPlugin\Moreoptions\CommonITILTask.

Check failure on line 547 in src/Controller.php

View workflow job for this annotation

GitHub Actions / GLPI 11.0.x - php:8.4 - mariadb:11.4 / Continuous integration

Parameter $item of method GlpiPlugin\Moreoptions\Controller::assignTechnicianFromTask() has invalid type GlpiPlugin\Moreoptions\CommonITILTask.

Check failure on line 547 in src/Controller.php

View workflow job for this annotation

GitHub Actions / GLPI 11.0.x - php:8.2 - mariadb:10.6 / Continuous integration

Parameter $item of method GlpiPlugin\Moreoptions\Controller::assignTechnicianFromTask() has invalid type GlpiPlugin\Moreoptions\CommonITILTask.

Check failure on line 547 in src/Controller.php

View workflow job for this annotation

GitHub Actions / GLPI 11.0.x - php:8.2 - mariadb:10.6 / Continuous integration

Parameter $item of method GlpiPlugin\Moreoptions\Controller::assignTechnicianFromTask() has invalid type GlpiPlugin\Moreoptions\CommonITILTask.
{
$conf = Config::getCurrentConfig();
if ($conf->fields['is_active'] != 1) {
return;
}

// Check if a technician is assigned to the task
if (empty($item->fields['users_id_tech'])) {

Check failure on line 555 in src/Controller.php

View workflow job for this annotation

GitHub Actions / GLPI 11.0.x - php:8.4 - mariadb:11.4 / Continuous integration

Access to property $fields on an unknown class GlpiPlugin\Moreoptions\CommonITILTask.

Check failure on line 555 in src/Controller.php

View workflow job for this annotation

GitHub Actions / GLPI 11.0.x - php:8.2 - mariadb:10.6 / Continuous integration

Access to property $fields on an unknown class GlpiPlugin\Moreoptions\CommonITILTask.
return;
}

$users_id_tech = $item->fields['users_id_tech'];

Check failure on line 559 in src/Controller.php

View workflow job for this annotation

GitHub Actions / GLPI 11.0.x - php:8.4 - mariadb:11.4 / Continuous integration

Access to property $fields on an unknown class GlpiPlugin\Moreoptions\CommonITILTask.

Check failure on line 559 in src/Controller.php

View workflow job for this annotation

GitHub Actions / GLPI 11.0.x - php:8.2 - mariadb:10.6 / Continuous integration

Access to property $fields on an unknown class GlpiPlugin\Moreoptions\CommonITILTask.

// Determine the parent ITIL object and user link class based on task type
switch ($item::class) {

Check failure on line 562 in src/Controller.php

View workflow job for this annotation

GitHub Actions / GLPI 11.0.x - php:8.4 - mariadb:11.4 / Continuous integration

Access to constant class on an unknown class GlpiPlugin\Moreoptions\CommonITILTask.

Check failure on line 562 in src/Controller.php

View workflow job for this annotation

GitHub Actions / GLPI 11.0.x - php:8.2 - mariadb:10.6 / Continuous integration

Access to constant class on an unknown class GlpiPlugin\Moreoptions\CommonITILTask.
case TicketTask::class:
if (empty($item->fields['tickets_id'])) {

Check failure on line 564 in src/Controller.php

View workflow job for this annotation

GitHub Actions / GLPI 11.0.x - php:8.4 - mariadb:11.4 / Continuous integration

Access to property $fields on an unknown class GlpiPlugin\Moreoptions\CommonITILTask.

Check failure on line 564 in src/Controller.php

View workflow job for this annotation

GitHub Actions / GLPI 11.0.x - php:8.2 - mariadb:10.6 / Continuous integration

Access to property $fields on an unknown class GlpiPlugin\Moreoptions\CommonITILTask.
return;
}
$itilObject = new Ticket();
$userLinkClass = Ticket_User::class;
$itilIdField = 'tickets_id';
$itilId = $item->fields['tickets_id'];

Check failure on line 570 in src/Controller.php

View workflow job for this annotation

GitHub Actions / GLPI 11.0.x - php:8.4 - mariadb:11.4 / Continuous integration

Access to property $fields on an unknown class GlpiPlugin\Moreoptions\CommonITILTask.

Check failure on line 570 in src/Controller.php

View workflow job for this annotation

GitHub Actions / GLPI 11.0.x - php:8.2 - mariadb:10.6 / Continuous integration

Access to property $fields on an unknown class GlpiPlugin\Moreoptions\CommonITILTask.
break;

case ChangeTask::class:
if (empty($item->fields['changes_id'])) {

Check failure on line 574 in src/Controller.php

View workflow job for this annotation

GitHub Actions / GLPI 11.0.x - php:8.4 - mariadb:11.4 / Continuous integration

Access to property $fields on an unknown class GlpiPlugin\Moreoptions\CommonITILTask.

Check failure on line 574 in src/Controller.php

View workflow job for this annotation

GitHub Actions / GLPI 11.0.x - php:8.2 - mariadb:10.6 / Continuous integration

Access to property $fields on an unknown class GlpiPlugin\Moreoptions\CommonITILTask.
return;
}
$itilObject = new Change();
$userLinkClass = Change_User::class;
$itilIdField = 'changes_id';
$itilId = $item->fields['changes_id'];

Check failure on line 580 in src/Controller.php

View workflow job for this annotation

GitHub Actions / GLPI 11.0.x - php:8.4 - mariadb:11.4 / Continuous integration

Access to property $fields on an unknown class GlpiPlugin\Moreoptions\CommonITILTask.

Check failure on line 580 in src/Controller.php

View workflow job for this annotation

GitHub Actions / GLPI 11.0.x - php:8.2 - mariadb:10.6 / Continuous integration

Access to property $fields on an unknown class GlpiPlugin\Moreoptions\CommonITILTask.
break;

case ProblemTask::class:
if (empty($item->fields['problems_id'])) {

Check failure on line 584 in src/Controller.php

View workflow job for this annotation

GitHub Actions / GLPI 11.0.x - php:8.4 - mariadb:11.4 / Continuous integration

Access to property $fields on an unknown class GlpiPlugin\Moreoptions\CommonITILTask.

Check failure on line 584 in src/Controller.php

View workflow job for this annotation

GitHub Actions / GLPI 11.0.x - php:8.2 - mariadb:10.6 / Continuous integration

Access to property $fields on an unknown class GlpiPlugin\Moreoptions\CommonITILTask.
return;
}
$itilObject = new Problem();
$userLinkClass = Problem_User::class;
$itilIdField = 'problems_id';
$itilId = $item->fields['problems_id'];
break;

default:
return;
}

// Get the parent ITIL object
if (!$itilObject->getFromDB($itilId)) {
return;
}

// Check if the technician is already assigned to the parent ITIL object
$userLink = new $userLinkClass();
$criteria = [
'users_id' => $users_id_tech,
'type' => CommonITILActor::ASSIGN,
$itilIdField => $itilId,
];

// If the technician is not already assigned, add them
if (!$userLink->getFromDBByCrit($criteria)) {
$userLink->add($criteria);
}
}
}
4 changes: 2 additions & 2 deletions tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@

define('GLPI_LOG_DIR', __DIR__ . '/files/_logs');

require_once __DIR__ . '/../../../phpunit/GLPITestCase.php';
require_once __DIR__ . '/../../../phpunit/DbTestCase.php';
require_once __DIR__ . '/../../../tests/GLPITestCase.php';
require_once __DIR__ . '/../../../tests/DbTestCase.php';
require_once __DIR__ . '/../../../vendor/autoload.php';
require_once __DIR__ . '/MoreOptionsTestCase.php';

Expand Down
Loading