Skip to content
Snippets Groups Projects
Commit 27c925cc authored by JediKev's avatar JediKev
Browse files

issue: DB Error #1062

This addresses a long-time issue of the famous `DB Error #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.
parent 88f97b55
No related branches found
Tags v1.9.0
No related merge requests found
......@@ -148,7 +148,15 @@ extends InstrumentedList {
$_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,
)));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment