Skip to content

Commit

Permalink
details, comments, delete
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtificialOwl committed Oct 15, 2021
1 parent c12c647 commit 2d3faa1
Show file tree
Hide file tree
Showing 23 changed files with 864 additions and 19 deletions.
1 change: 1 addition & 0 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
<command>OCA\Backup\Command\ExternalList</command>
<command>OCA\Backup\Command\ExternalRemove</command>

<command>OCA\Backup\Command\PointComment</command>
<command>OCA\Backup\Command\PointCreate</command>
<command>OCA\Backup\Command\PointDelete</command>
<command>OCA\Backup\Command\PointDetails</command>
Expand Down
4 changes: 2 additions & 2 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
['name' => 'Remote#healthRestoringPoint', 'url' => '/rp/{pointId}/health', 'verb' => 'GET'],
['name' => 'Remote#downloadRestoringPoint', 'url' => '/rp/{pointId}/{chunkName}download', 'verb' => 'GET'],
['name' => 'Remote#createRestoringPoint', 'url' => '/rp', 'verb' => 'PUT'],
['name' => 'Remote#updateRestoringPoint', 'url' => '/rp/{pointId}', 'verb' => 'PUT'],
// ['name' => 'Remote#uploadRestoringChunk', 'url' => '/rp/{pointId}', 'verb' => 'POST']
['name' => 'Remote#updateRestoringPoint', 'url' => '/rp/{pointId}', 'verb' => 'POST'],
['name' => 'Remote#deleteRestoringPoint', 'url' => '/rp/{pointId}', 'verb' => 'DELETE'],
['name' => 'Remote#uploadRestoringChunk', 'url' => '/rp/{pointId}/{chunkName}', 'verb' => 'POST']
]
];
123 changes: 123 additions & 0 deletions lib/Command/PointComment.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
<?php

declare(strict_types=1);


/**
* Nextcloud - Backup now. Restore later.
*
* This file is licensed under the Affero General Public License version 3 or
* later. See the COPYING file.
*
* @author Maxence Lange <maxence@artificial-owl.com>
* @copyright 2021, Maxence Lange <maxence@artificial-owl.com>
* @license GNU AGPL version 3 or any later version
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation, either version 3 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/


namespace OCA\Backup\Command;


use ArtificialOwl\MySmallPhpTools\Exceptions\SignatoryException;
use OC\Core\Command\Base;
use OCA\Backup\Exceptions\RestoringPointNotFoundException;
use OCA\Backup\Service\MetadataService;
use OCA\Backup\Service\OutputService;
use OCA\Backup\Service\PointService;
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;


/**
* Class PointComment
*
* @package OCA\Backup\Command
*/
class PointComment extends Base {


/** @var PointService */
private $pointService;

/** @var MetadataService */
private $metadataService;

/** @var OutputService */
private $outputService;


/**
* PointComment constructor.
*
* @param PointService $pointService
* @param MetadataService $metadataService
* @param OutputService $outputService
*/
public function __construct(
PointService $pointService,
MetadataService $metadataService,
OutputService $outputService
) {
parent::__construct();

$this->pointService = $pointService;
$this->metadataService = $metadataService;
$this->outputService = $outputService;
}


/**
*
*/
protected function configure() {
parent::configure();

$this->setName('backup:point:comment')
->setDescription('Add a description to a restoring point')
->addArgument('pointId', InputArgument::REQUIRED, 'id of the restoring point to comment')
->addArgument('comment', InputArgument::REQUIRED, 'comment');
}


/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int
* @throws RestoringPointNotFoundException
* @throws SignatoryException
* @throws NotFoundException
* @throws NotPermittedException
*/
protected function execute(InputInterface $input, OutputInterface $output): int {
$this->outputService->setOutput($output);

$point = $this->pointService->getLocalRestoringPoint($input->getArgument('pointId'));
$point->setComment($input->getArgument('comment'));

$this->pointService->update($point, true);
$this->metadataService->globalUpdate($point);

return 0;
}


}

