N°8796 - Add PHP code style validation in iTop and extensions - format whole code base

This commit is contained in:
odain
2025-11-07 15:39:53 +01:00
parent 12f23113f5
commit 890a2568c8
2110 changed files with 53099 additions and 63885 deletions

View File

@@ -1,4 +1,5 @@
<?php
/*
* @copyright Copyright (C) 2010-2024 Combodo SAS
* @license http://opensource.org/licenses/AGPL-3.0
@@ -8,35 +9,31 @@ use Combodo\iTop\Application\WebPage\WebPage;
class AttachmentPlugIn implements iApplicationUIExtension, iApplicationObjectExtension
{
const ENUM_GUI_ALL = 'all';
const ENUM_GUI_BACKOFFICE = 'backoffice';
const ENUM_GUI_PORTALS = 'portals';
public const ENUM_GUI_ALL = 'all';
public const ENUM_GUI_BACKOFFICE = 'backoffice';
public const ENUM_GUI_PORTALS = 'portals';
protected static $m_bIsModified = false;
public function OnDisplayProperties($oObject, WebPage $oPage, $bEditMode = false)
{
if ($this->GetAttachmentsPosition() == 'properties')
{
if ($this->GetAttachmentsPosition() == 'properties') {
$this->DisplayAttachments($oObject, $oPage, $bEditMode);
}
}
public function OnDisplayRelations($oObject, WebPage $oPage, $bEditMode = false)
{
if ($this->GetAttachmentsPosition() == 'relations')
{
if ($this->GetAttachmentsPosition() == 'relations') {
$this->DisplayAttachments($oObject, $oPage, $bEditMode);
}
}
public function OnFormSubmit($oObject, $sFormPrefix = '')
{
if ($this->IsTargetObject($oObject))
{
if ($this->IsTargetObject($oObject)) {
// For new objects attachments are processed in OnDBInsert
if (!$oObject->IsNew())
{
if (!$oObject->IsNew()) {
self::UpdateAttachments($oObject);
}
}
@@ -52,12 +49,9 @@ class AttachmentPlugIn implements iApplicationUIExtension, iApplicationObjectExt
public static function GetMaxUploadSize()
{
$sMaxUpload = ini_get('upload_max_filesize');
if (!$sMaxUpload)
{
if (!$sMaxUpload) {
$result = false;
}
else
{
} else {
$result = utils::ConvertToBytes($sMaxUpload);
}
@@ -70,13 +64,11 @@ class AttachmentPlugIn implements iApplicationUIExtension, iApplicationObjectExt
* @return bool
* @since 3.2.1 N°7534
*/
public static function IsAttachmentAllowedForObject(cmdbAbstractObject $oObject) : bool
public static function IsAttachmentAllowedForObject(cmdbAbstractObject $oObject): bool
{
$aAllowedClasses = MetaModel::GetModuleSetting('itop-attachments', 'allowed_classes', array('Ticket'));
foreach ($aAllowedClasses as $sAllowedClass)
{
if ($oObject instanceof $sAllowedClass)
{
$aAllowedClasses = MetaModel::GetModuleSetting('itop-attachments', 'allowed_classes', ['Ticket']);
foreach ($aAllowedClasses as $sAllowedClass) {
if ($oObject instanceof $sAllowedClass) {
return true;
}
}
@@ -91,24 +83,15 @@ class AttachmentPlugIn implements iApplicationUIExtension, iApplicationObjectExt
public static function GetMaxUpload()
{
$iMaxUpload = static::GetMaxUploadSize();
if (!$iMaxUpload)
{
if (!$iMaxUpload) {
$sRet = Dict::S('Attachments:UploadNotAllowedOnThisSystem');
}
else
{
if ($iMaxUpload > 1024 * 1024 * 1024)
{
} else {
if ($iMaxUpload > 1024 * 1024 * 1024) {
$sRet = Dict::Format('Attachment:Max_Go', sprintf('%0.2f', $iMaxUpload / (1024 * 1024 * 1024)));
}
else
{
if ($iMaxUpload > 1024 * 1024)
{
} else {
if ($iMaxUpload > 1024 * 1024) {
$sRet = Dict::Format('Attachment:Max_Mo', sprintf('%0.2f', $iMaxUpload / (1024 * 1024)));
}
else
{
} else {
$sRet = Dict::Format('Attachment:Max_Ko', sprintf('%0.2f', $iMaxUpload / (1024)));
}
}
@@ -127,9 +110,8 @@ class AttachmentPlugIn implements iApplicationUIExtension, iApplicationObjectExt
// Delete all "pending" attachments for this form
$sOQL = 'SELECT Attachment WHERE temp_id = :temp_id';
$oSearch = DBObjectSearch::FromOQL($sOQL);
$oSet = new DBObjectSet($oSearch, array(), array('temp_id' => $sTempId));
while ($oAttachment = $oSet->Fetch())
{
$oSet = new DBObjectSet($oSearch, [], ['temp_id' => $sTempId]);
while ($oAttachment = $oSet->Fetch()) {
$oAttachment->DBDelete();
// Pending attachment, don't mention it in the history
}
@@ -137,7 +119,7 @@ class AttachmentPlugIn implements iApplicationUIExtension, iApplicationObjectExt
public function EnumUsedAttributes($oObject)
{
return array();
return [];
}
public function GetIcon($oObject)
@@ -148,14 +130,14 @@ class AttachmentPlugIn implements iApplicationUIExtension, iApplicationObjectExt
public function GetHilightClass($oObject)
{
// Possible return values are:
// HILIGHT_CLASS_CRITICAL, HILIGHT_CLASS_WARNING, HILIGHT_CLASS_OK, HILIGHT_CLASS_NONE
// HILIGHT_CLASS_CRITICAL, HILIGHT_CLASS_WARNING, HILIGHT_CLASS_OK, HILIGHT_CLASS_NONE
return HILIGHT_CLASS_NONE;
}
public function EnumAllowedActions(DBObjectSet $oSet)
{
// No action
return array();
return [];
}
public function OnIsModified($oObject)
@@ -165,23 +147,21 @@ class AttachmentPlugIn implements iApplicationUIExtension, iApplicationObjectExt
public function OnCheckToWrite($oObject)
{
return array();
return [];
}
public function OnCheckToDelete($oObject)
{
return array();
return [];
}
public function OnDBUpdate($oObject, $oChange = null)
{
if ($this->IsTargetObject($oObject))
{
if ($this->IsTargetObject($oObject)) {
// Get all current attachments
$oSearch = DBObjectSearch::FromOQL("SELECT Attachment WHERE item_class = :class AND item_id = :item_id");
$oSet = new DBObjectSet($oSearch, array(), array('class' => get_class($oObject), 'item_id' => $oObject->GetKey()));
while ($oAttachment = $oSet->Fetch())
{
$oSet = new DBObjectSet($oSearch, [], ['class' => get_class($oObject), 'item_id' => $oObject->GetKey()]);
while ($oAttachment = $oSet->Fetch()) {
$oAttachment->SetItem($oObject, true /*updateonchange*/);
}
}
@@ -189,20 +169,17 @@ class AttachmentPlugIn implements iApplicationUIExtension, iApplicationObjectExt
public function OnDBInsert($oObject, $oChange = null)
{
if ($this->IsTargetObject($oObject))
{
if ($this->IsTargetObject($oObject)) {
self::UpdateAttachments($oObject, $oChange);
}
}
public function OnDBDelete($oObject, $oChange = null)
{
if ($this->IsTargetObject($oObject))
{
if ($this->IsTargetObject($oObject)) {
$oSearch = DBObjectSearch::FromOQL("SELECT Attachment WHERE item_class = :class AND item_id = :item_id");
$oSet = new DBObjectSet($oSearch, array(), array('class' => get_class($oObject), 'item_id' => $oObject->GetKey()));
while ($oAttachment = $oSet->Fetch())
{
$oSet = new DBObjectSet($oSearch, [], ['class' => get_class($oObject), 'item_id' => $oObject->GetKey()]);
while ($oAttachment = $oSet->Fetch()) {
$oAttachment->DBDelete();
}
}
@@ -216,11 +193,9 @@ class AttachmentPlugIn implements iApplicationUIExtension, iApplicationObjectExt
protected function IsTargetObject($oObject)
{
$aAllowedClasses = MetaModel::GetModuleSetting('itop-attachments', 'allowed_classes', array('Ticket'));
foreach ($aAllowedClasses as $sAllowedClass)
{
if ($oObject instanceof $sAllowedClass)
{
$aAllowedClasses = MetaModel::GetModuleSetting('itop-attachments', 'allowed_classes', ['Ticket']);
foreach ($aAllowedClasses as $sAllowedClass) {
if ($oObject instanceof $sAllowedClass) {
return true;
}
}
@@ -233,7 +208,7 @@ class AttachmentPlugIn implements iApplicationUIExtension, iApplicationObjectExt
return MetaModel::GetModuleSetting('itop-attachments', 'position', 'relations');
}
var $m_bDeleteEnabled = true;
public $m_bDeleteEnabled = true;
public function EnableDelete($bEnabled)
{
@@ -254,34 +229,28 @@ class AttachmentPlugIn implements iApplicationUIExtension, iApplicationObjectExt
public function DisplayAttachments(DBObject $oObject, WebPage $oPage, $bEditMode = false)
{
// Exit here if the class is not allowed
if (!$this->IsTargetObject($oObject))
{
if (!$this->IsTargetObject($oObject)) {
return;
}
$sObjClass = get_class($oObject);
$iObjKey = $oObject->GetKey();
$sTransactionId = $oPage->GetTransactionId();
if ($bEditMode && empty($sTransactionId))
{
if ($bEditMode && empty($sTransactionId)) {
throw new InvalidParameterException('Attachments renderer : invalid transaction id');
}
$oAttachmentsRenderer = AttachmentsRendererFactory::GetInstance($oPage, $sObjClass, $iObjKey, $sTransactionId);
if ($this->GetAttachmentsPosition() === 'relations')
{
if ($this->GetAttachmentsPosition() === 'relations') {
$iCount = $oAttachmentsRenderer->GetAttachmentsSet()->Count() + $oAttachmentsRenderer->GetTempAttachmentsSet()->Count();
$sTitle = ($iCount > 0) ? Dict::Format('Attachments:TabTitle_Count', $iCount) : Dict::S('Attachments:EmptyTabTitle');
$oPage->SetCurrentTab('Attachments:Tab', $sTitle);
}
$bIsReadOnlyState = self::IsReadonlyState($oObject, $oObject->GetState(), AttachmentPlugIn::ENUM_GUI_BACKOFFICE);
if ($bEditMode && !$bIsReadOnlyState)
{
if ($bEditMode && !$bIsReadOnlyState) {
$oAttachmentsRenderer->RenderEditAttachmentsList();
}
else
{
} else {
$oAttachmentsRenderer->RenderViewAttachmentsList();
}
}
@@ -307,27 +276,23 @@ class AttachmentPlugIn implements iApplicationUIExtension, iApplicationObjectExt
{
self::$m_bIsModified = false;
if (utils::ReadParam('attachment_plugin', 'not-in-form') == 'not-in-form')
{
if (utils::ReadParam('attachment_plugin', 'not-in-form') == 'not-in-form') {
// Workaround to an issue in iTop < 2.0
// Leave silently if there is no trace of the attachment form
return;
}
$sTransactionId = utils::ReadParam('transaction_id', null, false, 'transaction_id');
if (!is_null($sTransactionId))
{
$aActions = array();
$aRemovedAttachmentIds = utils::ReadParam('removed_attachments', array());
if (!is_null($sTransactionId)) {
$aActions = [];
$aRemovedAttachmentIds = utils::ReadParam('removed_attachments', []);
// Get all current attachments
$oSearch = DBObjectSearch::FromOQL("SELECT Attachment WHERE item_class = :class AND item_id = :item_id");
$oSearch->AllowAllData();
$oSet = new DBObjectSet($oSearch, array(), array('class' => get_class($oObject), 'item_id' => $oObject->GetKey()));
while ($oAttachment = $oSet->Fetch())
{
$oSet = new DBObjectSet($oSearch, [], ['class' => get_class($oObject), 'item_id' => $oObject->GetKey()]);
while ($oAttachment = $oSet->Fetch()) {
// Remove attachments that are no longer attached to the current object
if (in_array($oAttachment->GetKey(), $aRemovedAttachmentIds))
{
if (in_array($oAttachment->GetKey(), $aRemovedAttachmentIds)) {
$aData = ['attachment' => $oAttachment];
$oObject->FireEvent(EVENT_REMOVE_ATTACHMENT_FROM_OBJECT, $aData);
$oAttachment->DBDelete();
@@ -342,16 +307,12 @@ class AttachmentPlugIn implements iApplicationUIExtension, iApplicationObjectExt
$sOQL = 'SELECT Attachment WHERE temp_id = :temp_id';
$oSearch = DBObjectSearch::FromOQL($sOQL);
$oSearch->AllowAllData();
$oSet = new DBObjectSet($oSearch, array(), array('temp_id' => $sTempId));
while ($oAttachment = $oSet->Fetch())
{
if (in_array($oAttachment->GetKey(), $aRemovedAttachmentIds))
{
$oSet = new DBObjectSet($oSearch, [], ['temp_id' => $sTempId]);
while ($oAttachment = $oSet->Fetch()) {
if (in_array($oAttachment->GetKey(), $aRemovedAttachmentIds)) {
$oAttachment->DBDelete();
// temporary attachment removed, don't even mention it in the history
}
else
{
} else {
$oAttachment->SetItem($oObject);
$oAttachment->Set('temp_id', '');
$oAttachment->DBUpdate();
@@ -361,10 +322,8 @@ class AttachmentPlugIn implements iApplicationUIExtension, iApplicationObjectExt
$oObject->FireEvent(EVENT_ADD_ATTACHMENT_TO_OBJECT, $aData);
}
}
if (count($aActions) > 0)
{
foreach ($aActions as $oChangeOp)
{
if (count($aActions) > 0) {
foreach ($aActions as $oChangeOp) {
self::RecordHistory($oChange, $oObject, $oChangeOp);
}
self::$m_bIsModified = true;
@@ -375,11 +334,10 @@ class AttachmentPlugIn implements iApplicationUIExtension, iApplicationObjectExt
public static function CopyAttachments($oObject, $sTransactionId)
{
$oSearch = DBObjectSearch::FromOQL("SELECT Attachment WHERE item_class = :class AND item_id = :item_id");
$oSet = new DBObjectSet($oSearch, array(), array('class' => get_class($oObject), 'item_id' => $oObject->GetKey()));
$oSet = new DBObjectSet($oSearch, [], ['class' => get_class($oObject), 'item_id' => $oObject->GetKey()]);
// Attach new (temporary) attachments
$sTempId = utils::GetUploadTempId($sTransactionId);
while ($oAttachment = $oSet->Fetch())
{
while ($oAttachment = $oSet->Fetch()) {
$oTempAttachment = clone $oAttachment;
$oTempAttachment->Set('expire', time() + utils::GetConfig()->Get('draft_attachments_lifetime'));
$oTempAttachment->Set('item_id', null);
@@ -392,15 +350,11 @@ class AttachmentPlugIn implements iApplicationUIExtension, iApplicationObjectExt
public static function GetFileIcon($sFileName)
{
$aPathParts = pathinfo($sFileName);
if (!array_key_exists('extension', $aPathParts))
{
if (!array_key_exists('extension', $aPathParts)) {
// No extension: use the default icon
$sIcon = 'icons8-file.svg';
}
else
{
switch (strtolower($aPathParts['extension']))
{
} else {
switch (strtolower($aPathParts['extension'])) {
case 'doc':
case 'docx':
$sIcon = 'icons8-word.svg';
@@ -433,7 +387,7 @@ class AttachmentPlugIn implements iApplicationUIExtension, iApplicationObjectExt
case 'vb':
$sIcon = 'icons8-code-file.svg';
break;
case 'pdf':
$sIcon = 'icons8-pdf.svg';
break;
@@ -486,7 +440,7 @@ class AttachmentPlugIn implements iApplicationUIExtension, iApplicationObjectExt
case 'ai':
$sIcon = 'icons8-image-file.svg';
break;
case 'zip':
case 'gz':
case 'tgz':
@@ -520,34 +474,34 @@ class AttachmentPlugIn implements iApplicationUIExtension, iApplicationObjectExt
case 'wma':
$sIcon = 'icons8-audio-file.svg';
break;
case 'csv':
$sIcon = 'icons8-csv.svg';
break;
case 'log':
$sIcon = 'icons8-event-log.svg';
break;
case 'sql':
$sIcon = 'icons8-sql.svg';
break;
case 'xml':
$sIcon = 'icons8-xml-file.svg';
break;
break;
case 'email':
case 'eml':
case 'emlx':
case 'msg':
$sIcon = 'icons8-mail.svg';
break;
case 'patch':
$sIcon = 'icons8-bandage.svg';
break;
default:
$sIcon = 'icons8-file.svg';
break;
@@ -560,8 +514,7 @@ class AttachmentPlugIn implements iApplicationUIExtension, iApplicationObjectExt
/////////////////////////////////////////////////////////////////////////
private static function RecordHistory($oChange, $oTargetObject, $oMyChangeOp)
{
if (!is_null($oChange))
{
if (!is_null($oChange)) {
$oMyChangeOp->Set("change", $oChange->GetKey());
}
$oMyChangeOp->Set("objclass", get_class($oTargetObject));
@@ -574,14 +527,11 @@ class AttachmentPlugIn implements iApplicationUIExtension, iApplicationObjectExt
{
$oBlob = $oAttachment->Get('contents');
$sFileName = $oBlob->GetFileName();
if ($bCreate)
{
if ($bCreate) {
$oChangeOp = new CMDBChangeOpAttachmentAdded();
$oChangeOp->Set('attachment_id', $oAttachment->GetKey());
$oChangeOp->Set('filename', $sFileName);
}
else
{
} else {
$oChangeOp = new CMDBChangeOpAttachmentRemoved();
$oChangeOp->Set('filename', $sFileName);
}
@@ -603,44 +553,36 @@ class AttachmentPlugIn implements iApplicationUIExtension, iApplicationObjectExt
*/
public static function IsReadonlyState(DBObject $oObject, $sState, $sGUI = self::ENUM_GUI_ALL)
{
$aParamDefaultValue = array(
static::ENUM_GUI_ALL => array(
'Ticket' => array('closed'),
),
);
$aParamDefaultValue = [
static::ENUM_GUI_ALL => [
'Ticket' => ['closed'],
],
];
$bReadonly = false;
$sClass = get_class($oObject);
$aReadonlyStatus = MetaModel::GetModuleSetting('itop-attachments', 'readonly_states', $aParamDefaultValue);
if (!empty($aReadonlyStatus))
{
if (!empty($aReadonlyStatus)) {
// Merging GUIs entries
$aEntries = array();
$aEntries = [];
// - All
if (array_key_exists(static::ENUM_GUI_ALL, $aReadonlyStatus))
{
if (array_key_exists(static::ENUM_GUI_ALL, $aReadonlyStatus)) {
$aEntries = array_merge_recursive($aEntries, $aReadonlyStatus[static::ENUM_GUI_ALL]);
}
// - Backoffice & Portals
foreach (array(static::ENUM_GUI_BACKOFFICE, static::ENUM_GUI_PORTALS) as $sEnumGUI)
{
if (in_array($sGUI, array(static::ENUM_GUI_ALL, $sEnumGUI)))
{
if (array_key_exists($sEnumGUI, $aReadonlyStatus))
{
foreach ([static::ENUM_GUI_BACKOFFICE, static::ENUM_GUI_PORTALS] as $sEnumGUI) {
if (in_array($sGUI, [static::ENUM_GUI_ALL, $sEnumGUI])) {
if (array_key_exists($sEnumGUI, $aReadonlyStatus)) {
$aEntries = array_merge_recursive($aEntries, $aReadonlyStatus[$sEnumGUI]);
}
}
}
$aParentClasses = array_reverse(MetaModel::EnumParentClasses($sClass, ENUM_PARENT_CLASSES_ALL));
foreach ($aParentClasses as $sParentClass)
{
if (array_key_exists($sParentClass, $aEntries))
{
foreach ($aParentClasses as $sParentClass) {
if (array_key_exists($sParentClass, $aEntries)) {
// If we found an ancestor of the object's class, we stop looking event if the current state is not specified
if (in_array($oObject->GetState(), $aEntries[$sParentClass]))
{
if (in_array($oObject->GetState(), $aEntries[$sParentClass])) {
$bReadonly = true;
}
break;
@@ -664,38 +606,38 @@ class CMDBChangeOpAttachmentAdded extends CMDBChangeOp
{
public static function Init()
{
$aParams = array
(
$aParams =
[
"category" => "core/cmdb, grant_by_profile",
"key_type" => "",
"name_attcode" => "change",
"state_attcode" => "",
"reconc_keys" => array(),
"reconc_keys" => [],
"db_table" => "priv_changeop_attachment_added",
"db_key_field" => "id",
"db_finalclass_field" => "",
);
];
MetaModel::Init_Params($aParams);
MetaModel::Init_InheritAttributes();
MetaModel::Init_AddAttribute(new AttributeExternalKey("attachment_id", array(
MetaModel::Init_AddAttribute(new AttributeExternalKey("attachment_id", [
"targetclass" => "Attachment",
"allowed_values" => null,
"sql" => "attachment_id",
"is_null_allowed" => true,
"on_target_delete" => DEL_SILENT,
"depends_on" => array(),
)));
MetaModel::Init_AddAttribute(new AttributeString("filename", array(
"depends_on" => [],
]));
MetaModel::Init_AddAttribute(new AttributeString("filename", [
"allowed_values" => null,
"sql" => "filename",
"default_value" => "",
"is_null_allowed" => false,
"depends_on" => array(),
)));
"depends_on" => [],
]));
// Display lists
MetaModel::Init_SetZListItems('details', array('attachment_id')); // Attributes to be displayed for the complete details
MetaModel::Init_SetZListItems('list', array('attachment_id')); // Attributes to be displayed for a list
MetaModel::Init_SetZListItems('details', ['attachment_id']); // Attributes to be displayed for the complete details
MetaModel::Init_SetZListItems('list', ['attachment_id']); // Attributes to be displayed for a list
}
/**
@@ -715,12 +657,15 @@ class CMDBChangeOpAttachmentAdded extends CMDBChangeOp
$oAttachment = $oMonoObjectSet->Fetch();
$oDoc = $oAttachment->Get('contents');
$sPreview = $oDoc->IsPreviewAvailable() ? 'data-preview="true"' : '';
$sResult = Dict::Format('Attachments:History_File_Added',
'<span class="attachment-history-added attachment"><a '.$sPreview.' target="_blank" href="'.$oDoc->GetDownloadURL($sTargetObjectClass,
$iTargetObjectKey, 'contents').'">'.$sFilename.'</a></span>');
}
else
{
$sResult = Dict::Format(
'Attachments:History_File_Added',
'<span class="attachment-history-added attachment"><a '.$sPreview.' target="_blank" href="'.$oDoc->GetDownloadURL(
$sTargetObjectClass,
$iTargetObjectKey,
'contents'
).'">'.$sFilename.'</a></span>'
);
} else {
$sResult = Dict::Format('Attachments:History_File_Added', '<span class="attachment-history-deleted">'.$sFilename.'</span>');
}
@@ -732,30 +677,30 @@ class CMDBChangeOpAttachmentRemoved extends CMDBChangeOp
{
public static function Init()
{
$aParams = array
(
$aParams =
[
"category" => "core/cmdb, grant_by_profile",
"key_type" => "",
"name_attcode" => "change",
"state_attcode" => "",
"reconc_keys" => array(),
"reconc_keys" => [],
"db_table" => "priv_changeop_attachment_removed",
"db_key_field" => "id",
"db_finalclass_field" => "",
);
];
MetaModel::Init_Params($aParams);
MetaModel::Init_InheritAttributes();
MetaModel::Init_AddAttribute(new AttributeString("filename", array(
MetaModel::Init_AddAttribute(new AttributeString("filename", [
"allowed_values" => null,
"sql" => "filename",
"default_value" => "",
"is_null_allowed" => false,
"depends_on" => array(),
)));
"depends_on" => [],
]));
// Display lists
MetaModel::Init_SetZListItems('details', array('filename')); // Attributes to be displayed for the complete details
MetaModel::Init_SetZListItems('list', array('filename')); // Attributes to be displayed for a list
MetaModel::Init_SetZListItems('details', ['filename']); // Attributes to be displayed for the complete details
MetaModel::Init_SetZListItems('list', ['filename']); // Attributes to be displayed for a list
}
/**
@@ -764,8 +709,10 @@ class CMDBChangeOpAttachmentRemoved extends CMDBChangeOp
public function GetDescription()
{
// Temporary, until we change the options of GetDescription() -needs a more global revision
$sResult = Dict::Format('Attachments:History_File_Removed',
'<span class="attachment-history-deleted">'.utils::EscapeHtml($this->Get('filename')).'</span>');
$sResult = Dict::Format(
'Attachments:History_File_Removed',
'<span class="attachment-history-deleted">'.utils::EscapeHtml($this->Get('filename')).'</span>'
);
return $sResult;
}
@@ -785,8 +732,8 @@ class TriggerOnAttachmentDownload extends TriggerOnAttributeBlobDownload
*/
public static function Init()
{
$aParams = array
(
$aParams =
[
"category" => "grant_by_profile,core/cmdb,application",
"key_type" => "autoincrement",
"name_attcode" => "description",
@@ -797,13 +744,12 @@ class TriggerOnAttachmentDownload extends TriggerOnAttributeBlobDownload
"db_key_field" => "id",
"db_finalclass_field" => "",
"display_template" => "",
);
];
MetaModel::Init_Params($aParams);
MetaModel::Init_InheritAttributes();
}
}
class AttachmentsHelper
{
/**
@@ -815,29 +761,22 @@ class AttachmentsHelper
public static function GetAttachmentsDateAddedFromDb($sObjClass, $iObjKey)
{
$sQuery = "SELECT CMDBChangeOpAttachmentAdded WHERE objclass='$sObjClass' AND objkey=$iObjKey";
try
{
try {
$oSearch = DBObjectSearch::FromOQL($sQuery);
}
catch (OQLException $e)
{
return array();
} catch (OQLException $e) {
return [];
}
$oSet = new DBObjectSet($oSearch);
try
{
$aAttachmentDates = array();
while ($oChangeOpAttAdded = $oSet->Fetch())
{
try {
$aAttachmentDates = [];
while ($oChangeOpAttAdded = $oSet->Fetch()) {
$iAttachmentId = $oChangeOpAttAdded->Get('attachment_id');
$sAttachmentDate = $oChangeOpAttAdded->Get('date');
$aAttachmentDates[$iAttachmentId] = $sAttachmentDate;
}
}
catch (Exception $e)
{
return array();
} catch (Exception $e) {
return [];
}
return $aAttachmentDates;