2019-10-10 02:13:04 +00:00
|
|
|
<?php
|
2020-10-14 22:19:31 +00:00
|
|
|
|
2021-07-19 05:53:45 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2019-10-10 02:13:04 +00:00
|
|
|
namespace App\Controller\Api\Stations\Files;
|
|
|
|
|
|
|
|
use App\Entity;
|
2021-03-31 16:42:24 +00:00
|
|
|
use App\Flysystem\StationFilesystems;
|
2019-10-10 02:13:04 +00:00
|
|
|
use App\Http\Response;
|
|
|
|
use App\Http\ServerRequest;
|
2021-05-06 15:08:57 +00:00
|
|
|
use App\Media\BatchUtilities;
|
2019-10-10 02:13:04 +00:00
|
|
|
use Psr\Http\Message\ResponseInterface;
|
|
|
|
|
2021-05-06 15:08:57 +00:00
|
|
|
class RenameAction
|
2019-10-10 02:13:04 +00:00
|
|
|
{
|
|
|
|
public function __invoke(
|
|
|
|
ServerRequest $request,
|
2021-05-06 15:08:57 +00:00
|
|
|
Response $response,
|
|
|
|
BatchUtilities $batchUtilities
|
2019-10-10 02:13:04 +00:00
|
|
|
): ResponseInterface {
|
2020-11-23 06:38:49 +00:00
|
|
|
$from = $request->getParam('file');
|
|
|
|
if (empty($from)) {
|
2019-10-10 02:13:04 +00:00
|
|
|
return $response->withStatus(500)
|
|
|
|
->withJson(new Entity\Api\Error(500, __('File not specified.')));
|
|
|
|
}
|
|
|
|
|
2020-11-23 06:38:49 +00:00
|
|
|
$to = $request->getParam('newPath');
|
|
|
|
if (empty($to)) {
|
2019-10-10 02:13:04 +00:00
|
|
|
return $response->withStatus(500)
|
|
|
|
->withJson(new Entity\Api\Error(500, __('New path not specified.')));
|
|
|
|
}
|
|
|
|
|
|
|
|
// No-op if paths match
|
2020-11-23 06:38:49 +00:00
|
|
|
if ($from === $to) {
|
2019-10-10 02:13:04 +00:00
|
|
|
return $response->withJson(new Entity\Api\Status());
|
|
|
|
}
|
|
|
|
|
|
|
|
$station = $request->getStation();
|
2020-11-23 06:38:49 +00:00
|
|
|
$storageLocation = $station->getMediaStorageLocation();
|
|
|
|
|
2021-06-08 06:40:49 +00:00
|
|
|
$fsMedia = (new StationFilesystems($station))->getMediaFilesystem();
|
2020-11-23 06:38:49 +00:00
|
|
|
|
2021-03-31 16:42:24 +00:00
|
|
|
$fsMedia->move($from, $to);
|
2020-11-23 06:38:49 +00:00
|
|
|
|
2021-05-06 15:08:57 +00:00
|
|
|
$batchUtilities->handleRename($from, $to, $storageLocation, $fsMedia);
|
2019-10-10 02:13:04 +00:00
|
|
|
|
|
|
|
return $response->withJson(new Entity\Api\Status());
|
|
|
|
}
|
2020-10-13 04:50:21 +00:00
|
|
|
}
|