BackupGuardStorage.php
4 years ago
SGDropbox.php
4 years ago
SGDropboxStorage.php
3 years ago
SGStorage.php
4 years ago
SGStorage.php
109 lines
| 1 | <?php |
| 2 | |
| 3 | require_once(SG_LIB_PATH . 'SGReloadHandler.php'); |
| 4 | require_once(SG_LIB_PATH . 'SGState.php'); |
| 5 | require_once(SG_LIB_PATH . 'SGUploadState.php'); |
| 6 | |
| 7 | interface SGIStorageDelegate |
| 8 | { |
| 9 | public function willStartUpload($chunksCount); |
| 10 | |
| 11 | public function updateProgressManually($progress); |
| 12 | |
| 13 | public function shouldUploadNextChunk(); |
| 14 | } |
| 15 | |
| 16 | abstract class SGStorage // phpcs:ignore |
| 17 | { |
| 18 | // phpcs:disable |
| 19 | protected $connected = false; |
| 20 | protected $activeDirectory = ''; |
| 21 | protected $delegate = null; |
| 22 | protected $state = null; |
| 23 | // phpcs:enable |
| 24 | |
| 25 | /* Make all initializations here */ |
| 26 | abstract public function init(); |
| 27 | |
| 28 | /* Connect to the Storage */ |
| 29 | abstract public function connect(); |
| 30 | |
| 31 | /* Connect offline. This will ensure that redirections to other pages won't be made */ |
| 32 | abstract public function connectOffline(); |
| 33 | |
| 34 | /* Check if it is already connected */ |
| 35 | abstract public function checkConnected(); |
| 36 | |
| 37 | /* Get list of files inside the active directory */ |
| 38 | abstract public function getListOfFiles(); |
| 39 | |
| 40 | /* Create a folder inside the active directory. If folder already exists, do nothing. */ |
| 41 | abstract public function createFolder($folderName); |
| 42 | |
| 43 | /* Download file from Storage*/ |
| 44 | abstract public function downloadFile($filePath, $size, $backupId = null); |
| 45 | |
| 46 | /* Upload local file to Storage */ |
| 47 | abstract public function uploadFile($filePath); |
| 48 | |
| 49 | /* Delete file from active directory */ |
| 50 | abstract public function deleteFile($fileName); |
| 51 | |
| 52 | /* Delete folder and it's contents from active directory */ |
| 53 | abstract public function deleteFolder($folderName); |
| 54 | |
| 55 | /* Search if file or folder exists in given path */ |
| 56 | abstract public function fileExists($path); |
| 57 | |
| 58 | public function __construct() |
| 59 | { |
| 60 | @session_write_close(); |
| 61 | @session_start(); |
| 62 | $this->init(); |
| 63 | $this->checkConnected(); |
| 64 | } |
| 65 | |
| 66 | /* NOTE: Depending on the storage type, $directory could be the ID of the directory and not the name. */ |
| 67 | public function setActiveDirectory($directory) |
| 68 | { |
| 69 | $this->activeDirectory = $directory; |
| 70 | } |
| 71 | |
| 72 | public function getActiveDirectory() |
| 73 | { |
| 74 | return $this->activeDirectory; |
| 75 | } |
| 76 | |
| 77 | public function isConnected() |
| 78 | { |
| 79 | return $this->connected; |
| 80 | } |
| 81 | |
| 82 | public function setDelegate(SGIStorageDelegate $delegate) |
| 83 | { |
| 84 | $this->delegate = $delegate; |
| 85 | } |
| 86 | |
| 87 | public function loadState() |
| 88 | { |
| 89 | $this->state = $this->delegate->getState(); |
| 90 | } |
| 91 | |
| 92 | public function reload() |
| 93 | { |
| 94 | $this->delegate->reload(); |
| 95 | } |
| 96 | |
| 97 | public function shouldReload() |
| 98 | { |
| 99 | return $this->delegate->shouldReload(); |
| 100 | } |
| 101 | |
| 102 | public function standardizeFileCreationDate($date) |
| 103 | { |
| 104 | $time = strtotime($date); |
| 105 | |
| 106 | return backupGuardConvertDateTimezone(date('Y-m-d H:i:s', $time), true); |
| 107 | } |
| 108 | } |
| 109 |