Skip to content

Commit 9834cb9

Browse files
committed
better health managment, lock RP
1 parent e2f1a21 commit 9834cb9

12 files changed

+219
-79
lines changed

lib/Command/PointDownload.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
207207

208208
$output->write('check health status: ');
209209
$this->pointService->generateHealth($point);
210-
$output->writeln($this->outputService->displayHealth($point));
210+
$output->writeln($this->outputService->displayHealth($point->getHealth()));
211211
$this->downloadMissingFiles($output, $remote, $external, $point);
212212

213213
return 0;

lib/Command/PointRestore.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
192192
$output->write('Checking Health status: ');
193193
$this->pointService->generateHealth($point);
194194

195-
$output->writeln($this->outputService->displayHealth($point));
195+
$output->writeln($this->outputService->displayHealth($point->getHealth()));
196196
$output->writeln('');
197197

198198
$healthStatus = $point->getHealth()->getStatus();

lib/Command/PointUnpack.php

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,18 @@
3232
namespace OCA\Backup\Command;
3333

3434

35+
use ArtificialOwl\MySmallPhpTools\Exceptions\SignatoryException;
3536
use OC\Core\Command\Base;
3637
use OCA\Backup\Exceptions\RestoringPointNotFoundException;
3738
use OCA\Backup\Service\PackService;
3839
use OCA\Backup\Service\PointService;
40+
use OCA\Backup\Service\RemoteStreamService;
3941
use OCP\Files\NotFoundException;
4042
use OCP\Files\NotPermittedException;
4143
use Symfony\Component\Console\Input\InputArgument;
4244
use Symfony\Component\Console\Input\InputInterface;
4345
use Symfony\Component\Console\Output\OutputInterface;
46+
use Throwable;
4447

4548

4649
/**
@@ -57,18 +60,27 @@ class PointUnpack extends Base {
5760
/** @var PackService */
5861
private $packService;
5962

63+
/** @var RemoteStreamService */
64+
private $remoteStreamService;
65+
6066

