Skip to content

Commit b250bb6

Browse files
committed
remote download parts
1 parent eb8148f commit b250bb6

File tree

6 files changed

+27
-18
lines changed

6 files changed

+27
-18
lines changed

lib/Command/PointDownload.php

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
193193
}
194194
}
195195

196-
$point->unsetHealth();
197-
// ->setInstance('');
196+
$point->setInstance()
197+
->unsetHealth();
198198

199199
$this->pointRequest->save($point);
200200
$this->pointService->saveMetadata($point);
@@ -290,9 +290,6 @@ private function downloadMissingFiles(
290290
);
291291

292292
$part = clone $this->packService->getPartFromChunk($chunk, $partHealth->getPartName());
293-
// $this->packService->getChunkPartContent($point, $chunk, $part);
294-
//
295-
// $this->remoteService->uploadPart($instance, $point, $chunk, $part);
296293

297294
if (!is_null($remote)) {
298295
$this->remoteService->downloadPart($remote, $point, $chunk, $part);

lib/Controller/RemoteController.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,16 +220,16 @@ public function healthRestoringPoint(string $pointId): DataResponse {
220220
}
221221

222222

223-
224223
/**
225224
* @PublicPage
226225
* @NoCSRFRequired
227226
*
228227
* @param string $pointId
228+
* @param string $chunkName
229229
*
230230
* @return DataResponse
231231
*/
232-
public function downloadRestoringPoint(string $pointId): DataResponse {
232+
public function downloadRestoringPoint(string $pointId, string $chunkName): DataResponse {
233233
try {
234234
$request = $this->extractRequest(DownloadRestoringChunk::class);
235235
} catch (Exception $e) {

lib/Model/RestoringPoint.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ public function getId(): string {
145145
*
146146
* @return RestoringPoint
147147
*/
148-
public function setInstance(string $instance): self {
148+
public function setInstance(string $instance = ''): self {
149149
$this->instance = $instance;
150150

151151
return $this;

lib/RemoteRequest/DownloadRestoringChunk.php

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,13 @@
3737
use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc23\TNC23Deserialize;
3838
use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc23\TNC23Logger;
3939
use OCA\Backup\AppInfo\Application;
40+
use OCA\Backup\Exceptions\RestoringChunkNotFoundException;
4041
use OCA\Backup\Exceptions\RestoringPointNotFoundException;
42+
use OCA\Backup\Exceptions\RestoringPointNotInitiatedException;
4143
use OCA\Backup\IRemoteRequest;
42-
use OCA\Backup\Model\RestoringChunk;
44+
use OCA\Backup\Model\RestoringChunkPart;
4345
use OCA\Backup\Service\ChunkService;
46+
use OCA\Backup\Service\PackService;
4447
use OCA\Backup\Service\PointService;
4548
use OCP\Files\NotFoundException;
4649
use OCP\Files\NotPermittedException;
@@ -64,6 +67,9 @@ class DownloadRestoringChunk extends CoreRequest implements IRemoteRequest {
6467
/** @var ChunkService */
6568
private $chunkService;
6669

70+
/** @var PackService */
71+
private $packService;
72+
6773

6874
/**
6975
* DownloadRestoringChunk constructor.
@@ -73,33 +79,40 @@ class DownloadRestoringChunk extends CoreRequest implements IRemoteRequest {
7379
*/
7480
public function __construct(
7581
PointService $pointService,
76-
ChunkService $chunkService
82+
ChunkService $chunkService,
83+
PackService $packService
7784
) {
7885
parent::__construct();
7986

8087
$this->pointService = $pointService;
8188
$this->chunkService = $chunkService;
89+
$this->packService = $packService;
8290

8391
$this->setup('app', Application::APP_ID);
8492
}
8593

8694

8795
/**
96+
* @throws RestoringPointNotInitiatedException
97+
* @throws RestoringChunkNotFoundException
8898
*/
8999
public function execute(): void {
90100
try {
91101
$signedRequest = $this->getSignedRequest();
92102
$signatory = $signedRequest->getSignatory();
93103
$pointId = $signedRequest->getIncomingRequest()->getParam('pointId');
104+
$chunkName = $signedRequest->getIncomingRequest()->getParam('chunkName');
94105

95106
$point = $this->pointService->getRestoringPoint($pointId, $signatory->getInstance());
96-
/** @var RestoringChunk $chunk */
97-
$chunk = $this->deserializeJson($signedRequest->getBody(), RestoringChunk::class);
107+
$chunk = $this->chunkService->getChunkFromRP($point, $chunkName);
108+
109+
/** @var RestoringChunkPart $part */
110+
$part = $this->deserializeJson($signedRequest->getBody(), RestoringChunkPart::class);
98111

99112
$this->pointService->initBaseFolder($point);
100-
$this->chunkService->getChunkContent($point, $chunk);
113+
$this->packService->getChunkPartContent($point, $chunk, $part);
101114

102-
$this->setOutcome($this->serialize($chunk));
115+
$this->setOutcome($this->serialize($part));
103116

104117
} catch (RestoringPointNotFoundException
105118
| InvalidItemException

lib/Service/ExternalFolderService.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,9 @@ public function downloadPart(
271271
RestoringChunkPart $part
272272
): void {
273273
$folder = $this->getExternalChunkFolder($external, $point, $chunk, true);
274+
274275
/** @var File $file */
275276
$file = $folder->get($part->getName());
276-
$file = $folder->get($part->getName());
277277
if ($file->getType() !== FileInfo::TYPE_FILE) {
278278
throw new RestoringChunkPartNotFoundException('remote part is not a file');
279279
}

lib/Service/RemoteService.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ public function downloadPart(
278278
RestoringPoint $point,
279279
RestoringChunk $chunk,
280280
RestoringChunkPart $part
281-
): RestoringChunkPart {
281+
): void {
282282
$result = $this->remoteStreamService->resultRequestRemoteInstance(
283283
$instance,
284284
RemoteInstance::RP_DOWNLOAD,
@@ -291,11 +291,10 @@ public function downloadPart(
291291
try {
292292
/** @var RestoringChunkPart $downloaded */
293293
$downloaded = $this->deserialize($result, RestoringChunkPart::class);
294+
$part->setContent($downloaded->getContent());
294295
} catch (InvalidItemException $e) {
295296
throw new RestoringChunkPartNotFoundException();
296297
}
297-
298-
return $downloaded;
299298
}
300299

301300

0 commit comments

Comments
 (0)