@@ -69,7 +69,7 @@ class ArchiveService {
69
69
70
70
const MAX_ZIP_SIZE = 100000000 ;
71
71
const BACKUP_SCRIPT = 'restore.php ' ;
72
-
72
+ const APP_ZIP = ' app.zip ' ;
73
73
74
74
/** @var FilesService */
75
75
private $ filesService ;
@@ -105,7 +105,11 @@ public function __construct(
105
105
* @throws ArchiveNotFoundException
106
106
*/
107
107
public function createChunks (RestoringPoint $ point ): void {
108
- foreach ($ point ->getRestoringData (false ) as $ data ) {
108
+ foreach ($ point ->getRestoringData () as $ data ) {
109
+ if ($ data ->getType () === RestoringData::INTERNAL_DATA ) {
110
+ continue ;
111
+ }
112
+
109
113
$ this ->filesService ->initRestoringData ($ data );
110
114
$ this ->filesService ->fillRestoringData ($ data , $ data ->getUniqueFile ());
111
115
@@ -226,7 +230,7 @@ public function extractContentFromZip(ZipArchive $zip, string $file) {
226
230
* @throws ArchiveNotFoundException
227
231
*/
228
232
public function verifyChecksum (Backup $ backup , RestoringChunk $ archive , bool $ encrypted ): bool {
229
- $ sum = $ this ->getChecksum ($ backup , $ archive, $ encrypted );
233
+ $ sum = $ this ->getChecksum ($ backup , $ archive );
230
234
231
235
if (!$ encrypted && $ sum === $ archive ->getChecksum ()) {
232
236
return true ;
@@ -283,7 +287,7 @@ public function createContentChunk(
283
287
284
288
$ this ->createContentZip ($ point , $ chunk , $ filename , $ content );
285
289
286
- $ this ->updateChecksum ($ point , $ chunk, false );
290
+ $ this ->updateChecksum ($ point , $ chunk );
287
291
// $this->encryptArchive($backup, $archive, true);
288
292
// $this->updateChecksum($backup, $archive, true);
289
293
}
@@ -398,17 +402,12 @@ public function finalizeZip(ZipStreamer $zip, RestoringChunk $archive): void {
398
402
/**
399
403
* @param RestoringPoint $point
400
404
* @param RestoringChunk $chunk
401
- * @param bool $encrypted
402
405
*
403
406
* @throws ArchiveNotFoundException
404
407
*/
405
- private function updateChecksum (
406
- RestoringPoint $ point ,
407
- RestoringChunk $ chunk ,
408
- bool $ encrypted
409
- ): void {
410
- $ sum = $ this ->getChecksum ($ point , $ chunk , $ encrypted );
411
- if ($ encrypted ) {
408
+ private function updateChecksum (RestoringPoint $ point , RestoringChunk $ chunk ): void {
409
+ $ sum = $ this ->getChecksum ($ point , $ chunk );
410
+ if ($ chunk ->isEncrypted ()) {
412
411
$ chunk ->setEncryptedChecksum ($ sum );
413
412
} else {
414
413
$ chunk ->setChecksum ($ sum );
@@ -419,33 +418,28 @@ private function updateChecksum(
419
418
/**
420
419
* @param RestoringPoint $point
421
420
* @param RestoringChunk $chunk
422
- * @param bool $encrypted
423
421
*
424
422
* @return string
425
423
* @throws ArchiveNotFoundException
426
424
*/
427
- public function getChecksum (
428
- RestoringPoint $ point ,
429
- RestoringChunk $ chunk ,
430
- bool $ encrypted
431
- ): string {
425
+ public function getChecksum (RestoringPoint $ point , RestoringChunk $ chunk ): string {
432
426
try {
433
427
if ($ point ->isPackage ()) {
434
- if (!file_exists ('./ ' . $ chunk ->getName (( $ encrypted ) ? '' : ' zip ' ))) {
428
+ if (!file_exists ('./ ' . $ chunk ->getFilename ( ))) {
435
429
throw new ArchiveNotFoundException ('Archive not found ' );
436
430
}
437
- $ stream = fopen ('./ ' . $ chunk ->getName (( $ encrypted ) ? '' : ' zip ' ), 'r ' );
431
+ $ stream = fopen ('./ ' . $ chunk ->getFilename ( ), 'r ' );
438
432
} else {
439
433
$ folder = $ point ->getBaseFolder ();
440
- $ file = $ folder ->getFile ($ chunk ->getName (( $ encrypted ) ? '' : ' zip ' ));
434
+ $ file = $ folder ->getFile ($ chunk ->getFilename ( ));
441
435
$ stream = $ file ->read ();
442
436
}
443
437
} catch (Exception $ e ) {
444
- throw new ArchiveNotFoundException ('Chunk not found ' );
438
+ throw new ArchiveNotFoundException ('Chunk ' . $ chunk -> getFilename () . ' not found ' );
445
439
}
446
440
447
441
if (is_bool ($ stream )) {
448
- throw new ArchiveNotFoundException ('Chunk not found ' );
442
+ throw new ArchiveNotFoundException ('Chunk ' . $ chunk -> getFilename () . ' not valid ' );
449
443
}
450
444
451
445
return $ this ->getChecksumFromStream ($ stream );
@@ -556,11 +550,12 @@ public function decryptArchive(Backup $backup, RestoringChunk $archive) {
556
550
*
557
551
* @throws BackupAppCopyException
558
552
* @throws BackupScriptNotFoundException
553
+ * @throws ArchiveNotFoundException
559
554
*/
560
555
public function copyApp (RestoringPoint $ point ): void {
561
556
$ folder = $ point ->getBaseFolder ();
562
557
try {
563
- $ file = $ folder ->newFile (' app.zip ' );
558
+ $ file = $ folder ->newFile (self :: APP_ZIP );
564
559
$ zip = new ZipStreamer (
565
560
[
566
561
'outstream ' => $ file ->write (),
@@ -569,9 +564,8 @@ public function copyApp(RestoringPoint $point): void {
569
564
'level ' => $ this ->assignCompressionLevel ()
570
565
]
571
566
);
572
-
573
567
} catch (Exception $ e ) {
574
- throw new BackupAppCopyException ('Could not generate app.zip ' );
568
+ throw new BackupAppCopyException ('Could not generate ' . self :: APP_ZIP );
575
569
}
576
570
577
571
$ appFiles = $ this ->filesService ->getFilesFromApp ();
@@ -596,6 +590,30 @@ public function copyApp(RestoringPoint $point): void {
596
590
}
597
591
598
592
593
+ /**
594
+ * @param RestoringPoint $point
595
+ *
596
+ * @throws ArchiveNotFoundException
597
+ */
598
+ public function generateInternalData (RestoringPoint $ point ): void {
599
+ $ data = new RestoringData (
600
+ RestoringData::INTERNAL_DATA ,
601
+ '' ,
602
+ RestoringData::INTERNAL
603
+ );
604
+
605
+ $ chunk = new RestoringChunk (self ::APP_ZIP );
606
+ $ this ->updateChecksum ($ point , $ chunk );
607
+ $ data ->addChunk ($ chunk );
608
+
609
+ $ chunk = new RestoringChunk (self ::BACKUP_SCRIPT );
610
+ $ this ->updateChecksum ($ point , $ chunk );
611
+ $ data ->addChunk ($ chunk );
612
+
613
+ $ point ->addRestoringData ($ data );
614
+ }
615
+
616
+
599
617
/**
600
618
* @return int
601
619
*/
0 commit comments