PluginProbe ʕ •ᴥ•ʔ
Backup Migration / 1.3.0
Backup Migration v1.3.0
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 / check / checker.php
backup-backup / includes / check Last commit date
checker.php 2 years ago system_info.php 2 years ago
checker.php
112 lines
1 <?php
2
3 // Namespace
4 namespace BMI\Plugin\Checker;
5
6 // Use
7 use BMI\Plugin\BMI_Logger AS Logger;
8 use BMI\Plugin\Progress\BMI_ZipProgress AS Progress;
9 use BMI\Plugin\Backup_Migration_Plugin as BMP;
10
11 // Exit on direct access
12 if (!defined('ABSPATH')) exit;
13
14 /**
15 * BMI_Checker
16 */
17 class BMI_Checker {
18
19 public $issues = array();
20 public $progress;
21
22 function __construct($progress = false) {
23
24 $this->progress = $progress;
25
26 }
27
28 public function logs($log, $status = 'INFO') {
29
30 if ($this->progress) {
31 $this->progress->log($log, $status);
32 }
33
34 }
35
36 public function is_enabled($func) {
37
38 $disabled = explode(',', ini_get('disable_functions'));
39 $isDisabled = in_array($func, $disabled);
40 if (!$isDisabled && function_exists($func)) return true;
41 else return false;
42
43 }
44
45 public function check_free_space($size, $hideRequire = false) {
46
47 if (!$hideRequire) {
48 $this->logs(__('Requires at least ', 'backup-backup') . $size . __(' bytes.', 'backup-backup') . ' [' . BMP::humanSize($size) . ']');
49 }
50
51 if ($this->is_enabled('disk_free_space') && intval(disk_free_space(BMI_BACKUPS)) > 100) {
52
53 $this->logs(__('Disk free space function is not disabled - using it...', 'backup-backup'));
54 $this->logs(__('Checking this path/partition: ', 'backup-backup') . BMI_BACKUPS);
55 $free = intval(disk_free_space(BMI_BACKUPS));
56 $this->logs(__('There is ', 'backup-backup') . number_format($free / 1024 / 1024, 2) . __(' MB free.', 'backup-backup') . ' [' . BMP::humanSize($free) . ']', 'SUCCESS');
57 if ($free > $size) {
58 $this->logs(__('Great! We have enough space.', 'backup-backup'), 'SUCCESS');
59 return true;
60 } else {
61 return false;
62 }
63
64 } else {
65
66 // Log
67 $this->logs(__('Disk free space function is disabled by hosting.', 'backup-backup'));
68 $this->logs(__('Using dummy file to check free space (it can take some time).', 'backup-backup'));
69
70 // TMP Filename
71 $file = BMI_BACKUPS . '/' . '.space_check';
72 try {
73
74 // 2 GB = (1024 * 1024 * 1024 * 2)
75 $total = $size;
76
77 $fh = fopen($file, 'w');
78 $chunk = 1024;
79 while ($size > 0) {
80 fputs($fh, str_pad('', min($chunk, $size)));
81 $size -= $chunk;
82 }
83 fclose($fh);
84
85 $fs = filesize($file);
86 @unlink($file);
87
88 if ($fs > ($total - 100)) return true;
89 else return false;
90
91 } catch (\Exception $e) {
92
93 Logger::error($e);
94 if (file_exists($file)) unlink($file);
95
96 return false;
97
98 } catch (\Throwable $e) {
99
100 Logger::error($e);
101 if (file_exists($file)) unlink($file);
102
103 return false;
104
105 }
106
107 }
108
109 }
110
111 }
112