Skip to content

Duplicate attachment from original model #32

@WimWidgets

Description

@WimWidgets

When duplicating an attachment, the attachment of the clone is used as a reference (line 92).

cloner/src/Cloner.php

Lines 89 to 95 in d9c92a1

protected function duplicateAttachments($clone) {
if (!$this->attachment || !method_exists($clone, 'getCloneableFileAttributes')) return;
foreach($clone->getCloneableFileAttributes() as $attribute) {
if (!$original = $clone->getAttribute($attribute)) continue;
$clone->setAttribute($attribute, $this->attachment->duplicate($original));
}
}

This probably doesn't matter in most cases, but it does with the attachment handler I use. This handler will for example generate the path based on properties of the model, like its key/ID. So in my adapter I cannot get the path of the current existing attachment, because the key is different in the clone.

Duplicating from the original model instead of the clone fixes my issue. It also seems more logical to me to duplicate from an original instead from a clone (which should only receive the duplicate).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions