Skip to content

Commit

Permalink
issue: DB Error osTicket#1062
Browse files Browse the repository at this point in the history
This addresses a long-time issue of the famous `DB Error osTicket#1062` when
uploading an Inline File to a Draft. The issue is that the system does not
check if an Attachment record exists before creating a new one. We create a
new Attachment record, we go to save it, and the system errors out because
that record already exists. This adds a check to see if the Attachment
record already exists and if so we use that instead of creating a new one.
  • Loading branch information
JediKev committed Nov 6, 2019
1 parent 88f97b5 commit 27c925c
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion include/class.attachment.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,15 @@ function upload($files, $inline=false, $lang=false) {

$_inline = isset($file['inline']) ? $file['inline'] : $inline;

$att = $this->add(new Attachment(array(
// Check if Attachment exists
if ($F && $this->key)
$existing = Attachment::objects()->filter(array(
'file__key' => $F->key,
'object_id' => $this->key['object_id'],
'type' => $this->key['type']
))->first();

$att = $this->add(isset($existing) ? $existing : new Attachment(array(
'file_id' => $fileId,
'inline' => $_inline ? 1 : 0,
)));
Expand Down

0 comments on commit 27c925c

Please sign in to comment.