migration.php
85 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 Restoration/Migration Logs |
| 14 | */ |
| 15 | class BMI_MigrationProgress { |
| 16 | |
| 17 | public $latest; |
| 18 | public $progress; |
| 19 | public $file; |
| 20 | public $muted = false; |
| 21 | |
| 22 | public function __construct($continue = false) { |
| 23 | |
| 24 | if (!file_exists(BMI_BACKUPS)) mkdir(BMI_BACKUPS, 0755, true); |
| 25 | |
| 26 | $this->latest = BMI_BACKUPS . '/latest_migration.log'; |
| 27 | $this->progress = BMI_BACKUPS . '/latest_migration_progress.log'; |
| 28 | |
| 29 | if (file_exists($this->latest) && $continue === false) { |
| 30 | unlink($this->latest); |
| 31 | } |
| 32 | |
| 33 | } |
| 34 | |
| 35 | public function start($muted = false) { |
| 36 | |
| 37 | $this->muted = $muted; |
| 38 | |
| 39 | } |
| 40 | |
| 41 | public function mute() { |
| 42 | |
| 43 | $this->muted = true; |
| 44 | |
| 45 | } |
| 46 | |
| 47 | public function unmute() { |
| 48 | |
| 49 | $this->muted = false; |
| 50 | |
| 51 | } |
| 52 | |
| 53 | public function progress($progress = '0') { |
| 54 | |
| 55 | file_put_contents($this->progress, $progress); |
| 56 | |
| 57 | } |
| 58 | |
| 59 | public function log($log = '', $level = 'INFO') { |
| 60 | |
| 61 | $this->file = fopen($this->latest, 'a'); |
| 62 | |
| 63 | if (!$this->muted) { |
| 64 | if (defined('BMI_USING_CLI_FUNCTIONALITY') && BMI_USING_CLI_FUNCTIONALITY === true) { |
| 65 | $log_string = '[' . strtoupper($level) . '] [' . date('Y-m-d H:i:s') . '] [CLI] ' . $log . "\n"; |
| 66 | } else { |
| 67 | $log_string = '[' . strtoupper($level) . '] [' . date('Y-m-d H:i:s') . '] ' . $log . "\n"; |
| 68 | } |
| 69 | fwrite($this->file, $log_string); |
| 70 | if (defined('BMI_USING_CLI_FUNCTIONALITY') && BMI_USING_CLI_FUNCTIONALITY === true) { |
| 71 | echo $log_string; |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | fclose($this->file); |
| 76 | } |
| 77 | |
| 78 | public function end() { |
| 79 | |
| 80 | return true; |
| 81 | |
| 82 | } |
| 83 | |
| 84 | } |
| 85 |