N°6077 - Attachment class: now creation_date and user_id are init by default (#339)

Those fields were empty in case the Attachment instance was created in an extension (Mail to Ticket for example).

Now the values are set in the object DBInsertNoReload method : 
* creation_date : current date
* user_id : current user

The previous values set for console and portal are removed.

A fix for Mail to Ticket extension is also planned : N°4081.
This commit is contained in:
Pierre Goiffon
2023-03-08 16:34:32 +01:00
committed by GitHub
parent 559f5b4bdb
commit 69beb05a55
3 changed files with 14 additions and 4 deletions

View File

@@ -98,8 +98,6 @@ try
$oAttachment->Set('expire', time() + MetaModel::GetConfig()->Get('draft_attachments_lifetime'));
$oAttachment->Set('temp_id', $sTempId);
$oAttachment->Set('item_class', $sClass);
$oAttachment->Set('creation_date', time());
$oAttachment->Set('user_id', UserRights::GetUserObject());
$oAttachment->SetDefaultOrgId();
$oAttachment->Set('contents', $oDoc);
$iAttId = $oAttachment->DBInsert();

View File

@@ -102,6 +102,20 @@
</field>
</fields>
<methods>
<method id="DBInsertNoReload">
<static>false</static>
<access>public</access>
<type>Overload-DBObject</type>
<code><![CDATA[
public function DBInsertNoReload()
{
$this->SetCurrentDateIfNull('creation_date');
$this->SetIfNull('user_id', CMDBChange::GetCurrentUserId());
return parent::DBInsertNoReload();
}
]]></code>
</method>
<method id="MapContextParam">
<comment><![CDATA[/**
* Maps the given context parameter name to the appropriate filter/search code for this class

View File

@@ -1230,8 +1230,6 @@ class ObjectController extends BrickController
$oAttachment->Set('expire', time() + MetaModel::GetConfig()->Get('draft_attachments_lifetime')); // one hour...
$oAttachment->Set('temp_id', $sTempId);
$oAttachment->Set('item_class', $sObjectClass);
$oAttachment->Set('creation_date', time());
$oAttachment->Set('user_id', UserRights::GetUserObject());
$oAttachment->SetDefaultOrgId();
$oAttachment->Set('contents', $oDocument);
$iAttId = $oAttachment->DBInsert();