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