6167
/**
6268
* PointUnpack constructor.
6369
*
6470
* @param PointService $pointService
6571
* @param PackService $packService
72+
* @param RemoteStreamService $remoteStreamService
6673
*/
67-
public function __construct(PointService $pointService, PackService $packService) {
74+
public function __construct(
75+
PointService $pointService,
76+
PackService $packService,
77+
RemoteStreamService $remoteStreamService
78+
) {
6879
parent::__construct();
6980

7081
$this->pointService = $pointService;
7182
$this->packService = $packService;
83+
$this->remoteStreamService = $remoteStreamService;
7284
}
7385

7486

@@ -89,16 +101,25 @@ protected function configure() {
89101
* @param OutputInterface $output
90102
*
91103
* @return int
92-
* @throws RestoringPointNotFoundException
93104
* @throws NotFoundException
94105
* @throws NotPermittedException
106+
* @throws RestoringPointNotFoundException
107+
* @throws SignatoryException
108+
* @throws Throwable
95109
*/
96110
protected function execute(InputInterface $input, OutputInterface $output): int {
97111
$point = $this->pointService->getLocalRestoringPoint($input->getArgument('pointId'));
98112

99113
$this->pointService->initBaseFolder($point);
100114
$this->packService->unpackPoint($point);
101115

116+
117+
// set Archive flag up after unpack
118+
$point->setArchive(true);
119+
120+
$this->remoteStreamService->subSignPoint($point);
121+
$this->pointService->updateSubInfos($point);
122+
102123
return 0;
103124
}
104125

lib/Db/CoreRequestBuilder.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ class CoreRequestBuilder {
7878
'id',
7979
'uid',
8080
'archive',
81+
'lock',
8182
'instance',
8283
'parent',
8384
'status',

lib/Db/PointRequest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ public function save(RestoringPoint $point): int {
5656
->setValue('parent', $qb->createNamedParameter($point->getParent()))
5757
->setValue('status', $qb->createNamedParameter($point->getStatus()))
5858
->setValue('archive', $qb->createNamedParameter(($point->isArchive()) ? 1 : 0))
59+
->setValue('lock', $qb->createNamedParameter($point->getLock()))
5960
->setValue('notes', $qb->createNamedParameter(json_encode($point->getNotes())))
6061
->setValue('metadata', $qb->createNamedParameter(json_encode($point->getMetadata())))
6162
->setValue('date', $qb->createNamedParameter($point->getDate()));

lib/Migration/Version0023Date20210907122531.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,18 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
116116
);
117117
$table->addColumn(
118118
'archive', 'integer', [
119+
'unsigned' => true,
119120
'notnull' => true,
120121
'length' => 1,
121122
]
122123
);
124+
$table->addColumn(
125+
'lock', 'integer', [
126+
'notnull' => true,
127+
'unsigned' => true,
128+
'length' => 11,
129+
]
130+
);
123131
$table->addColumn(
124132
'instance', 'string', [
125133
'notnull' => true,
@@ -141,8 +149,8 @@ public function changeSchema(IOutput $output, Closure $schemaClosure, array $opt
141149
);
142150
$table->addColumn(
143151
'notes', 'text', [
144-
'notnull' => true
145-
]
152+
'notnull' => true
153+
]
146154
);
147155
$table->addColumn(
148156
'metadata', 'text', [

lib/Model/RestoringPoint.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,9 @@ class RestoringPoint implements IDeserializable, INC23QueryRow, ISignedModel, Js
104104
/** @var bool */
105105
private $archive = false;
106106

107+
/** @var int */
108+
private $lock = 0;
109+
107110
/** @var ISimpleFolder */
108111
private $baseFolder = null;
109112

@@ -280,6 +283,32 @@ public function isArchive(): bool {
280283
}
281284

282285

286+
/**
287+
* @param int $lock
288+
*
289+
* @return RestoringPoint
290+
*/
291+
public function setLock(int $lock): self {
292+
$this->lock = $lock;
293+
294+
return $this;
295+
}
296+
297+
/**
298+
* @return int
299+
*/
300+
public function getLock(): int {
301+
return $this->lock;
302+
}
303+
304+
/**
305+
* @return bool
306+
*/
307+
public function isLock(): bool {
308+
return ($this->lock > 0);
309+
}
310+
311+
283312
/**
284313
* @param SimpleDataStore $notes
285314
*
@@ -603,6 +632,7 @@ public function importFromDatabase(array $data): INC23QueryRow {
603632
->setInstance($this->get('instance', $data))
604633
->setParent($this->get('parent', $data))
605634
->setArchive($this->getBool('archive', $data))
635+
->setLock($this->getInt('lock', $data))
606636
->setStatus($this->getInt('status', $data))
607637
->setNotes(new SimpleDataStore($this->getArray('notes', $data)))
608638
->setDate($this->getInt('date', $data));

lib/Service/ConfigService.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@
3535
use ArtificialOwl\MySmallPhpTools\Model\Nextcloud\nc23\NC23Request;
3636
use ArtificialOwl\MySmallPhpTools\Model\SimpleDataStore;
3737
use ArtificialOwl\MySmallPhpTools\Traits\TArrayTools;
38+
use Exception;
39+
use OC;
3840
use OCA\Backup\AppInfo\Application;
41+
use OCA\Files_External\Service\GlobalStoragesService;
3942
use OCP\IConfig;
4043

4144

@@ -105,6 +108,9 @@ class ConfigService {
105108
/** @var IConfig */
106109
private $config;
107110

111+
/** @var int */
112+
private $externalEnabled = -1;
113+
108114

109115
/**
110116
* ConfigService constructor.
@@ -272,10 +278,31 @@ public function getTempFileName(): string {
272278
}
273279

274280

281+
/**
282+
* @return bool
283+
*/
275284
public function isRemoteEnabled(): bool {
276285
return $this->getAppValueBool(self::REMOTE_ENABLED);
277286
}
278287

288+
289+
/**
290+
* @return bool
291+
*/
292+
public function isExternalEnabled(): bool {
293+
if ($this->externalEnabled === -1) {
294+
try {
295+
OC::$server->get(GlobalStoragesService::class);
296+
$this->externalEnabled = 0;
297+
} catch (Exception $e) {
298+
$this->externalEnabled = 1;
299+
}
300+
}
301+
302+
return ($this->externalEnabled === 1);
303+
}
304+
305+
279306
/**
280307
* @return array
281308
*/

0 commit comments

Comments
 (0)