Skip to content

Commit aad7d18

Browse files
committed
setting up custom data pack.
Signed-off-by: Maxence Lange <maxence@artificial-owl.com>
1 parent 7dca704 commit aad7d18

9 files changed

+453
-8
lines changed

lib/Command/DataAdd.php

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
6+
/**
7+
* Nextcloud - Backup now. Restore later.
8+
*
9+
* This file is licensed under the Affero General Public License version 3 or
10+
* later. See the COPYING file.
11+
*
12+
* @author Maxence Lange <maxence@artificial-owl.com>
13+
* @copyright 2021, Maxence Lange <maxence@artificial-owl.com>
14+
* @license GNU AGPL version 3 or any later version
15+
*
16+
* This program is free software: you can redistribute it and/or modify
17+
* it under the terms of the GNU Affero General Public License as
18+
* published by the Free Software Foundation, either version 3 of the
19+
* License, or (at your option) any later version.
20+
*
21+
* This program is distributed in the hope that it will be useful,
22+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
23+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24+
* GNU Affero General Public License for more details.
25+
*
26+
* You should have received a copy of the GNU Affero General Public License
27+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
28+
*
29+
*/
30+
31+
32+
namespace OCA\Backup\Command;
33+
34+
use OC\Core\Command\Base;
35+
use Symfony\Component\Console\Input\InputInterface;
36+
use Symfony\Component\Console\Output\OutputInterface;
37+
38+
/**
39+
* Class DataAdd
40+
*
41+
* @package OCA\Backup\Command
42+
*/
43+
class DataAdd extends Base {
44+
45+
46+
/**
47+
* DataAdd constructor.
48+
*/
49+
public function __construct() {
50+
parent::__construct();
51+
}
52+
53+
54+
/**
55+
*
56+
*/
57+
protected function configure() {
58+
$this->setName('backup:data:add')
59+
->setDescription('Add a new data pack to your backups');
60+
}
61+
62+
63+
/**
64+
* @param InputInterface $input
65+
* @param OutputInterface $output
66+
*
67+
* @return int
68+
*/
69+
protected function execute(InputInterface $input, OutputInterface $output): int {
70+
return 0;
71+
}
72+
73+
}

lib/Command/DataList.php

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
6+
/**
7+
* Nextcloud - Backup now. Restore later.
8+
*
9+
* This file is licensed under the Affero General Public License version 3 or
10+
* later. See the COPYING file.
11+
*
12+
* @author Maxence Lange <maxence@artificial-owl.com>
13+
* @copyright 2021, Maxence Lange <maxence@artificial-owl.com>
14+
* @license GNU AGPL version 3 or any later version
15+
*
16+
* This program is free software: you can redistribute it and/or modify
17+
* it under the terms of the GNU Affero General Public License as
18+
* published by the Free Software Foundation, either version 3 of the
19+
* License, or (at your option) any later version.
20+
*
21+
* This program is distributed in the hope that it will be useful,
22+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
23+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24+
* GNU Affero General Public License for more details.
25+
*
26+
* You should have received a copy of the GNU Affero General Public License
27+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
28+
*
29+
*/
30+
31+
32+
namespace OCA\Backup\Command;
33+
34+
use Exception;
35+
use OC\Core\Command\Base;
36+
use OCA\Backup\Service\ExternalFolderService;
37+
use Symfony\Component\Console\Helper\Table;
38+
use Symfony\Component\Console\Input\InputInterface;
39+
use Symfony\Component\Console\Output\ConsoleOutput;
40+
use Symfony\Component\Console\Output\OutputInterface;
41+
42+
/**
43+
* Class DataList
44+
*
45+
* @package OCA\Backup\Command
46+
*/
47+
class DataList extends Base {
48+
49+
50+
51+
/**
52+
* DataList constructor.
53+
*/
54+
public function __construct() {
55+
parent::__construct();
56+
}
57+
58+
59+
/**
60+
*
61+
*/
62+
protected function configure() {
63+
$this->setName('backup:data:list')
64+
->setDescription('Listing configured data pack');
65+
}
66+
67+
68+
/**
69+
* @param InputInterface $input
70+
* @param OutputInterface $output
71+
*
72+
* @return int
73+
*/
74+
protected function execute(InputInterface $input, OutputInterface $output): int {
75+
$output = new ConsoleOutput();
76+
$output = $output->section();
77+
$table = new Table($output);
78+
$table->setHeaders(['StorageId', 'Path', 'Storage Folder']);
79+
$table->render();
80+
81+
// foreach ($this->externalFolderService->getAll() as $externalFolder) {
82+
// $table->appendRow(
83+
// [
84+
// $externalFolder->getStorageId(),
85+
// $storagePath,
86+
// $externalFolder->getRoot()
87+
// ]
88+
// );
89+
// }
90+
91+
return 0;
92+
}
93+
}

