1 | <?php |
||
28 | class GoogleDrive implements Simulator |
||
29 | { |
||
30 | use Cleanable; |
||
31 | |||
32 | /** |
||
33 | * @var \Google_Client |
||
34 | */ |
||
35 | private $client; |
||
36 | |||
37 | /** |
||
38 | * Google json secret file. |
||
39 | * |
||
40 | * @var string |
||
41 | */ |
||
42 | private $secret; |
||
43 | |||
44 | /** |
||
45 | * Google json credentials file. |
||
46 | * |
||
47 | * @var string |
||
48 | */ |
||
49 | private $access; |
||
50 | |||
51 | /** |
||
52 | * Google drive parent folder id. |
||
53 | * |
||
54 | * @var string |
||
55 | */ |
||
56 | private $parent; |
||
57 | |||
58 | /** |
||
59 | * Upload chunk size. |
||
60 | * |
||
61 | * @var int |
||
62 | */ |
||
63 | private $chunkSize = 1 * 1024 * 1024; |
||
64 | |||
65 | /** |
||
66 | * (non-PHPDoc) |
||
67 | * |
||
68 | * @see \phpbu\App\Backup\Sync::setup() |
||
69 | * @param array $config |
||
70 | * @throws \phpbu\App\Backup\Sync\Exception |
||
71 | */ |
||
72 | public function setup(array $config) |
||
86 | |||
87 | /** |
||
88 | * Make sure both google authentication files exist and determine absolute path to them. |
||
89 | * |
||
90 | * @param array $config |
||
91 | * @throws \phpbu\App\Backup\Sync\Exception |
||
92 | */ |
||
93 | private function setupAuthFiles(array $config) |
||
106 | |||
107 | /** |
||
108 | * Execute the Sync |
||
109 | * |
||
110 | * @see \phpbu\App\Backup\Sync::sync() |
||
111 | * @param \phpbu\App\Backup\Target $target |
||
112 | * @param \phpbu\App\Result $result |
||
113 | * @throws \phpbu\App\Backup\Sync\Exception |
||
114 | */ |
||
115 | public function sync(Target $target, Result $result) |
||
147 | |||
148 | /** |
||
149 | * Simulate the sync execution. |
||
150 | * |
||
151 | * @param \phpbu\App\Backup\Target $target |
||
152 | * @param \phpbu\App\Result $result |
||
153 | */ |
||
154 | public function simulate(Target $target, Result $result) |
||
161 | |||
162 | /** |
||
163 | * Create google api client. |
||
164 | * |
||
165 | * @return \Google_Client |
||
166 | * @throws \Google_Exception |
||
167 | */ |
||
168 | protected function createClient() : GClient |
||
185 | |||
186 | /** |
||
187 | * Create google api file. |
||
188 | * |
||
189 | * @param \phpbu\App\Backup\Target $target |
||
190 | * @return \Google_Service_Drive_DriveFile |
||
191 | */ |
||
192 | protected function createFile(Target $target) : GFile |
||
200 | |||
201 | /** |
||
202 | * Create google api file deferred upload. |
||
203 | * |
||
204 | * @param \Google_Client $client |
||
205 | * @param \Psr\Http\Message\RequestInterface $request |
||
206 | * @param \phpbu\App\Backup\Target $target |
||
207 | * @return \Google_Http_MediaFileUpload |
||
208 | * @throws \phpbu\App\Exception |
||
209 | */ |
||
210 | protected function createUploadStream(GClient $client, RequestInterface $request, Target $target) : GStream |
||
224 | |||
225 | /** |
||
226 | * Return google credentials. |
||
227 | * |
||
228 | * @return array |
||
229 | */ |
||
230 | private function getAccessToken() : array |
||
234 | |||
235 | /** |
||
236 | * Update the access token in the google credentials file. |
||
237 | * |
||
238 | * @param array $accessToken |
||
239 | * @return void |
||
240 | */ |
||
241 | private function updateAccessToken(array $accessToken) |
||
245 | |||
246 | /** |
||
247 | * Creates collector for remote cleanup. |
||
248 | * |
||
249 | * @param \phpbu\App\Backup\Target $target |
||
250 | * @return \phpbu\App\Backup\Collector |
||
251 | * @throws \Google_Exception |
||
252 | */ |
||
253 | protected function createCollector(Target $target): Collector |
||
257 | } |
||
258 |