Skip to content

Commit

Permalink
cleaning code
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtificialOwl committed Sep 30, 2021
1 parent c0b48fc commit 92289a4
Show file tree
Hide file tree
Showing 56 changed files with 298 additions and 2,627 deletions.
1 change: 0 additions & 1 deletion appinfo/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
['name' => 'Remote#listRestoringPoint', 'url' => '/rp', 'verb' => 'GET'],
['name' => 'Remote#getRestoringPoint', 'url' => '/rp/{pointId}', 'verb' => 'GET'],
['name' => 'Remote#healthRestoringPoint', 'url' => '/rp/{pointId}/health', 'verb' => 'GET'],
['name' => 'Remote#partRestoringPoint', 'url' => '/rp/{pointId}/part', 'verb' => 'GET'],
['name' => 'Remote#downloadRestoringPoint', 'url' => '/rp/{pointId}/download', 'verb' => 'GET'],
['name' => 'Remote#createRestoringPoint', 'url' => '/rp', 'verb' => 'PUT'],
['name' => 'Remote#updateRestoringPoint', 'url' => '/rp/{pointId}', 'verb' => 'PUT'],
Expand Down
18 changes: 4 additions & 14 deletions lib/Command/PointDelete.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,19 +33,14 @@


use OC\Core\Command\Base;
use OCA\Backup\Exceptions\ArchiveCreateException;
use OCA\Backup\Exceptions\ArchiveNotFoundException;
use OCA\Backup\Exceptions\BackupAppCopyException;
use OCA\Backup\Exceptions\BackupScriptNotFoundException;
use OCA\Backup\Exceptions\RestoringPointException;
use OCA\Backup\Exceptions\SqlDumpException;
use OCA\Backup\Exceptions\RestoringPointNotFoundException;
use OCA\Backup\Service\PointService;
use OCP\DB\Exception;
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;
use Throwable;


