This repository was archived by the owner on Jul 26, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBackupZip.php
More file actions
68 lines (61 loc) · 1.91 KB
/
Copy pathBackupZip.php
File metadata and controls
68 lines (61 loc) · 1.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php declare(strict_types=1);
namespace Cli\Services;
use ZipArchive;
class BackupZip
{
protected ZipArchive $zip;
public function __construct(
protected string $filePath
) {
$this->zip = new ZipArchive();
$status = $this->zip->open($this->filePath);
if (!file_exists($this->filePath) || $status !== true) {
throw new \Exception("Could not open file [{$this->filePath}] as ZIP");
}
}
/**
* @return array<string, array{desc: string, exists: bool}>
*/
public function getContentsOverview(): array
{
return [
'env' => [
'desc' => '.env Config File',
'exists' => boolval($this->zip->statName('.env')),
],
'themes' => [
'desc' => 'Themes Folder',
'exists' => $this->hasFolder('themes/'),
],
'public/uploads' => [
'desc' => 'Public File Uploads',
'exists' => $this->hasFolder('public/uploads/'),
],
'storage/uploads' => [
'desc' => 'Private File Uploads',
'exists' => $this->hasFolder('storage/uploads/'),
],
'db' => [
'desc' => 'Database Dump',
'exists' => boolval($this->zip->statName('db.sql')),
],
];
}
public function extractInto(string $directoryPath): void
{
$result = $this->zip->extractTo($directoryPath);
if (!$result) {
throw new \Exception("Failed extraction of ZIP into [{$directoryPath}].");
}
}
protected function hasFolder($folderPath): bool
{
for ($i = 0; $i < $this->zip->numFiles; $i++) {
$filePath = $this->zip->getNameIndex($i);
if (str_starts_with($filePath, $folderPath)) {
return true;
}
}
return false;
}
}