Skip to content

Commit

Permalink
archive/unarchive, broadcast on demand, external based on storageId
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtificialOwl committed Oct 18, 2021
1 parent f5738eb commit a2c2488
Show file tree
Hide file tree
Showing 28 changed files with 984 additions and 594 deletions.
2 changes: 2 additions & 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\PointArchive</command>
<command>OCA\Backup\Command\PointComment</command>
<command>OCA\Backup\Command\PointCreate</command>
<command>OCA\Backup\Command\PointDelete</command>
Expand All @@ -42,6 +43,7 @@
<command>OCA\Backup\Command\PointPack</command>
<command>OCA\Backup\Command\PointRestore</command>
<command>OCA\Backup\Command\PointScan</command>
<command>OCA\Backup\Command\PointUnarchive</command>
<command>OCA\Backup\Command\PointUnpack</command>
<command>OCA\Backup\Command\PointUpload</command>

Expand Down
2 changes: 2 additions & 0 deletions appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
['name' => 'Local#getSettings', 'url' => '/settings', 'verb' => 'GET'],
['name' => 'Local#setSettings', 'url' => '/settings', 'verb' => 'PUT'],
['name' => 'Local#getRestoringPoint', 'url' => '/rp', 'verb' => 'GET'],
['name' => 'Local#getExternalFolder', 'url' => '/external', 'verb' => 'GET'],
['name' => 'Local#setExternalFolder', 'url' => '/external', 'verb' => 'POST'],
['name' => 'Local#initAction', 'url' => '/action/{type}/{param}', 'verb' => 'POST']
],

Expand Down
38 changes: 35 additions & 3 deletions lib/Command/ExternalAdd.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,12 @@
namespace OCA\Backup\Command;


