PluginProbe ʕ •ᴥ•ʔ
Backup Migration / 1.3.5
Backup Migration v1.3.5
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 / progress / zip.php
backup-backup / includes / progress Last commit date
logger-only.php 2 years ago migration.php 2 years ago staging.php 2 years ago zip.php 2 years ago
zip.php
164 lines
1 <?php
2
3 // Namespace
4 namespace BMI\Plugin\Progress;
5
6 // Use
7 use BMI\Plugin\BMI_Logger AS Logger;
8
9 // Exit on direct access
10 if (!defined('ABSPATH')) exit;
11
12 /**
13 * Main File Backup Logs
14 */
15 class BMI_ZipProgress {
16
17 public $name;
18 public $date;
19 public $millis;
20 public $cron;
21 public $logfilename;
22 public $latest;
23 public $latest_progress;
24 public $files;
25 public $bytes;
26 public $total_queries;
27 public $file;
28 public $progress;
29 public $muted = false;
30 public $clearEndCodes = false;
31
32 public function __construct($backup_name, $files = 0, $bytes = 0, $cron = false, $reset = true, $clearEndCodes = false) {
33
34 if (!file_exists(BMI_BACKUPS)) mkdir(BMI_BACKUPS, 0755, true);
35
36 $this->name = $backup_name;
37 $this->date = date('Y-m-d H:i:s');
38 $this->millis = microtime(true);
39 $this->cron = $cron;
40 $this->logfilename = substr($backup_name, 0, -4) . '.log';
41 $this->latest = BMI_BACKUPS . '/latest.log';
42 $this->latest_progress = BMI_BACKUPS . '/latest_progress.log';
43 $this->files = $files;
44 $this->bytes = $bytes;
45 $this->total_queries = 1;
46 $this->clearEndCodes = $clearEndCodes;
47
48 if ($reset == true) {
49 if (file_exists($this->latest)) @unlink($this->latest);
50 if (file_exists($this->latest_progress)) @unlink($this->latest_progress);
51 file_put_contents($this->latest_progress, '0/100');
52 }
53
54 if ($this->clearEndCodes) {
55 $this->removeAllEndCodes();
56 }
57
58 }
59
60 public function createManifest($dbBackupEngine = 'v4') {
61
62 global $table_prefix;
63
64 $manifest = array(
65 'name' => $this->name,
66 'date' => $this->date,
67 'files' => $this->files,
68 'bytes' => $this->bytes,
69 'cron' => $this->cron,
70 'total_queries' => $this->total_queries,
71 'manifest' => date('Y-m-d H:i:s'),
72 'millis_start' => $this->millis,
73 'millis_end' => microtime(true),
74 'version' => (defined('BMI_VERSION') ? BMI_VERSION : ''),
75 'domain' => parse_url(home_url())['host'],
76 'dbdomain' => get_option('siteurl'),
77 'uid' => get_current_user_id(),
78 'source_query_output' => (defined('BMI_DB_MAX_ROWS_PER_QUERY') ? BMI_DB_MAX_ROWS_PER_QUERY : ''),
79 'db_backup_engine' => $dbBackupEngine,
80 'config' => array(
81 'ABSPATH' => ABSPATH,
82 'DB_NAME' => (defined('DB_NAME') ? DB_NAME : ''),
83 'DB_USER' => (defined('DB_USER') ? DB_USER : ''),
84 'DB_PASSWORD' => (defined('DB_PASSWORD') ? DB_PASSWORD : ''),
85 'DB_HOST' => (defined('DB_HOST') ? DB_HOST : ''),
86 'DB_CHARSET' => (defined('DB_CHARSET') ? DB_CHARSET : ''),
87 'DB_COLLATE' => (defined('DB_COLLATE') ? DB_COLLATE : ''),
88 'AUTH_KEY' => (defined('AUTH_KEY') ? AUTH_KEY : ''),
89 'SECURE_AUTH_KEY' => (defined('SECURE_AUTH_KEY') ? SECURE_AUTH_KEY : ''),
90 'LOGGED_IN_KEY' => (defined('LOGGED_IN_KEY') ? LOGGED_IN_KEY : ''),
91 'NONCE_KEY' => (defined('NONCE_KEY') ? NONCE_KEY : ''),
92 'AUTH_SALT' => (defined('AUTH_SALT') ? AUTH_SALT : ''),
93 'SECURE_AUTH_SALT' => (defined('SECURE_AUTH_SALT') ? SECURE_AUTH_SALT : ''),
94 'LOGGED_IN_SALT' => (defined('LOGGED_IN_SALT') ? LOGGED_IN_SALT : ''),
95 'NONCE_SALT' => (defined('NONCE_SALT') ? NONCE_SALT : ''),
96 'WP_DEBUG_LOG' => (defined('WP_DEBUG_LOG') ? WP_DEBUG_LOG : ''),
97 'WP_CONTENT_URL' => (defined('WP_CONTENT_URL') ? WP_CONTENT_URL : ''),
98 'WP_CONTENT_DIR' => (defined('WP_CONTENT_DIR') ? trailingslashit(WP_CONTENT_DIR) : ''),
99 'table_prefix' => $table_prefix
100 )
101 );
102
103 return json_encode($manifest);
104
105 }
106
107 public function start($muted = false) {
108
109 $this->muted = $muted;
110
111 }
112
113 public function log($log = '', $level = 'INFO') {
114
115 if (!$this->muted) {
116 $this->file = fopen($this->latest, 'a');
117 if (defined('BMI_USING_CLI_FUNCTIONALITY') && BMI_USING_CLI_FUNCTIONALITY === true) {
118 $log_string = '[' . strtoupper($level) . '] [' . date('Y-m-d H:i:s') . '] [CLI] ' . $log . "\n";
119 } else {
120 $log_string = '[' . strtoupper($level) . '] [' . date('Y-m-d H:i:s') . '] ' . $log . "\n";
121 }
122 fwrite($this->file, $log_string);
123 fclose($this->file);
124 if (defined('BMI_USING_CLI_FUNCTIONALITY') && BMI_USING_CLI_FUNCTIONALITY === true) {
125 echo $log_string;
126 }
127 }
128
129 }
130
131 public function progress($progress = '0') {
132
133 $this->progress = fopen($this->latest_progress, 'w') or die(__("Unable to open file!", 'backup-backup'));
134 fwrite($this->progress, $progress);
135 fclose($this->progress);
136
137 }
138
139 public function removeAllEndCodes() {
140
141 $logs = file_get_contents($this->latest);
142 $logs = explode("\n", $logs);
143
144 foreach ($logs as $line => $string) {
145 if (strpos($string, '[END-CODE]') !== false) {
146 $code = substr($string, 10);
147 $logs[$line] = "[VERBOSE] Logs from there starts as new process, it was continued by smart solution system after applying new plugin settings. (" . $code . ")";
148 }
149 }
150
151 $logs = implode("\n", $logs);
152 file_put_contents($this->latest, $logs);
153 file_put_contents($this->latest_progress, '0/100');
154
155 }
156
157 public function end() {
158
159 // fclose($this->file);
160
161 }
162
163 }
164