Skip to content

Commit

Permalink
Get original attachment from model instead of clone when duplicating
Browse files Browse the repository at this point in the history
  • Loading branch information
wimski committed May 7, 2020
1 parent a4e2721 commit 73433ef
Showing 1 changed file with 4 additions and 3 deletions.
7 changes: 4 additions & 3 deletions src/Cloner.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function __construct(AttachmentAdapter $attachment = null,
*/
public function duplicate($model, $relation = null) {
$clone = $this->cloneModel($model);
$this->duplicateAttachments($clone);
$this->duplicateAttachments($model, $clone);
$this->saveClone($clone, $relation, $model);
$this->cloneRelations($model, $clone);
return $clone;
Expand Down Expand Up @@ -83,13 +83,14 @@ protected function cloneModel($model) {
* Duplicate all attachments, given them a new name, and update the attribute
* value
*
* @param Illuminate\Database\Eloquent\Model $model
* @param Illuminate\Database\Eloquent\Model $clone
* @return void
*/
protected function duplicateAttachments($clone) {
protected function duplicateAttachments($model, $clone) {
if (!$this->attachment || !method_exists($clone, 'getCloneableFileAttributes')) return;
foreach($clone->getCloneableFileAttributes() as $attribute) {
if (!$original = $clone->getAttribute($attribute)) continue;
if (!$original = $model->getAttribute($attribute)) continue;
$clone->setAttribute($attribute, $this->attachment->duplicate($original));
}
}
Expand Down

0 comments on commit 73433ef

Please sign in to comment.