49 changes: 45 additions & 4 deletions lib/Command/PointDelete.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,14 @@

use OC\Core\Command\Base;
use OCA\Backup\Exceptions\RestoringPointNotFoundException;
use OCA\Backup\Service\ExternalFolderService;
use OCA\Backup\Service\PointService;
use OCP\DB\Exception;
use OCA\Backup\Service\RemoteService;
use OCP\Files\NotFoundException;
use OCP\Files\NotPermittedException;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;


Expand All @@ -54,16 +56,30 @@ class PointDelete extends Base {
/** @var PointService */
private $pointService;

/** @var RemoteService */
private $remoteService;

/** @var ExternalFolderService */
private $externalFolderService;


/**
* PointCreate constructor.
*
* @param PointService $pointService
* @param RemoteService $remoteService
* @param ExternalFolderService $externalFolderService
*/
public function __construct(PointService $pointService) {
public function __construct(
PointService $pointService,
RemoteService $remoteService,
ExternalFolderService $externalFolderService
) {
parent::__construct();

$this->pointService = $pointService;
$this->remoteService = $remoteService;
$this->externalFolderService = $externalFolderService;
}


Expand All @@ -75,7 +91,15 @@ protected function configure() {

$this->setName('backup:point:delete')
->setDescription('Locally delete a restoring point')
->addArgument('pointId', InputArgument::REQUIRED, 'id of the restoring point to delete');
->addArgument('pointId', InputArgument::REQUIRED, 'id of the restoring point to delete')
->addOption(
'remote', '', InputOption::VALUE_REQUIRED,
'remove a restoring point from a remote instance (or local)', ''
)
->addOption(
'external', '', InputOption::VALUE_REQUIRED,
'remove a restoring point from an external folder', ''
);
}


Expand All @@ -87,9 +111,26 @@ protected function configure() {
* @throws NotFoundException
* @throws NotPermittedException
* @throws RestoringPointNotFoundException
* @throws Exception
*/
protected function execute(InputInterface $input, OutputInterface $output): int {
if ($input->getOption('remote')) {
$remote = $this->remoteService->getByInstance($input->getOption('remote'));
$this->remoteService->deletePointRemote($remote, $input->getArgument('pointId'));

return 0;
}

if ($input->getOption('external')) {
$external = $this->externalFolderService->getByStorageId((int)$input->getOption('external'));
$point = $this->externalFolderService->getRestoringPoint(
$external,
$input->getArgument('pointId')
);

return 0;
}


$point = $this->pointService->getLocalRestoringPoint($input->getArgument('pointId'));

$this->pointService->delete($point);
Expand Down
21 changes: 21 additions & 0 deletions lib/Command/PointDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
use OCA\Backup\Model\ChunkPartHealth;
use OCA\Backup\Model\RestoringChunk;
use OCA\Backup\Model\RestoringData;
use OCA\Backup\Model\RestoringHealth;
use OCA\Backup\Model\RestoringPoint;
use OCA\Backup\Service\ChunkService;
use OCA\Backup\Service\ExternalFolderService;
Expand Down Expand Up @@ -224,6 +225,26 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}
}

$source = '';
if ($remote) {
$source = ' on <info>' . $remote . '</info>';
} else if ($external) {
$source = ' at <info>' . $externalFolder->getStorageId() . '</info>:<info>' .
$externalFolder->getRoot() . '</info>';
}
$output->writeln('');

$color = 'info';
if ($point->getHealth()->getStatus() !== RestoringHealth::STATUS_OK) {
$color = 'error';
}

$output->writeln(
'Status of the restoring point ' . $source . ': <' . $color . '>' .
RestoringHealth::$DEF[$point->getHealth()->getStatus()] . '</' . $color . '>'
);


return 0;
}

Expand Down
4 changes: 4 additions & 0 deletions lib/Command/PointDownload.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$remote = $input->getOption('remote');
$external = (int)$input->getOption('external');

if (!$remote && !$external) {
throw new InvalidOptionException('use --remote or --external');
}

try {
$point = $this->pointService->getRestoringPoint($pointId);
$output->writeln('> found a local restoring point');
Expand Down
11 changes: 10 additions & 1 deletion lib/Command/PointList.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$output = $output->section();

$table = new Table($output);
$table->setHeaders(['Restoring Point', 'Date', 'Parent', 'Status', 'Instance', 'Health']);
$table->setHeaders(['Restoring Point', 'Date', 'Parent', 'Comment', 'Status', 'Instance', 'Health']);
$table->render();

foreach ($rp as $pointId => $item) {
Expand All @@ -168,11 +168,20 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}
}
}

