PluginProbe ʕ •ᴥ•ʔ
Backup Migration / 1.3.2
Backup Migration v1.3.2
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
140 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
31 public function __construct($backup_name, $files = 0, $bytes = 0, $cron = false, $reset = true) {
32
33 if (!file_exists(BMI_BACKUPS)) mkdir(BMI_BACKUPS, 0755, true);
34
35 $this->name = $backup_name;
36 $this->date = date('Y-m-d H:i:s');
37 $this->millis = microtime(true);
38 $this->cron = $cron;
39 $this->logfilename = substr($backup_name, 0, -4) . '.log';
40 $this->latest = BMI_BACKUPS . '/latest.log';
41 $this->latest_progress = BMI_BACKUPS . '/latest_progress.log';
42 $this->files = $files;
43 $this->bytes = $bytes;
44 $this->total_queries = 1;
45
46 if ($reset == true) {
47 if (file_exists($this->latest)) @unlink($this->latest);
48 if (file_exists($this->latest_progress)) @unlink($this->latest_progress);
49 file_put_contents($this->latest_progress, '0/100');
50 }
51
52 }
53
54 public function createManifest($dbBackupEngine = 'v4') {
55
56 global $table_prefix;
57
58 $manifest = array(
59 'name' => $this->name,
60 'date' => $this->date,
61 'files' => $this->files,
62 'bytes' => $this->bytes,
63 'cron' => $this->cron,
64 'total_queries' => $this->total_queries,
65 'manifest' => date('Y-m-d H:i:s'),
66 'millis_start' => $this->millis,
67 'millis_end' => microtime(true),
68 'version' => (defined('BMI_VERSION') ? BMI_VERSION : ''),
69 'domain' => parse_url(home_url())['host'],
70 'dbdomain' => get_option('siteurl'),
71 'uid' => get_current_user_id(),
72 'source_query_output' => (defined('BMI_DB_MAX_ROWS_PER_QUERY') ? BMI_DB_MAX_ROWS_PER_QUERY : ''),
73 'db_backup_engine' => $dbBackupEngine,
74 'config' => array(
75 'ABSPATH' => ABSPATH,
76 'DB_NAME' => (defined('DB_NAME') ? DB_NAME : ''),
77 'DB_USER' => (defined('DB_USER') ? DB_USER : ''),
78 'DB_PASSWORD' => (defined('DB_PASSWORD') ? DB_PASSWORD : ''),
79 'DB_HOST' => (defined('DB_HOST') ? DB_HOST : ''),
80 'DB_CHARSET' => (defined('DB_CHARSET') ? DB_CHARSET : ''),
81 'DB_COLLATE' => (defined('DB_COLLATE') ? DB_COLLATE : ''),
82 'AUTH_KEY' => (defined('AUTH_KEY') ? AUTH_KEY : ''),
83 'SECURE_AUTH_KEY' => (defined('SECURE_AUTH_KEY') ? SECURE_AUTH_KEY : ''),
84 'LOGGED_IN_KEY' => (defined('LOGGED_IN_KEY') ? LOGGED_IN_KEY : ''),
85 'NONCE_KEY' => (defined('NONCE_KEY') ? NONCE_KEY : ''),
86 'AUTH_SALT' => (defined('AUTH_SALT') ? AUTH_SALT : ''),
87 'SECURE_AUTH_SALT' => (defined('SECURE_AUTH_SALT') ? SECURE_AUTH_SALT : ''),
88 'LOGGED_IN_SALT' => (defined('LOGGED_IN_SALT') ? LOGGED_IN_SALT : ''),
89 'NONCE_SALT' => (defined('NONCE_SALT') ? NONCE_SALT : ''),
90 'WP_DEBUG_LOG' => (defined('WP_DEBUG_LOG') ? WP_DEBUG_LOG : ''),
91 'WP_CONTENT_URL' => (defined('WP_CONTENT_URL') ? WP_CONTENT_URL : ''),
92 'WP_CONTENT_DIR' => (defined('WP_CONTENT_DIR') ? trailingslashit(WP_CONTENT_DIR) : ''),
93 'table_prefix' => $table_prefix
94 )
95 );
96
97 return json_encode($manifest);
98
99 }
100
101 public function start($muted = false) {
102
103 $this->muted = $muted;
104
105 }
106
107 public function log($log = '', $level = 'INFO') {
108
109 if (!$this->muted) {
110 $this->file = fopen($this->latest, 'a');
111 if (defined('BMI_USING_CLI_FUNCTIONALITY') && BMI_USING_CLI_FUNCTIONALITY === true) {
112 $log_string = '[' . strtoupper($level) . '] [' . date('Y-m-d H:i:s') . '] [CLI] ' . $log . "\n";
113 } else {
114 $log_string = '[' . strtoupper($level) . '] [' . date('Y-m-d H:i:s') . '] ' . $log . "\n";
115 }
116 fwrite($this->file, $log_string);
117 fclose($this->file);
118 if (defined('BMI_USING_CLI_FUNCTIONALITY') && BMI_USING_CLI_FUNCTIONALITY === true) {
119 echo $log_string;
120 }
121 }
122
123 }
124
125 public function progress($progress = '0') {
126
127 $this->progress = fopen($this->latest_progress, 'w') or die(__("Unable to open file!", 'backup-backup'));
128 fwrite($this->progress, $progress);
129 fclose($this->progress);
130
131 }
132
133 public function end() {
134
135 // fclose($this->file);
136
137 }
138
139 }
140