Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
name: "Generate CI matrix"
uses: "glpi-project/plugin-ci-workflows/.github/workflows/generate-ci-matrix.yml@v1"
with:
glpi-version: "11.0.x"
glpi-version: "12.0.x"
ci:
name: "GLPI ${{ matrix.glpi-version }} - php:${{ matrix.php-version }} - ${{ matrix.db-image }}"
needs: "generate-ci-matrix"
Expand Down
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
## [2.15.0] - 2026-10-06

### Added

- GLPI 12 compatibility

### Fixed

Expand Down
8 changes: 4 additions & 4 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,10 @@ function plugin_tag_post_init()
// Always define hook for tickets
// Needed for rules to function properly when a ticket is created from a mail
// collector
$PLUGIN_HOOKS[Hooks::ITEM_ADD]['tag'][Ticket::getType()] = ['PluginTagTagItem', 'updateItem'];
$PLUGIN_HOOKS[Hooks::ITEM_UPDATE]['tag'][Ticket::getType()] = ['PluginTagTagItem', 'updateItem'];
$PLUGIN_HOOKS[Hooks::PRE_ITEM_UPDATE]['tag'][Ticket::getType()] = ['PluginTagTagItem', 'updateItem'];
$PLUGIN_HOOKS[Hooks::PRE_ITEM_PURGE]['tag'][Ticket::getType()] = ['PluginTagTagItem', 'purgeItem'];
$PLUGIN_HOOKS[Hooks::ITEM_ADD]['tag'][Ticket::class] = ['PluginTagTagItem', 'updateItem'];
$PLUGIN_HOOKS[Hooks::ITEM_UPDATE]['tag'][Ticket::class] = ['PluginTagTagItem', 'updateItem'];
$PLUGIN_HOOKS[Hooks::PRE_ITEM_UPDATE]['tag'][Ticket::class] = ['PluginTagTagItem', 'updateItem'];
$PLUGIN_HOOKS[Hooks::PRE_ITEM_PURGE]['tag'][Ticket::class] = ['PluginTagTagItem', 'purgeItem'];

// Always define hook for Form (GLPI 11 namespace class)
// Needed because getCurrentItemtype() doesn't handle namespaces correctly
Expand Down
10 changes: 5 additions & 5 deletions inc/config.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,21 +30,21 @@