$comment = $point->getComment();
try {
$this->remoteStreamService->verifySubSign($point);
} catch (SignatoryException | SignatureException $e) {
$comment = '';
}

$table->appendRow(
[
($fresh) ? $displayPointId : '',
($fresh) ? date('Y-m-d H:i:s', $point->getDate()) : '',
($fresh) ? $point->getParent() : '',
$comment,
implode(',', $status),
$instance,
$this->displayStyleHealth($point),
Expand Down
1 change: 0 additions & 1 deletion lib/Command/RemoteList.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int

/** @var RemoteInstance $current */
try {
echo $remoteInstance->getId() . "\n";
$current = $this->remoteStreamService->retrieveSignatory($remoteInstance->getId());
$currentUid = $current->getUid(true);
if ($remoteInstance->getUid(true) === $currentUid) {
Expand Down
59 changes: 59 additions & 0 deletions lib/Controller/RemoteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@
use OCA\Backup\IRemoteRequest;
use OCA\Backup\Model\RemoteInstance;
use OCA\Backup\RemoteRequest\CreateRestoringPoint;
use OCA\Backup\RemoteRequest\DeleteRestoringPoint;
use OCA\Backup\RemoteRequest\DownloadRestoringChunk;
use OCA\Backup\RemoteRequest\GetRestoringPoint;
use OCA\Backup\RemoteRequest\ListRestoringPoint;
use OCA\Backup\RemoteRequest\UpdateRestoringPoint;
use OCA\Backup\RemoteRequest\UploadRestoringChunk;
use OCA\Backup\Service\RemoteStreamService;
use OCP\AppFramework\Controller;
Expand Down Expand Up @@ -192,6 +194,63 @@ public function getRestoringPoint(string $pointId): DataResponse {
}
}


/**
* @PublicPage
* @NoCSRFRequired
*
* @param string $pointId
*
* @return DataResponse
*/
public function updateRestoringPoint(string $pointId): DataResponse {
try {
$request = $this->extractRequest(UpdateRestoringPoint::class);
} catch (Exception $e) {
return $this->exceptionResponse($e, Http::STATUS_UNAUTHORIZED);
}

try {
$request->execute();

return new DataResponse($request->getOutcome());
} catch (Exception $e) {
$this->e($e, ['request' => $request]);

return $this->exceptionResponse($e);
}
}



/**
* @PublicPage
* @NoCSRFRequired
*
* @param string $pointId
*
* @return DataResponse
*/
public function deleteRestoringPoint(string $pointId): DataResponse {
try {
$request = $this->extractRequest(DeleteRestoringPoint::class);
} catch (Exception $e) {
return $this->exceptionResponse($e, Http::STATUS_UNAUTHORIZED);
}

try {
$request->execute();

return new DataResponse($request->getOutcome());
} catch (Exception $e) {
$this->e($e, ['request' => $request]);

return $this->exceptionResponse($e);
}
}



/**
* @PublicPage
* @NoCSRFRequired
Expand Down

0 comments on commit 2d3faa1

Please sign in to comment.