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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- Fix tags being removed when saving them on a closed ticket
- Fix tag search criterion matching items of other types sharing the same ID
- Fix error when updating a ticket without creation date (e.g. entity transfer)
- Fix tags left in a deleted entity: declare their entity relation so it is checked and replaced on entity deletion

## [2.14.8] - 2026-09-30

Expand Down
14 changes: 14 additions & 0 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,20 @@ function plugin_tag_getDropdown()
return ['PluginTagTag' => PluginTagTag::getTypeName(2)];
}

/**
* Declare foreign keys to core tables, so that core usage checks and replacements take them into account
*
* @return array
*/
function plugin_tag_getDatabaseRelations()
{
return [
'glpi_entities' => [
'glpi_plugin_tag_tags' => 'entities_id',
],
];
}

/**
* Define massive actions for other itemtype
*
Expand Down
22 changes: 22 additions & 0 deletions tests/Units/TagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
use CommonITILObject;
use Computer;
use DBmysql;
use Entity;
use GlpiPlugin\Tag\Tests\TagTestCase;
use Phone;
use PHPUnit\Framework\Attributes\DataProvider;
Expand Down Expand Up @@ -235,4 +236,25 @@ public function testSearchOnTagIgnoresOtherItemtypes(string $searchtype, bool $b
$names = array_column(array_column($data['data']['rows'], 'raw'), 'ITEM_Computer_1');
$this->assertSame(array_map(fn($name) => sprintf('%s %s', $prefix, $name), $expected), $names);
}

public function testTagIsMovedWhenItsEntityIsReplaced(): void
{
$this->login();
$root_id = getItemByTypeName(Entity::class, '_test_root_entity', true);

$entity = $this->createItem(Entity::class, [
'name' => __FUNCTION__,
'entities_id' => $root_id,
]);
$tag = $this->createItem(PluginTagTag::class, [
'name' => __FUNCTION__,
'entities_id' => $entity->getID(),
]);

$this->assertTrue($entity->isUsed());

$this->assertTrue($entity->delete(['id' => $entity->getID(), '_replace_by' => $root_id], true));
$this->assertTrue($tag->getFromDB($tag->getID()));
$this->assertSame($root_id, $tag->fields['entities_id']);
}
}