Skip to content

Commit

Permalink
Extracting logic to get the destination folder to method
Browse files Browse the repository at this point in the history
  • Loading branch information
nWidart committed Oct 10, 2017
1 parent cfde81a commit 6bc5522
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions Modules/Media/Http/Controllers/Api/MoveMediaController.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ public function __construct(

public function __invoke(MoveMediaRequest $request)
{
$destination = $this->folder->findFolder($request->get('destinationFolder'));
if ($destination === null) {
$destination = $this->makeRootFolder();
}
$destination = $this->getDestinationFolder($request->get('destinationFolder'));

$failedMoves = 0;
foreach ($request->get('files') as $file) {
Expand Down Expand Up @@ -80,4 +77,18 @@ private function makeRootFolder() : File
'path' => config('asgard.media.config.files-path'),
]);
}

/**
* @param int $destinationFolderId
* @return File
*/
protected function getDestinationFolder($destinationFolderId) : File
{
$destination = $this->folder->findFolder($destinationFolderId);
if ($destination === null) {
$destination = $this->makeRootFolder();
}

return $destination;
}
}

0 comments on commit 6bc5522

Please sign in to comment.