Skip to content

Commit

Permalink
do not delte documents from rich text
Browse files Browse the repository at this point in the history
  • Loading branch information
cedric-anne committed Jan 27, 2025
1 parent ff653ad commit 52529c8
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion src/Glpi/Asset/Capacity/HasDocumentsCapacity.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,14 @@ public function getCloneRelations(): array

public function isUsed(string $classname): bool
{
// TODO filter using 'timeline_position' => 0 criteria
return parent::isUsed($classname)
&& $this->countAssetsLinkedToPeerItem($classname, Document_Item::class) > 0;
}

public function getCapacityUsageDescription(string $classname): string
{
// TODO filter using 'timeline_position' => 0 criteria
return sprintf(
__('%1$s documents attached to %2$s assets'),
$this->countPeerItemsUsage($classname, Document_Item::class),
Expand All @@ -88,7 +90,16 @@ public function onCapacityDisabled(string $classname): void

// Delete relations to documents
$document_item = new Document_Item();
$document_item->deleteByCriteria(['itemtype' => $classname], force: true, history: false);
$document_item->deleteByCriteria(
[
'itemtype' => $classname,
// 0 is the value when a document is attached manually
// filtering on this value prevents removal of documents attached from rich text fields
'timeline_position' => 0,
],
force: true,
history: false
);

// Clean history related to documents
$this->deleteRelationLogs($classname, Document::class);
Expand Down

0 comments on commit 52529c8

Please sign in to comment.