Skip to content

Commit

Permalink
Merge pull request #35 from Wimski/update/attachment-clone
Browse files Browse the repository at this point in the history
Pass saved clone to attachment adapter duplicate method
  • Loading branch information
weotch authored Jun 16, 2020
2 parents bfb2db6 + 0b6bdea commit 4373516
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/Adapters/Upchuck.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,10 @@ public function __construct(Helpers $helpers,
* Duplicate a file given it's URL
*
* @param string $url
* @param Illuminate\Database\Eloquent\Model $clone
* @return string
*/
public function duplicate($url) {
public function duplicate($url, $clone) {

// Make the destination path
$current_path = $this->helpers->path($url);
Expand Down
3 changes: 2 additions & 1 deletion src/AttachmentAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ interface AttachmentAdapter {
* a model attribute
*
* @param string $reference
* @param Illuminate\Database\Eloquent\Model $clone
* @return string New reference to duplicated file
*/
public function duplicate($reference);
public function duplicate($reference, $clone);

}
6 changes: 3 additions & 3 deletions src/Cloner.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public function __construct(AttachmentAdapter $attachment = null,
*/
public function duplicate($model, $relation = null) {
$clone = $this->cloneModel($model);
$this->duplicateAttachments($model, $clone);
$this->saveClone($clone, $relation, $model);
$this->saveClone($clone, $relation, $model);
$this->duplicateAttachments($model, $clone);
$this->cloneRelations($model, $clone);
return $clone;
}
Expand Down Expand Up @@ -91,7 +91,7 @@ protected function duplicateAttachments($model, $clone) {
if (!$this->attachment || !method_exists($clone, 'getCloneableFileAttributes')) return;
foreach($clone->getCloneableFileAttributes() as $attribute) {
if (!$original = $model->getAttribute($attribute)) continue;
$clone->setAttribute($attribute, $this->attachment->duplicate($original));
$clone->setAttribute($attribute, $this->attachment->duplicate($original, $clone));
}
}

Expand Down

0 comments on commit 4373516

Please sign in to comment.