PluginProbe ʕ •ᴥ•ʔ
Backup Migration / 1.4.9
Backup Migration v1.4.9
2.1.6 2.1.5.2 trunk 1.3.0 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.4.5 1.4.6 1.4.6.1 1.4.7 1.4.8 1.4.9 1.4.9.1 2.0.0 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.5.1
backup-backup / includes / external / controller.php
backup-backup / includes / external Last commit date
backupbliss.php 11 months ago controller.php 11 months ago
controller.php
147 lines
1 <?php
2
3 // Namespace
4 namespace BMI\Plugin\External;
5
6 // Use
7 use BMI\Plugin\BMI_Logger as Logger;
8 use BMI\Plugin\External\BMI_External_BackupBliss as BackupBliss;
9 use BMI\Plugin\Dashboard as Dashboard;
10 use BMI\Plugin\External\BMI_External_Storage_Premium as ExternalStoragePremium;
11
12 // Exit on direct access
13 if (!defined('ABSPATH')) {
14 exit;
15 }
16
17 /**
18 * BMI_External_Storage
19 */
20 class BMI_External_Storage {
21
22 public $backupbliss;
23
24 public function __construct() {
25
26 require_once BMI_INCLUDES . '/external/backupbliss.php';
27 $this->backupbliss = new BackupBliss();
28
29 }
30
31 public function getExternalBackups() {
32
33 $backups = [];
34
35 // Google Drive
36 $backups['backupbliss'] = $this->getBackupBlissBackupsParsedForList();
37
38
39 if (defined('BMI_BACKUP_PRO') && defined('BMI_PRO_INC')) {
40 $proPath = BMI_PRO_INC . 'external/controller.php';
41 if (file_exists($proPath)) {
42 require_once $proPath;
43
44 $externalStorage = new ExternalStoragePremium();
45 $external = $externalStorage->getExternalBackups();
46 $backups = array_merge($backups, $external);
47 }
48 }
49
50
51 //Here we check and remove if there are any failed tasks but backups are successfully uploaded.
52
53 $toBeUploaded = get_option('bmip_to_be_uploaded', [
54 'current_upload' => [],
55 'queue' => [],
56 'failed' => []
57 ]);
58
59 if (isset($toBeUploaded['failed'])) {
60 foreach($backups as $cloudName => $cloudBackups) {
61 $cloudName = strtolower($cloudName);
62 foreach($cloudBackups as $md5 => $backupDetails) {
63 if (isset($toBeUploaded['failed'][$cloudName . "_" . $md5]))
64 unset($toBeUploaded['failed'][$cloudName . "_" . $md5]);
65 }
66 }
67
68 //Remove failed tasks if any of the cloud storages are disabled or empty
69 $failed = $toBeUploaded['failed'];
70 foreach($failed as $failed_task => $failed_count) {
71 $data = explode("_", $failed_task);
72
73
74 if (count($data) == 2) {
75 $cloudtype = $data[0];
76 $cloudtype = isset($backups[$cloudtype]) ? $cloudtype : strtoupper($cloudtype);
77 if (isset($backups[$cloudtype]) && count($backups[$cloudtype]) == 0) {
78 unset($toBeUploaded["failed"][$failed_task]); //Removes the failed task as there's no backups found or disabled.
79 }
80 }
81 }
82
83 update_option('bmip_to_be_uploaded', $toBeUploaded);
84 }
85
86
87 return $backups;
88
89 }
90
91 private function getBackupBlissBackupsParsedForList() {
92
93
94 $files = $this->backupbliss->parseFiles($this->backupbliss->getAllFiles());
95
96 $parsedBackups = [];
97
98
99 if ($files) {
100 foreach ($files['manifests'] as $manifestFileName => $filedetail) {
101
102 $localManifest = BMI_BACKUPS . DIRECTORY_SEPARATOR. $manifestFileName;
103
104 if (file_exists($localManifest)) {
105
106 $manifestData = file_get_contents($localManifest);
107 $manifest = json_decode($manifestData);
108
109 } else {
110
111 $manifestData = $this->backupbliss->getFile($manifestFileName);
112 if (is_array($manifestData) && $manifestData["file_data"]) {
113
114 file_put_contents($localManifest, $manifestData["file_data"]);
115 $manifest = json_decode($manifestData["file_data"]);
116
117 } else continue;
118
119 }
120
121 if (!isset($manifest))
122 continue;
123
124 $md5 = pathinfo($manifestFileName, PATHINFO_FILENAME);
125 $backupFileName = $manifest->name;
126
127 if (!isset($files["backups"][$backupFileName]))
128 continue;
129
130 $parsedBackups[$md5] = [];
131 $parsedBackups[$md5][] = $backupFileName;
132 $parsedBackups[$md5][] = $manifest->date;
133 $parsedBackups[$md5][] = $manifest->files;
134 $parsedBackups[$md5][] = $manifest->manifest;
135 $parsedBackups[$md5][] = $files["backups"][$backupFileName]["size"];
136 $parsedBackups[$md5][] = $manifest->is_locked;
137 $parsedBackups[$md5][] = $manifest->cron;
138 $parsedBackups[$md5][] = $md5;
139 $parsedBackups[$md5][] = $backupFileName;
140 $parsedBackups[$md5][] = sanitize_text_field($manifest->domain);
141 }
142 }
143
144 return $parsedBackups;
145 }
146 }
147