From 432a950f8cc85097f674743a77eb11e127ff396c Mon Sep 17 00:00:00 2001 From: Eric Date: Mon, 20 Apr 2020 10:54:27 +0200 Subject: [PATCH] =?UTF-8?q?N=C2=B02945=20-=20Fix=20fatal=20error=20when=20?= =?UTF-8?q?adding=20empty=20attachment=20alert=20when=20empty=20attachment?= =?UTF-8?q?=20is=20detected?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- core/attributedef.class.inc.php | 11 +++++++++-- .../itop-attachments/ajax.itop-attachment.php | 4 ++++ .../en.dict.itop-attachments.php | 1 + .../fr.dict.itop-attachments.php | 1 + .../renderers.itop-attachments.php | 18 +++++++++++++++--- 5 files changed, 30 insertions(+), 5 deletions(-) diff --git a/core/attributedef.class.inc.php b/core/attributedef.class.inc.php index 30ebb8e23a..e86e84e4f3 100644 --- a/core/attributedef.class.inc.php +++ b/core/attributedef.class.inc.php @@ -7706,10 +7706,17 @@ class AttributeBlob extends AttributeDefinition // (temporary tables created on disk) // We will have to remove the blobs from the list of attributes when doing the select // then the use of Get() should finalize the load - if ($value instanceOf ormDocument && !$value->IsEmpty()) + if ($value instanceOf ormDocument) { $aValues = array(); - $aValues[$this->GetCode().'_data'] = $value->GetData(); + if (!$value->IsEmpty()) + { + $aValues[$this->GetCode().'_data'] = $value->GetData(); + } + else + { + $aValues[$this->GetCode().'_data'] = ''; + } $aValues[$this->GetCode().'_mimetype'] = $value->GetMimeType(); $aValues[$this->GetCode().'_filename'] = $value->GetFileName(); } diff --git a/datamodels/2.x/itop-attachments/ajax.itop-attachment.php b/datamodels/2.x/itop-attachments/ajax.itop-attachment.php index 902922781a..cdcace1cbe 100644 --- a/datamodels/2.x/itop-attachments/ajax.itop-attachment.php +++ b/datamodels/2.x/itop-attachments/ajax.itop-attachment.php @@ -89,6 +89,10 @@ try try { $oDoc = utils::ReadPostedDocument('file'); + if ($oDoc->IsEmpty()) + { + throw new FileUploadException(Dict::S('Attachments:Error:UploadedFileEmpty')); + } /** @var Attachment $oAttachment */ $oAttachment = MetaModel::NewObject('Attachment'); $oAttachment->Set('expire', time() + MetaModel::GetConfig()->Get('draft_attachments_lifetime')); diff --git a/datamodels/2.x/itop-attachments/en.dict.itop-attachments.php b/datamodels/2.x/itop-attachments/en.dict.itop-attachments.php index 1067abcf5f..ba40a951e3 100755 --- a/datamodels/2.x/itop-attachments/en.dict.itop-attachments.php +++ b/datamodels/2.x/itop-attachments/en.dict.itop-attachments.php @@ -32,6 +32,7 @@ Dict::Add('EN US', 'English', 'English', array( 'Attachments:NoAttachment' => 'No attachment. ', 'Attachments:PreviewNotAvailable' => 'Preview not available for this type of attachment.', 'Attachments:Error:FileTooLarge' => 'File is too large to be uploaded. %1$s', + 'Attachments:Error:UploadedFileEmpty' => 'The received file is empty. Check that your server disk is not full.', 'Attachments:Render:Icons' => 'Display as icons', 'Attachments:Render:Table' => 'Display as list', )); diff --git a/datamodels/2.x/itop-attachments/fr.dict.itop-attachments.php b/datamodels/2.x/itop-attachments/fr.dict.itop-attachments.php index bf101df0a3..6359f2a724 100755 --- a/datamodels/2.x/itop-attachments/fr.dict.itop-attachments.php +++ b/datamodels/2.x/itop-attachments/fr.dict.itop-attachments.php @@ -31,6 +31,7 @@ Dict::Add('FR FR', 'French', 'Français', array( 'Attachments:NoAttachment' => 'Aucune pièce jointe.', 'Attachments:PreviewNotAvailable' => 'Pas d\'aperçu pour ce type de pièce jointe.', 'Attachments:Error:FileTooLarge' => 'Le fichier est trop gros pour être chargé. %1$s', + 'Attachments:Error:UploadedFileEmpty' => 'Le fichier téléchargé est vide. Vérifiez qu\'il reste de la place disque disponible sur le serveur', 'Attachments:Render:Icons' => 'Affichage en icônes', 'Attachments:Render:Table' => 'Affichage en liste', )); diff --git a/datamodels/2.x/itop-attachments/renderers.itop-attachments.php b/datamodels/2.x/itop-attachments/renderers.itop-attachments.php index 8774a08f86..b91f59670e 100644 --- a/datamodels/2.x/itop-attachments/renderers.itop-attachments.php +++ b/datamodels/2.x/itop-attachments/renderers.itop-attachments.php @@ -173,7 +173,7 @@ abstract class AbstractAttachmentsRenderer $(sContentNode).html(data); $(sContentNode).unblock(); } - ); + ) } $('#file').fileupload({ @@ -181,8 +181,20 @@ abstract class AbstractAttachmentsRenderer formData: { operation: 'add', temp_id: '$this->sTransactionId', obj_class: '$sClass' }, dataType: 'json', pasteZone: null, // Don't accept files via Chrome's copy/paste - done: RefreshAttachmentsDisplay, - send: function(e, data){ + done: function (e, data) { + if(typeof(data.result.error) != 'undefined') + { + if(data.result.error !== '') + { + alert(data.result.error); + } + else + { + RefreshAttachmentsDisplay(); + } + } + }, + send: function(e, data){ // Don't send attachment if size is greater than PHP post_max_size, otherwise it will break the request and all its parameters (\$_REQUEST, \$_POST, ...) // Note: We loop on the files as the data structures is an array but in this case, we only upload 1 file at a time. var iTotalSizeInBytes = 0;