use ArtificialOwl\MySmallPhpTools\Traits\Nextcloud\nc23\TNC23WellKnown;
use OC\Core\Command\Base;
use OCA\Backup\Db\ExternalFolderRequest;
use OCA\Backup\Model\ExternalFolder;
use OCA\Files_External\Service\GlobalStoragesService;
use OCA\Files_External\Service\UserStoragesService;
use OCP\Files\Mount\IMountManager;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -49,8 +51,14 @@
class ExternalAdd extends Base {


use TNC23WellKnown;
/** @var IMountManager */
private $mountManager;

/** @var GlobalStoragesService */
private $globalStoragesService;

/** @var UserStoragesService */
private $userStoragesService;

/** @var ExternalFolderRequest */
private $externalFolderRequest;
Expand All @@ -59,11 +67,22 @@ class ExternalAdd extends Base {
/**
* ExternalAdd constructor.
*
* @param GlobalStoragesService $globalStoragesService
* @param UserStoragesService $userStoragesService
* @param ExternalFolderRequest $externalFolderRequest
*/
public function __construct(ExternalFolderRequest $externalFolderRequest) {
public function __construct(
IMountManager $mountManager,
GlobalStoragesService $globalStoragesService,
UserStoragesService $userStoragesService,
ExternalFolderRequest $externalFolderRequest
) {
parent::__construct();


$this->mountManager = $mountManager;
$this->globalStoragesService = $globalStoragesService;
$this->userStoragesService = $userStoragesService;
$this->externalFolderRequest = $externalFolderRequest;
}

Expand All @@ -86,6 +105,19 @@ protected function configure() {
* @return int
*/
protected function execute(InputInterface $input, OutputInterface $output): int {


// $storages = array_map(function (StorageConfig $storageConfig) use ($user) {
// try {
// $this->prepareStorageConfig($storageConfig, $user);
// return $this->constructStorage($storageConfig);
// } catch (\Exception $e) {
// // propagate exception into filesystem
// return new FailedStorage(['exception' => $e]);
// }
// }, $storageConfigs);


$storageId = (int)$input->getArgument('storage_id');
$root = $input->getArgument('root');

Expand Down
136 changes: 136 additions & 0 deletions lib/Command/PointArchive.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
<?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\ExternalFolderNotFoundException;
use OCA\Backup\Exceptions\MetadataException;
use OCA\Backup\Exceptions\RemoteInstanceException;
use OCA\Backup\Exceptions\RemoteInstanceNotFoundException;
use OCA\Backup\Exceptions\RemoteResourceNotFoundException;
use OCA\Backup\Exceptions\RestoringChunkPartNotFoundException;
use OCA\Backup\Exceptions\RestoringPointException;
use OCA\Backup\Exceptions\RestoringPointNotFoundException;
use OCA\Backup\Exceptions\RestoringPointPackException;
use OCA\Backup\Service\OccService;
use OCA\Backup\Service\OutputService;
use OCP\Files\GenericFileException;
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;


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


/** @var OccService */
private $occService;

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


/**
* PointArchive constructor.
*
* @param OccService $occService
* @param OutputService $outputService
*/
public function __construct(
OccService $occService,
OutputService $outputService
) {
parent::__construct();

$this->occService = $occService;
$this->outputService = $outputService;
}


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

$this->setName('backup:point:archive')
->setDescription('Archive a restoring point')
->addArgument('pointId', InputArgument::REQUIRED, 'id of the restoring point to comment')
->addOption('remote', '', InputOption::VALUE_REQUIRED, 'address of the remote instance')
->addOption('external', '', InputOption::VALUE_REQUIRED, 'id of the external folder')
->addOption('all-storage', '', InputOption::VALUE_NONE, 'duplicate action on all storages');
}


/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int
* @throws MetadataException
* @throws NotFoundException
* @throws NotPermittedException
* @throws RestoringPointNotFoundException
* @throws SignatoryException
* @throws ExternalFolderNotFoundException
* @throws RemoteInstanceException
* @throws RemoteInstanceNotFoundException
* @throws RemoteResourceNotFoundException
* @throws RestoringChunkPartNotFoundException
* @throws RestoringPointException
* @throws RestoringPointPackException
* @throws GenericFileException
*/
protected function execute(InputInterface $input, OutputInterface $output): int {
$this->outputService->setOutput($output);
$point = $this->occService->getRestoringPointBasedOnParams($input);

$point->setInstance()
->setArchive(true);

$this->occService->updatePointBasedOnParams($point, $input);

return 0;
}

}

55 changes: 34 additions & 21 deletions lib/Command/PointComment.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,23 @@

use ArtificialOwl\MySmallPhpTools\Exceptions\SignatoryException;
use OC\Core\Command\Base;
use OCA\Backup\Exceptions\ExternalFolderNotFoundException;
use OCA\Backup\Exceptions\MetadataException;
use OCA\Backup\Exceptions\RemoteInstanceException;
use OCA\Backup\Exceptions\RemoteInstanceNotFoundException;
use OCA\Backup\Exceptions\RemoteResourceNotFoundException;
use OCA\Backup\Exceptions\RestoringChunkPartNotFoundException;
use OCA\Backup\Exceptions\RestoringPointException;
use OCA\Backup\Exceptions\RestoringPointNotFoundException;
use OCA\Backup\Service\MetadataService;
use OCA\Backup\Exceptions\RestoringPointPackException;
use OCA\Backup\Service\OccService;
use OCA\Backup\Service\OutputService;
use OCA\Backup\Service\PointService;
use OCP\Files\GenericFileException;
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 @@ -53,32 +62,26 @@
class PointComment extends Base {


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

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

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


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

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

Expand All @@ -92,7 +95,10 @@ protected function 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');
->addArgument('comment', InputArgument::REQUIRED, 'comment')
->addOption('remote', '', InputOption::VALUE_REQUIRED, 'address of the remote instance')
->addOption('external', '', InputOption::VALUE_REQUIRED, 'id of the external folder')
->addOption('all-storage', '', InputOption::VALUE_NONE, 'duplicate action on all storages');
}


Expand All @@ -101,23 +107,30 @@ protected function configure() {
* @param OutputInterface $output
*
* @return int
* @throws RestoringPointNotFoundException
* @throws SignatoryException
* @throws MetadataException
* @throws NotFoundException
* @throws NotPermittedException
* @throws RestoringPointNotFoundException
* @throws SignatoryException
* @throws ExternalFolderNotFoundException
* @throws RemoteInstanceException
* @throws RemoteInstanceNotFoundException
* @throws RemoteResourceNotFoundException
* @throws RestoringChunkPartNotFoundException
* @throws RestoringPointException
* @throws RestoringPointPackException
* @throws GenericFileException
*/
protected function execute(InputInterface $input, OutputInterface $output): int {
$this->outputService->setOutput($output);
$point = $this->occService->getRestoringPointBasedOnParams($input);

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

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

return 0;
}


}

0 comments on commit a2c2488

Please sign in to comment.