class PluginTagConfig extends CommonDBTM
{
protected static $notable = true;
protected static bool $notable = true;

public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
{

if (!$withtemplate && $item->getType() === 'Config') {
return self::createTabEntry(__('Tag Management', 'tag'), 0, $item::getType(), PluginTagTag::getIcon());
if (!$withtemplate && $item::class === 'Config') {
return self::createTabEntry(__('Tag Management', 'tag'), 0, $item::class, PluginTagTag::getIcon());
}

return '';
}

public function showConfigForm()
{
if (!Session::haveRight('config', UPDATE)) {
if (!Session::haveRight(Config::$rightname, UPDATE)) {
return false;
}

Expand Down Expand Up @@ -83,7 +83,7 @@ public function showConfigForm()

public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0)
{
if ($item->getType() == 'Config') {
if ($item::class == 'Config') {
$config = new self();
$config->showConfigForm();
}
Expand Down
2 changes: 1 addition & 1 deletion inc/profile.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class PluginTagProfile extends Profile
{
public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
{
return self::createTabEntry(__('Tag Management', 'tag'), 0, $item::getType(), PluginTagTag::getIcon());
return self::createTabEntry(__('Tag Management', 'tag'), 0, $item::class, PluginTagTag::getIcon());
}

public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0)
Expand Down
22 changes: 9 additions & 13 deletions inc/tag.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,11 @@
class PluginTagTag extends CommonDropdown
{
// From CommonDBTM
public $dohistory = true;
public bool $dohistory = true;

public const S_OPTION = 10500;

public static $rightname = 'plugin_tag_tag';
public static string $rightname = 'plugin_tag_tag';

public static function getTypeName($nb = 1)
{
Expand Down Expand Up @@ -194,11 +194,9 @@ public static function install(Migration $migration)
$migration->migrationOneTable($table);

$datas = getAllDataFromTable($table, ['NOT' => ['type_menu' => null]]);
if (!empty($datas)) {
foreach ($datas as $data) {
$itemtypes = $CFG_GLPI['plugin_tag_itemtypes'][$data['type_menu']] ?? [];
$DB->update($table, ['type_menu' => json_encode($itemtypes)], ['id' => $data['id']]);
}
foreach ($datas as $data) {
$itemtypes = $CFG_GLPI['plugin_tag_itemtypes'][$data['type_menu']] ?? [];
$DB->update($table, ['type_menu' => json_encode($itemtypes)], ['id' => $data['id']]);
}
}

Expand Down Expand Up @@ -258,7 +256,7 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0)
]);
}

$tab[2] = self::createTabEntry(_sn('Associated item', 'Associated items', 2), $nb, $item::getType(), 'ti ti-list');
$tab[2] = self::createTabEntry(_sn('Associated item', 'Associated items', 2), $nb, $item::class, 'ti ti-list');
return $tab;
}

Expand Down Expand Up @@ -558,9 +556,7 @@ public static function preKanbanContent($params = [])
}

if (isset($params['itemtype']) && isset($params['items_id'])) {
if (!isset($params['content'])) {
$params['content'] = "";
}
$params['content'] ??= "";

$iterator = $DB->request([
'SELECT' => [
Expand Down Expand Up @@ -915,7 +911,7 @@ public static function getCurrentItemtype()

$item = getItemForItemtype($itemtype);
if ($item instanceof CommonDBTM) {
return $item->getType();
return $item::class;
}

return false;
Expand All @@ -924,6 +920,6 @@ public static function getCurrentItemtype()

public static function getIcon()
{
return "fas fa-tags";
return "ti ti-tags";
}
}
8 changes: 4 additions & 4 deletions inc/taginjection.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,9 @@ public function getOptions($primary_type = '')
$options['displaytype'] = ["dropdown" => [12]];

return PluginDatainjectionCommonInjectionLib::addToSearchOptions($tab, $options, $this);
} else {
return [];
}

return [];
}

/**
Expand All @@ -88,8 +88,8 @@ public function addOrUpdateObject($values = [], $options = [])
}

return $results;
} else {
return [];
}

return [];
}
}
30 changes: 15 additions & 15 deletions inc/tagitem.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,17 +65,17 @@
class PluginTagTagItem extends CommonDBRelation
{
// From CommonDBRelation
public static $itemtype_1 = 'PluginTagTag';
public static ?string $itemtype_1 = 'PluginTagTag';

public static $items_id_1 = 'plugin_tag_tags_id';
public static ?string $items_id_1 = 'plugin_tag_tags_id';

public static $take_entity_1 = true;
public static bool $take_entity_1 = true;

public static $itemtype_2 = 'itemtype';
public static ?string $itemtype_2 = 'itemtype';

public static $items_id_2 = 'items_id';
public static ?string $items_id_2 = 'items_id';

public static $take_entity_2 = false;
public static bool $take_entity_2 = false;


public static function getTypeName($nb = 1)
Expand Down Expand Up @@ -475,7 +475,7 @@ public static function updateItem(CommonDBTM $item, bool $delete_existing_tags =
if (
$item->getID()
&& !isset($item->input["_plugin_tag_tag_process_form"])
&& ($item::getType() != Ticket::getType() || abs(strtotime((string) $item->fields['date_creation']) - strtotime((string) $_SESSION['glpi_currenttime'])) >= 5)
&& ($item::class != Ticket::class || abs(strtotime((string) $item->fields['date_creation']) - strtotime((string) $_SESSION['glpi_currenttime'])) >= 5)
) {
return true;
}
Expand Down Expand Up @@ -536,7 +536,7 @@ public static function updateItem(CommonDBTM $item, bool $delete_existing_tags =

// process actions
$existing_tags_ids = array_column(
$tag_item->find(['items_id' => $item->getID(), 'itemtype' => $item->getType()]),
$tag_item->find(['items_id' => $item->getID(), 'itemtype' => $item::class]),
'plugin_tag_tags_id',
);
$added_tags_ids = array_diff($tag_values, $existing_tags_ids);
Expand All @@ -550,15 +550,15 @@ public static function updateItem(CommonDBTM $item, bool $delete_existing_tags =
$tag_item->add([
'plugin_tag_tags_id' => $tag_id,
'items_id' => $item->getID(),
'itemtype' => $item->getType(),
'itemtype' => $item::class,
]);
}

foreach ($removed_tags_ids as $tag_id) {
$tag_item->deleteByCriteria([
'plugin_tag_tags_id' => $tag_id,
"items_id" => $item->getID(),
"itemtype" => $item->getType(),
"itemtype" => $item::class,
]);
}

Expand Down Expand Up @@ -591,7 +591,7 @@ public static function purgeItem(CommonDBTM $item)
$tagitem = new self();
return $tagitem->deleteByCriteria([
"items_id" => $item->getID(),
"itemtype" => $item->getType(),
"itemtype" => $item::class,
]);
}

Expand Down Expand Up @@ -627,9 +627,9 @@ public static function processMassiveActionsForOneItemtype(
$object->fields['id'] = $items_id;
$object->input = $input;
if (self::updateItem($object, false)) {
$ma->itemDone($item->getType(), $items_id, MassiveAction::ACTION_OK);
$ma->itemDone($item::class, $items_id, MassiveAction::ACTION_OK);
} else {
$ma->itemDone($item->getType(), $items_id, MassiveAction::ACTION_KO);
$ma->itemDone($item::class, $items_id, MassiveAction::ACTION_KO);
$ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION));
}
}
Expand All @@ -648,9 +648,9 @@ public static function processMassiveActionsForOneItemtype(
'plugin_tag_tags_id' => $input['_plugin_tag_tag_values'],
])
) {
$ma->itemDone($item->getType(), $items_id, MassiveAction::ACTION_OK);
$ma->itemDone($item::class, $items_id, MassiveAction::ACTION_OK);
} else {
$ma->itemDone($item->getType(), $items_id, MassiveAction::ACTION_KO);
$ma->itemDone($item::class, $items_id, MassiveAction::ACTION_KO);
$ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION));
}
}
Expand Down
5 changes: 5 additions & 0 deletions plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@
<author>TECLIB'</author>
</authors>
<versions>
<version>
<num>2.15.0</num>
<compatibility>~12.0.0</compatibility>
<download_url>https://github.com/pluginsGLPI/tag/releases/download/2.15.0/glpi-tag-2.15.0.tar.bz2</download_url>
</version>
<version>
<num>2.14.8</num>
<compatibility>~11.0.1</compatibility>
Expand Down
5 changes: 2 additions & 3 deletions public/js/modules/TagDropdownColorizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,15 @@ export class GlpiPluginTagTagDropdownColorizer {

/**
* Get style for a given tag options.
*
* @param {object} options
*
* @param {object} options
* @returns {object}
*/
tagStyle(options) {
const backgroundColor = this.getBackgroundColor(options);
return {
'background-color': backgroundColor,
'color': this.isDark(backgroundColor) ? '#fff' : '',
'padding': '2px 4px',
'border-radius': '2px',
}
}
Expand Down
8 changes: 4 additions & 4 deletions setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@

use function Safe\define;

define('PLUGIN_TAG_VERSION', '2.14.8');
define('PLUGIN_TAG_VERSION', '2.15.0');

// Minimal GLPI version, inclusive
define("PLUGIN_TAG_MIN_GLPI", "11.0.1");
define("PLUGIN_TAG_MIN_GLPI", "12.0.0");
// Maximum GLPI version, exclusive
define("PLUGIN_TAG_MAX_GLPI", "11.0.99");
define("PLUGIN_TAG_MAX_GLPI", "12.0.99");

/**
* Init hooks of the plugin.
Expand Down Expand Up @@ -182,7 +182,7 @@ function plugin_init_tag()
function plugin_version_tag()
{
return [
'name' => __('Tag Management', 'tag'),
'name' => 'Tag',
'version' => PLUGIN_TAG_VERSION,
'author' => '<a href="http://www.teclib.com">Teclib\'</a> - Infotel conseil',
'homepage' => 'https://github.com/pluginsGLPI/tag',
Expand Down
13 changes: 4 additions & 9 deletions tests/QuestionTypeTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,15 +58,10 @@ protected function renderHelpdeskForm(Form $form): Crawler
{
$this->login();
$controller = new RendererController();
$response = $controller->__invoke(
Request::create(
'',
'GET',
[
'id' => $form->getID(),
],
),
);
$request = Request::create('', 'GET');
$request->attributes->set('id', $form->getID());

$response = $controller->__invoke($request);
return new Crawler($response->getContent());
}
}
12 changes: 8 additions & 4 deletions tests/Units/TagDestinationFieldTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@

namespace GlpiPlugin\Tag\Tests\Units;

use CommonDBTM;
use Glpi\Form\AnswersHandler\AnswersHandler;
use Glpi\Form\Destination\FormDestination;
use Glpi\Form\Form;
use Glpi\Tests\AbstractDestinationFieldTest;
use Glpi\Tests\FormBuilder;
Expand All @@ -44,7 +46,7 @@
use PluginTagTagItem;
use User;

include_once __DIR__ . '/../../../../tests/abstracts/AbstractDestinationFieldTest.php';
include_once __DIR__ . '/../../../../tests/src/AbstractDestinationFieldTest.php';

final class TagDestinationFieldTest extends AbstractDestinationFieldTest
{
Expand Down Expand Up @@ -209,8 +211,9 @@ private function sendFormAndAssertTicketTags(
$destinations = $form->getDestinations();
$this->assertCount(1, $destinations);
$destination = current($destinations);
$this->assertTrue($destination instanceof FormDestination);
$this->updateItem(
$destination::getType(),
$destination::class,
$destination->getId(),
['config' => [PluginTagDestinationField::getKey() => $config->jsonSerialize()]],
["config"],
Expand All @@ -236,12 +239,13 @@ private function sendFormAndAssertTicketTags(
$created_items = $answers->getCreatedItems();
$this->assertCount(1, $created_items);
$ticket = current($created_items);
$this->assertTrue($ticket instanceof CommonDBTM);

// Check ticket tags
$tag_item = new PluginTagTagItem();
$tags = $tag_item->find(['items_id' => $ticket->getId(), 'itemtype' => $ticket::getType()]);
$tags = $tag_item->find(['items_id' => $ticket->getId(), 'itemtype' => $ticket::class]);
$this->assertCount(count($expected_tag_ids), $tags);
$tag_ids = array_map(fn($tag) => $tag['plugin_tag_tags_id'], $tags);
$tag_ids = array_values(array_map(fn($tag) => $tag['plugin_tag_tags_id'], $tags));
$this->assertEqualsCanonicalizing($expected_tag_ids, $tag_ids);
}

Expand Down
1 change: 0 additions & 1 deletion tests/Units/TagItemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ public function testTagsFromTicket(): void
$tagID1 = $this->createTag('TicketTag1');
$tagID2 = $this->createTag('TicketTag2');


$ticket = new Ticket();
$ticket->add([
'name' => 'Ticket add Tag',
Expand Down
Loading