lib/Command/DataRemove.php

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
6+
/**
7+
* Nextcloud - Backup now. Restore later.
8+
*
9+
* This file is licensed under the Affero General Public License version 3 or
10+
* later. See the COPYING file.
11+
*
12+
* @author Maxence Lange <maxence@artificial-owl.com>
13+
* @copyright 2021, Maxence Lange <maxence@artificial-owl.com>
14+
* @license GNU AGPL version 3 or any later version
15+
*
16+
* This program is free software: you can redistribute it and/or modify
17+
* it under the terms of the GNU Affero General Public License as
18+
* published by the Free Software Foundation, either version 3 of the
19+
* License, or (at your option) any later version.
20+
*
21+
* This program is distributed in the hope that it will be useful,
22+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
23+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24+
* GNU Affero General Public License for more details.
25+
*
26+
* You should have received a copy of the GNU Affero General Public License
27+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
28+
*
29+
*/
30+
31+
32+
namespace OCA\Backup\Command;
33+
34+
use OC\Core\Command\Base;
35+
use OCA\Backup\Exceptions\ExternalFolderNotFoundException;
36+
use Symfony\Component\Console\Input\InputArgument;
37+
use Symfony\Component\Console\Input\InputInterface;
38+
use Symfony\Component\Console\Output\OutputInterface;
39+
40+
/**
41+
* Class DataRemove
42+
*
43+
* @package OCA\Backup\Command
44+
*/
45+
class DataRemove extends Base {
46+
47+
48+
/**
49+
* DataRemove constructor.
50+
*/
51+
public function __construct() {
52+
parent::__construct();
53+
}
54+
55+
56+
/**
57+
*
58+
*/
59+
protected function configure() {
60+
$this->setName('backup:data:remove')
61+
->setDescription('Removing data pack')
62+
->addArgument('storage_id', InputArgument::REQUIRED, 'storageId');
63+
}
64+
65+
66+
/**
67+
* @param InputInterface $input
68+
* @param OutputInterface $output
69+
*
70+
* @return int
71+
* @throws ExternalFolderNotFoundException
72+
*/
73+
protected function execute(InputInterface $input, OutputInterface $output): int {
74+
// $storageId = (int)$input->getArgument('storage_id');
75+
76+
// try {
77+
// $this->restoringDataRequest->getByStorageId($storageId);
78+
// } catch (ExternalFolderNotFoundException $e) {
79+
// throw new ExternalFolderNotFoundException('Unknown external folder');
80+
// }
81+
//
82+
// $this->externalFolderRequest->remove($storageId);
83+
// $output->writeln('external filesystem removed.');
84+
//
85+
return 0;
86+
}
87+
}

lib/Db/CoreRequestBuilder.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class CoreRequestBuilder {
4848
public const TABLE_REMOTE = 'backup_remote';
4949
public const TABLE_EXTERNAL = 'backup_external';
5050
public const TABLE_EVENT = 'backup_event';
51+
public const TABLE_DATA = 'backup_data';
5152

5253
public const TABLE_AUTHTOKEN = 'authtoken';
5354

@@ -91,6 +92,13 @@ class CoreRequestBuilder {
9192
'status',
9293
'data',
9394
'result'
95+
],
96+
self::TABLE_DATA => [
97+
'id',
98+
'name',
99+
'type',
100+
'root',
101+
'path'
94102
]
95103
];
96104

lib/Db/RestoringDataRequest.php

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
6+
/**
7+
* Nextcloud - Backup now. Restore later.
8+
*
9+
* This file is licensed under the Affero General Public License version 3 or
10+
* later. See the COPYING file.
11+
*
12+
* @author Maxence Lange <maxence@artificial-owl.com>
13+
* @copyright 2021, Maxence Lange <maxence@artificial-owl.com>
14+
* @license GNU AGPL version 3 or any later version
15+
*
16+
* This program is free software: you can redistribute it and/or modify
17+
* it under the terms of the GNU Affero General Public License as
18+
* published by the Free Software Foundation, either version 3 of the
19+
* License, or (at your option) any later version.
20+
*
21+
* This program is distributed in the hope that it will be useful,
22+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
23+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24+
* GNU Affero General Public License for more details.
25+
*
26+
* You should have received a copy of the GNU Affero General Public License
27+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
28+
*
29+
*/
30+
31+
32+
namespace OCA\Backup\Db;
33+
34+
35+
use OCA\Backup\Model\RestoringData;
36+
37+
/**
38+
* Class RestoringDataRequest
39+
*
40+
* @package OCA\Backup\Db
41+
*/
42+
class RestoringDataRequest extends RestoringDataRequestBuilder {
43+
44+
45+
public function save(RestoringData $data): void {
46+
$qb = $this->getRestoringDataInsertSql();
47+
48+
$qb->setValue('name', $qb->createNamedParameter($data->getName()))
49+
->setValue('type', $qb->createNamedParameter($data->getType()))
50+
->setValue('root', $qb->createNamedParameter($data->getRoot()))
51+
->setValue('path', $qb->createNamedParameter($data->getPath()));
52+
// ->setValue('static', $qb->createNamedParameter(($data->isStatic() ? '1' : '0')));
53+
$qb->execute();
54+
}
55+
56+
57+
/**
58+
* @return RestoringData[]
59+
*/
60+
public function getAll(): array {
61+
$qb = $this->getRestoringDataSelectSql();
62+
63+
return $this->getItemsFromRequest($qb);
64+
}
65+
}

0 commit comments

Comments
 (0)