SGINoticeAdapter.php
3 years ago
SGNotice.php
3 years ago
SGNoticeAdapterWordpress.php
3 years ago
SGNoticeHandler.php
3 years ago
SGNoticeHandler.php
101 lines
| 1 | <?php |
| 2 | |
| 3 | class SGNoticeHandler |
| 4 | { |
| 5 | public function run() |
| 6 | { |
| 7 | $this->checkTimeoutError(); |
| 8 | $this->checkMigrationError(); |
| 9 | $this->checkRestoreNotWritableError(); |
| 10 | $this->checkLiteSpeedWarning(); |
| 11 | $this->checkTables(); |
| 12 | $this->checkPingFilePermission(); |
| 13 | $this->checkExpiredLicense(); |
| 14 | $this->checkPluginRequirements(); |
| 15 | } |
| 16 | |
| 17 | private function checkPluginRequirements() |
| 18 | { |
| 19 | try { |
| 20 | //check minimum requirements |
| 21 | checkMinimumRequirements(); |
| 22 | |
| 23 | //prepare directory for backups |
| 24 | prepareBackupDir(); |
| 25 | } catch (SGException $exp) { |
| 26 | SGNotice::getInstance()->addNotice($exp->getMessage(), SG_NOTICE_ERROR, true); |
| 27 | } |
| 28 | } |
| 29 | |
| 30 | private function checkTimeoutError() |
| 31 | { |
| 32 | $pluginCapabilities = backupGuardGetCapabilities(); |
| 33 | if (SGConfig::get('SG_EXCEPTION_TIMEOUT_ERROR')) { |
| 34 | if ($pluginCapabilities != BACKUP_GUARD_CAPABILITIES_FREE) { |
| 35 | SGNotice::getInstance()->addNoticeFromTemplate('timeout_error', SG_NOTICE_ERROR, true); |
| 36 | } |
| 37 | else { |
| 38 | SGNotice::getInstance()->addNoticeFromTemplate('timeout_free_error', SG_NOTICE_ERROR, true); |
| 39 | } |
| 40 | } |
| 41 | } |
| 42 | |
| 43 | public function checkTables() |
| 44 | { |
| 45 | if (!checkAllMissedTables()) { |
| 46 | SGNotice::getInstance()->addNoticeFromTemplate('missed_table', SG_NOTICE_ERROR, true); |
| 47 | } |
| 48 | } |
| 49 | |
| 50 | private function checkMigrationError() |
| 51 | { |
| 52 | if (SGConfig::get('SG_BACKUP_SHOW_MIGRATION_ERROR')) { |
| 53 | SGNotice::getInstance()->addNoticeFromTemplate('migration_error', SG_NOTICE_ERROR, true); |
| 54 | } |
| 55 | } |
| 56 | |
| 57 | private function checkRestoreNotWritableError() |
| 58 | { |
| 59 | if (SGConfig::get('SG_BACKUP_SHOW_NOT_WRITABLE_ERROR')) { |
| 60 | SGNotice::getInstance()->addNoticeFromTemplate('restore_notwritable_error', SG_NOTICE_ERROR, true); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | private function checkLiteSpeedWarning() |
| 65 | { |
| 66 | $server = ''; |
| 67 | if (isset($_SERVER['SERVER_SOFTWARE'])) { |
| 68 | $server = strtolower($_SERVER['SERVER_SOFTWARE']); |
| 69 | } |
| 70 | |
| 71 | //check if LiteSpeed server is running |
| 72 | if (strpos($server, 'litespeed') !== false) { |
| 73 | $htaccessContent = ''; |
| 74 | if (is_readable(ABSPATH.'.htaccess')) { |
| 75 | $htaccessContent = @file_get_contents(ABSPATH.'.htaccess'); |
| 76 | if (!$htaccessContent) { |
| 77 | $htaccessContent = ''; |
| 78 | } |
| 79 | } |
| 80 | |
| 81 | if (!$htaccessContent || !preg_match('/noabort/i', $htaccessContent)) { |
| 82 | SGNotice::getInstance()->addNoticeFromTemplate('litespeed_warning', SG_NOTICE_WARNING); |
| 83 | } |
| 84 | } |
| 85 | } |
| 86 | |
| 87 | private function checkPingFilePermission() |
| 88 | { |
| 89 | if (file_exists(SG_PING_FILE_PATH) && !is_readable(SG_PING_FILE_PATH)) { |
| 90 | SGNotice::getInstance()->addNoticeFromTemplate('ping_permission', SG_NOTICE_ERROR, true); |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | private function checkExpiredLicense() |
| 95 | { |
| 96 | if (strtolower(SGConfig::get('SG_LICENSE_KEY_STATUS')) == JBWP_LICENSE_KEY_STATUS_EXPIRED) { |
| 97 | SGNotice::getInstance()->addNoticeFromTemplate('expired_license_error', SG_NOTICE_ERROR, true); |
| 98 | } |
| 99 | } |
| 100 | } |
| 101 |