mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 02:28:44 +02:00
N°7294 - EVENT_ADD_ATTACHMENT_TO_OBJECT not triggered on the object
This commit is contained in:
@@ -263,16 +263,15 @@
|
||||
<description>An attachment has been added to an object</description>
|
||||
<replaces>Attachment::AfterUpdate</replaces>
|
||||
<sources>
|
||||
<source id="Attachment">Attachment</source>
|
||||
<source id="cmdbAbstractObject">cmdbAbstractObject</source>
|
||||
</sources>
|
||||
<event_data>
|
||||
<event_datum id="object">
|
||||
<description>The attachment updated</description>
|
||||
<description>The object where the attachment is added</description>
|
||||
<type>DBObject</type>
|
||||
</event_datum>
|
||||
<event_datum id="target_object">
|
||||
<description>The object to which the attachment is linked</description>
|
||||
<event_datum id="attachment">
|
||||
<description>The attachment added to the objet</description>
|
||||
<type>DBObject</type>
|
||||
</event_datum>
|
||||
<event_datum id="debug_info">
|
||||
@@ -285,16 +284,15 @@
|
||||
<description>An attachment has been removed from an object</description>
|
||||
<replaces>Attachment::AfterUpdate</replaces>
|
||||
<sources>
|
||||
<source id="Attachment">Attachment</source>
|
||||
<source id="cmdbAbstractObject">cmdbAbstractObject</source>
|
||||
</sources>
|
||||
<event_data>
|
||||
<event_datum id="object">
|
||||
<description>The attachment updated</description>
|
||||
<description>The object where the attachment is removed</description>
|
||||
<type>DBObject</type>
|
||||
</event_datum>
|
||||
<event_datum id="target_object">
|
||||
<description>The object to which the attachment is linked</description>
|
||||
<event_datum id="attachment">
|
||||
<description>The attachment removed</description>
|
||||
<type>DBObject</type>
|
||||
</event_datum>
|
||||
<event_datum id="debug_info">
|
||||
|
||||
@@ -262,7 +262,6 @@ class AttachmentPlugIn implements iApplicationUIExtension, iApplicationObjectExt
|
||||
else
|
||||
{
|
||||
$oAttachmentsRenderer->RenderViewAttachmentsList();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -291,8 +290,8 @@ class AttachmentPlugIn implements iApplicationUIExtension, iApplicationObjectExt
|
||||
// Remove attachments that are no longer attached to the current object
|
||||
if (in_array($oAttachment->GetKey(), $aRemovedAttachmentIds))
|
||||
{
|
||||
$aData = ['target_object' => $oObject];
|
||||
$oAttachment->FireEvent(EVENT_REMOVE_ATTACHMENT_FROM_OBJECT, $aData);
|
||||
$aData = ['attachment' => $oAttachment];
|
||||
$oObject->FireEvent(EVENT_REMOVE_ATTACHMENT_FROM_OBJECT, $aData);
|
||||
$oAttachment->DBDelete();
|
||||
$aActions[] = self::GetActionChangeOp($oAttachment, false /* false => deletion */);
|
||||
}
|
||||
@@ -320,8 +319,8 @@ class AttachmentPlugIn implements iApplicationUIExtension, iApplicationObjectExt
|
||||
$oAttachment->DBUpdate();
|
||||
// temporary attachment confirmed, list it in the history
|
||||
$aActions[] = self::GetActionChangeOp($oAttachment, true /* true => creation */);
|
||||
$aData = ['target_object' => $oObject];
|
||||
$oAttachment->FireEvent(EVENT_ADD_ATTACHMENT_TO_OBJECT, $aData);
|
||||
$aData = ['attachment' => $oAttachment];
|
||||
$oObject->FireEvent(EVENT_ADD_ATTACHMENT_TO_OBJECT, $aData);
|
||||
}
|
||||
}
|
||||
if (count($aActions) > 0)
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
/**
|
||||
* @copyright Copyright (C) 2010-2024 Combodo SARL
|
||||
* @license http://opensource.org/licenses/AGPL-3.0
|
||||
*/
|
||||
namespace Combodo\iTop\Test\UnitTest\Module\ItopAttachment;
|
||||
|
||||
use Combodo\iTop\Service\Events\EventData;
|
||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||
use MetaModel;
|
||||
|
||||
class TestAttachment extends ItopDataTestCase
|
||||
{
|
||||
private string $sAddAttachmentName;
|
||||
private string $sRemoveAttachmentName;
|
||||
const CREATE_TEST_ORG = true;
|
||||
|
||||
public function setUp(): void
|
||||
{
|
||||
parent::setUp();
|
||||
//static::$DEBUG_UNIT_TEST = true;
|
||||
}
|
||||
|
||||
public function testAddAttachment()
|
||||
{
|
||||
$this->sAddAttachmentName = '';
|
||||
$this->sRemoveAttachmentName = '';
|
||||
|
||||
$_REQUEST['transaction_id'] = 'test_transaction';
|
||||
$_REQUEST['attachment_plugin'] = 'in_form';
|
||||
|
||||
$oDocument = new \ormDocument('Test', 'text/plain', 'test.txt');
|
||||
|
||||
$this->EventService_RegisterListener(EVENT_ADD_ATTACHMENT_TO_OBJECT, [$this, 'OnAddAttachment']);
|
||||
$this->EventService_RegisterListener(EVENT_REMOVE_ATTACHMENT_FROM_OBJECT, [$this, 'OnRemoveAttachment']);
|
||||
|
||||
$oAttachment = MetaModel::NewObject('Attachment', [
|
||||
'item_class' => 'UserRequest',
|
||||
'temp_id' => 'test_transaction',
|
||||
'contents' => $oDocument,
|
||||
]);
|
||||
|
||||
$oAttachment->DBInsert();
|
||||
$oTicket = $this->CreateTicket(1);
|
||||
|
||||
$_REQUEST['removed_attachments'] = [$oAttachment->GetKey()];
|
||||
$this->InvokeNonPublicStaticMethod(\AttachmentPlugIn::class, 'UpdateAttachments', [$oTicket]);
|
||||
|
||||
$this->assertEquals('test.txt', $this->sAddAttachmentName);
|
||||
$this->assertEquals('test.txt', $this->sRemoveAttachmentName);
|
||||
}
|
||||
|
||||
public function OnAddAttachment(EventData $oData)
|
||||
{
|
||||
$this->debug('OnAddAttachment');
|
||||
$this->assertEquals('UserRequest', get_class($oData->Get('object')));
|
||||
$oAttachment = $oData->Get('attachment');
|
||||
/** @var \ormDocument $oDocument */
|
||||
$oDocument = $oAttachment->Get('contents');
|
||||
$this->sAddAttachmentName = $oDocument->GetFileName();
|
||||
}
|
||||
|
||||
public function OnRemoveAttachment(EventData $oData)
|
||||
{
|
||||
$this->debug('OnRemoveAttachment');
|
||||
$this->assertEquals('UserRequest', get_class($oData->Get('object')));
|
||||
$oAttachment = $oData->Get('attachment');
|
||||
/** @var \ormDocument $oDocument */
|
||||
$oDocument = $oAttachment->Get('contents');
|
||||
$this->sRemoveAttachmentName = $oDocument->GetFileName();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user