BackupGuard
5 years ago
Dropbox
5 years ago
Request
5 years ago
SGArchive.php
5 years ago
SGAuthClient.php
5 years ago
SGCallback.php
5 years ago
SGCdrEntry.php
5 years ago
SGCharsetHandler.php
5 years ago
SGDBState.php
5 years ago
SGEntry.php
5 years ago
SGFileEntry.php
5 years ago
SGFileState.php
5 years ago
SGMigrateState.php
5 years ago
SGMysqldump.php
5 years ago
SGReloadHandler.php
5 years ago
SGReloader.php
5 years ago
SGReloaderState.php
5 years ago
SGReviewManager.php
5 years ago
SGState.php
5 years ago
SGStatsRequests.php
5 years ago
SGUploadHandler.php
5 years ago
SGUploadState.php
5 years ago
SGReloader.php
87 lines
| 1 | <?php |
| 2 | |
| 3 | require_once(SG_BACKUP_PATH.'SGBackup.php'); |
| 4 | require_once(SG_LIB_PATH.'SGReloaderState.php'); |
| 5 | require_once(SG_LIB_PATH.'SGReloadHandler.php'); |
| 6 | require_once(SG_LIB_PATH.'SGCallback.php'); |
| 7 | |
| 8 | class SGReloader |
| 9 | { |
| 10 | public static function awake($method = null) |
| 11 | { |
| 12 | $reloaderState = SGReloaderState::loadState(); |
| 13 | if ($reloaderState['callback'] != "" && $reloaderState['state'] == SG_RELOADER_STATUS_IDLE) { |
| 14 | |
| 15 | $callbackJson = json_decode($reloaderState['callback']); |
| 16 | $callbackJson->params['method'] = $method; |
| 17 | $callback = new SGCallback($callbackJson->class, $callbackJson->method, $callbackJson->params); |
| 18 | |
| 19 | if ($callback->canPerform()) { |
| 20 | self::saveState('', SG_RELOADER_STATUS_RUNNING); |
| 21 | $callback->perform(); |
| 22 | } |
| 23 | } |
| 24 | |
| 25 | return; |
| 26 | } |
| 27 | |
| 28 | private static function saveState($callback, $state = SG_RELOADER_STATUS_IDLE) |
| 29 | { |
| 30 | $sgReloaderState = new SGReloaderState(); |
| 31 | $sgReloaderState->setCallback($callback); |
| 32 | $sgReloaderState->setState($state); |
| 33 | $sgReloaderState->update(); |
| 34 | } |
| 35 | |
| 36 | public static function didCompleteCallback() |
| 37 | { |
| 38 | self::saveState('', SG_RELOADER_STATUS_IDLE); |
| 39 | } |
| 40 | |
| 41 | public static function registerCallback(SGCallback $callback) |
| 42 | { |
| 43 | self::saveState((string)$callback); |
| 44 | } |
| 45 | |
| 46 | public static function reset() |
| 47 | { |
| 48 | SGReloaderState::reset(); |
| 49 | } |
| 50 | |
| 51 | public static function reloadWithAjaxUrl($awakeURL) |
| 52 | { |
| 53 | //external restore works only with ajax requests |
| 54 | if (defined('BG_EXTERNAL_RESTORE_RUNNING') && BG_EXTERNAL_RESTORE_RUNNING) { |
| 55 | return; |
| 56 | } |
| 57 | |
| 58 | // awake frequency in miliseconds |
| 59 | $sgAwakeFrequency = SGConfig::get('SG_AJAX_REQUEST_FREQUENCY')?SGConfig::get('SG_AJAX_REQUEST_FREQUENCY'):SG_AJAX_DEFAULT_REQUEST_FREQUENCY; |
| 60 | $sgAwakeFrequency = $sgAwakeFrequency/1000; // awake frequency in seconds |
| 61 | |
| 62 | // add 3 seconds to awake frequency |
| 63 | $timeout = $sgAwakeFrequency + 3; |
| 64 | while ($timeout) { |
| 65 | |
| 66 | $reloaderState = SGReloaderState::loadState(); |
| 67 | $state = $reloaderState['state']; |
| 68 | |
| 69 | if ($state == SG_RELOADER_STATUS_RUNNING) { |
| 70 | return; |
| 71 | } |
| 72 | |
| 73 | sleep(1); |
| 74 | $timeout--; |
| 75 | } |
| 76 | |
| 77 | self::reload($awakeURL); |
| 78 | } |
| 79 | |
| 80 | private static function reload($awakeURL) |
| 81 | { |
| 82 | $sgReloadHandler = new SGReloadHandler($awakeURL); |
| 83 | $sgReloadHandler->reload(); |
| 84 | return; |
| 85 | } |
| 86 | } |
| 87 |