Skip to content
Open
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 @@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- CI: fix Psalm cache directory, declare a unique composer autoloader suffix
- 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 @@ -250,6 +250,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 @@ -31,6 +31,7 @@
namespace GlpiPlugin\Tag\Tests\Units;

use DBmysql;
use Entity;
use Glpi\Search\SearchOption;
use GlpiPlugin\Tag\Tests\TagTestCase;
use PluginTagTag;
Expand Down Expand Up @@ -161,4 +162,25 @@ public function testUpdateAcceptsScalarTypeMenu(): void

$this->assertSame('["Ticket"]', $tag->fields['type_menu']);
}

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']);
}
}