/**
Expand Down Expand Up @@ -91,13 +86,8 @@ protected function configure() {
* @return int
* @throws NotFoundException
* @throws NotPermittedException
* @throws ArchiveCreateException
* @throws ArchiveNotFoundException
* @throws BackupAppCopyException
* @throws BackupScriptNotFoundException
* @throws SqlDumpException
* @throws RestoringPointException
* @throws Throwable
* @throws RestoringPointNotFoundException
* @throws Exception
*/
protected function execute(InputInterface $input, OutputInterface $output): int {
$point = $this->pointService->getLocalRestoringPoint($input->getArgument('pointId'));
Expand Down
3 changes: 3 additions & 0 deletions lib/Command/PointDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,9 @@ protected function configure() {
* @return int
* @throws NotFoundException
* @throws NotPermittedException
* @throws RemoteInstanceException
* @throws RemoteInstanceNotFoundException
* @throws RemoteResourceNotFoundException
* @throws RestoringPointNotFoundException
*/
protected function execute(InputInterface $input, OutputInterface $output): int {
Expand Down
46 changes: 7 additions & 39 deletions lib/Command/PointRestore.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools;
use ArtificialOwl\MySmallPhpTools\Traits\TStringTools;
use Exception;
use OC\Core\Command\Base;
use OCA\Backup\Exceptions\ArchiveCreateException;
use OCA\Backup\Exceptions\ArchiveFileNotFoundException;
Expand All @@ -42,6 +43,7 @@
use OCA\Backup\Exceptions\RestoringChunkNotFoundException;
use OCA\Backup\Exceptions\RestoringDataNotFoundException;
use OCA\Backup\Exceptions\RestoringPointNotFoundException;
use OCA\Backup\Exceptions\SqlDumpException;
use OCA\Backup\Exceptions\SqlImportException;
use OCA\Backup\Model\ChangedFile;
use OCA\Backup\Model\RestoringData;
Expand Down Expand Up @@ -156,6 +158,7 @@ protected function configure() {
* @throws NotPermittedException
* @throws RestoringPointNotFoundException
* @throws RestoringDataNotFoundException
* @throws SqlDumpException
*/
protected function execute(InputInterface $input, OutputInterface $output): int {
$this->output = $output;
Expand Down Expand Up @@ -202,7 +205,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
'Your instance will come back to a previous state from '
. $this->getDateDiff($point->getDate(), time()) . ' ago.'
);
} catch (\Exception $e) {
} catch (Exception $e) {
}

$output->writeln('');
Expand All @@ -229,6 +232,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int

/**
* @param RestoringPoint $point
*
* @throws SqlDumpException
*/
public function restorePointComplete(RestoringPoint $point): void {
$this->pointService->loadSqlDump();
Expand Down Expand Up @@ -284,7 +289,7 @@ public function restorePointComplete(RestoringPoint $point): void {
* @param RestoringData $data
*
* @throws SqlImportException
* @throws \OCA\Backup\Exceptions\SqlDumpException
* @throws SqlDumpException
*/
private function importSqlDump(RestoringPoint $point, RestoringData $data): void {
$chunks = $data->getChunks();
Expand Down Expand Up @@ -313,43 +318,6 @@ private function importSqlDump(RestoringPoint $point, RestoringData $data): void
}


/**
* @return array
*/
private function extractDatabaseConfig(): array {
if ($this->configService->getSystemValue('dbtype') !== 'mysql') {
return [];
}

return [
'dbname' => $this->configService->getSystemValue('dbname'),
'dbhost' => $this->configService->getSystemValue('dbhost'),
'dbport' => $this->configService->getSystemValue('dbport'),
'dbuser' => $this->configService->getSystemValue('dbuser'),
'dbpassword' => $this->configService->getSystemValue('dbpassword')
];

// $CONFIG = [];
// require($config);
//
// $this->mustContains(['dbtype'], $CONFIG);
// if ($CONFIG['dbtype'] === 'mysql') {
// $this->mustContains(['dbname', 'dbport', 'dbhost', 'dbuser', 'dbpassword'], $CONFIG);
// $data = [
// 'dbname' => $CONFIG['dbname'],
// 'dbhost' => $CONFIG['dbhost'],
// 'dbport' => $CONFIG['dbport'],
// 'dbuser' => $CONFIG['dbuser'],
// 'dbpassword' => $CONFIG['dbpassword']
// ];
//
// return $data;
// }
//
// return [];
}


/**
* @param RestoringPoint $point
* @param string|null $filename
Expand Down
5 changes: 5 additions & 0 deletions lib/Command/PointScan.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
use OCA\Backup\Service\ArchiveService;
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;
Expand Down Expand Up @@ -116,6 +118,9 @@ protected function configure() {
* @param OutputInterface $output
*
* @return int
* @throws RestoringPointNotFoundException
* @throws NotFoundException
* @throws NotPermittedException
*/
protected function execute(InputInterface $input, OutputInterface $output): int {
$pointId = $input->getArgument('pointId');
Expand Down
93 changes: 93 additions & 0 deletions lib/Command/PointStore.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
<?php

declare(strict_types=1);


/**
* Nextcloud - Backup
*
* 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 2019, 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 OC\Core\Command\Base;
use OCA\Backup\Exceptions\RestoringPointNotFoundException;
use OCA\Backup\Service\PointService;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;


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


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


/**
* PointStore constructor.
*
* @param PointService $pointService
*/
public function __construct(PointService $pointService) {
parent::__construct();

$this->pointService = $pointService;
}


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

$this->setName('backup:point:store')
->setDescription('Increase compression of a restoring point and prepare for upload')
->addArgument('pointId', InputArgument::REQUIRED, 'Id of the restoring point');
}


/**
* @param InputInterface $input
* @param OutputInterface $output
*
* @return int
* @throws RestoringPointNotFoundException
*/
protected function execute(InputInterface $input, OutputInterface $output): int {
$point = $this->pointService->getLocalRestoringPoint($input->getArgument('pointId'));

return 0;
}

}

27 changes: 20 additions & 7 deletions lib/Command/PointUpload.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,16 @@
use OCA\Backup\Exceptions\RemoteInstanceNotFoundException;
use OCA\Backup\Exceptions\RemoteResourceNotFoundException;
use OCA\Backup\Exceptions\RestorationPointUploadException;
use OCA\Backup\Exceptions\RestoringChunkNotFoundException;
use OCA\Backup\Exceptions\RestoringPointNotFoundException;
use OCA\Backup\Model\RestoringChunkHealth;
use OCA\Backup\Model\RestoringHealth;
use OCA\Backup\Model\RestoringPoint;
use OCA\Backup\Service\OutputService;
use OCA\Backup\Service\PointService;
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\Output\OutputInterface;
Expand Down Expand Up @@ -278,13 +281,23 @@ private function uploadMissingFiles(
}

$output->write(' * Uploading ' . $chunk->getDataName() . '/' . $chunk->getChunkName() . ': ');
$restoringChunk = $this->pointService->getChunkContent(
$point,
$chunk->getDataName(),
$chunk->getChunkName()
);
$this->remoteService->uploadChunk($instance, $point, $restoringChunk);
$output->writeln('<info>ok</info>');
try {
$restoringChunk = $this->pointService->getChunkContent(
$point,
$chunk->getDataName(),
$chunk->getChunkName()
);
$this->remoteService->uploadChunk($instance, $point, $restoringChunk);
$output->writeln('<info>ok</info>');
} catch (
RestoringChunkNotFoundException
| NotFoundException
| NotPermittedException
| RemoteInstanceException
| RemoteInstanceNotFoundException
| RemoteResourceNotFoundException $e) {
$output->writeln('<error>' . $e->getMessage() . '</error>');
}

}
}
Expand Down
1 change: 1 addition & 0 deletions lib/Command/RemoteAdd.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ private function getCurrentResourceFromAddress(
* @param InputInterface $input
* @param OutputInterface $output
* @param RemoteInstance $remoteInstance
* @param RemoteInstance|null $knownInstance
*/
private function configureRemoteInstance(
InputInterface $input,
Expand Down
2 changes: 0 additions & 2 deletions lib/Command/RemoteRemove.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
use OC\Core\Command\Base;
use OCA\Backup\Db\RemoteRequest;
use OCA\Backup\Exceptions\RemoteInstanceNotFoundException;
use OCA\Backup\Service\RemoteStreamService;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
Expand All @@ -57,7 +56,6 @@ class RemoteRemove extends Base {
* RemoteRemove constructor.
*
* @param RemoteRequest $remoteRequest
* @param RemoteStreamService $remoteStreamService
*/
public function __construct(RemoteRequest $remoteRequest) {
$this->remoteRequest = $remoteRequest;
Expand Down
4 changes: 2 additions & 2 deletions lib/Command/Reset.php
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$this->coreRequestBuilder->cleanDatabase();
try {
$this->pointService->destroyBackupFS();
} catch (NotFoundException $e) {
} catch (NotPermittedException $e) {
} catch (NotFoundException | NotPermittedException $e) {
}

$this->configService->setAppValue(ConfigService::LAST_FULL_RP, '');
if ($action === 'uninstall') {
$this->coreRequestBuilder->uninstall();
Expand Down
4 changes: 2 additions & 2 deletions lib/Command/SetupExport.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
namespace OCA\Backup\Command;


use Exception;
use OC\Core\Command\Base;
use OCA\Backup\Service\ConfigService;
use OCA\Backup\Service\EncryptService;
use OCA\Backup\Service\RemoteService;
use SodiumException;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
Expand Down Expand Up @@ -96,7 +96,7 @@ protected function configure() {
* @param OutputInterface $output
*
* @return int
* @throws SodiumException
* @throws Exception
*/
protected function execute(InputInterface $input, OutputInterface $output): int {
$setup = [
Expand Down
11 changes: 0 additions & 11 deletions lib/Controller/RemoteController.php
Original file line number Diff line number Diff line change
Expand Up @@ -220,17 +220,6 @@ public function healthRestoringPoint(string $pointId): DataResponse {
}


/**
* @PublicPage
* @NoCSRFRequired
*
* @param string $pointId
*
* @return DataResponse
*/
public function partRestoringPoint(string $pointId): DataResponse {
}


/**
* @PublicPage
Expand Down

0 comments on commit 92289a4

Please sign in to comment.