N°2945 - Fix fatal error when adding empty attachment

alert when empty attachment is detected
This commit is contained in:
Eric
2020-04-20 10:54:27 +02:00
parent bbc751bee4
commit 432a950f8c
5 changed files with 30 additions and 5 deletions

View File

@@ -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();
}

View File

@@ -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'));

View File

@@ -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',
));

View File

@@ -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',
));

View File

@@ -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;