Database
2 years ago
Database.php
2 years ago
DateTimeAdapter.php
4 years ago
Directory.php
2 years ago
Maintenance.php
4 years ago
PhpAdapter.php
4 years ago
SourceDatabase.php
2 years ago
WpAdapter.php
3 years ago
Maintenance.php
37 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WPStaging\Framework\Adapter; |
| 4 | |
| 5 | use WPStaging\Framework\Filesystem\FileObject; |
| 6 | use WPStaging\Framework\Filesystem\Filesystem; |
| 7 | |
| 8 | class Maintenance |
| 9 | { |
| 10 | const FILE_NAME = '.maintenance'; |
| 11 | |
| 12 | public function isMaintenance() |
| 13 | { |
| 14 | return file_exists($this->findMaintenanceFilePath()); |
| 15 | } |
| 16 | |
| 17 | public function enableMaintenance($isMaintenance) |
| 18 | { |
| 19 | $maintenanceFile = $this->findMaintenanceFilePath(); |
| 20 | $fileExists = $this->isMaintenance(); |
| 21 | if ($isMaintenance && !$fileExists) { |
| 22 | // Perhaps maintenance.php in WP_CONTENT? |
| 23 | (new FileObject($maintenanceFile, FileObject::MODE_WRITE))->fwriteSafe('<?php $upgrading = time() ?>'); |
| 24 | return; |
| 25 | } |
| 26 | |
| 27 | if (!$isMaintenance && $fileExists) { |
| 28 | (new Filesystem())->delete($maintenanceFile); |
| 29 | } |
| 30 | } |
| 31 | |
| 32 | private function findMaintenanceFilePath() |
| 33 | { |
| 34 | return ABSPATH . self::FILE_NAME; |
| 35 | } |
| 36 | } |
| 37 |