-
Notifications
You must be signed in to change notification settings - Fork 1
/
Plugin.php
64 lines (56 loc) · 1.61 KB
/
Plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
<?php namespace Captive\Backup;
use Backend;
use Storage;
use Google_Client;
use Google_Service_Drive;
use League\Flysystem\Filesystem;
use Hypweb\Flysystem\GoogleDrive\GoogleDriveAdapter;
use System\Classes\PluginBase;
/**
* Backup Plugin Information File
*/
class Plugin extends PluginBase
{
/**
* Returns information about this plugin.
*
* @return array
*/
public function pluginDetails()
{
return [
'name' => 'captive.backup::lang.plugin.name',
'description' => 'captive.backup::lang.plugin.description',
'author' => 'Captive Media Inc.',
'icon' => 'icon-database',
];
}
/**
* Register method, called when the plugin is first registered.
*
* @return void
*/
public function register()
{
$this->registerConsoleCommand('captive.backup', 'Captive\Backup\Console\Backup');
}
/**
* Boot method, called right before the request route.
*
* @return array
*/
public function boot()
{
// Init Google Drive Storage, TODO: AWS S3
Storage::extend('googledrive', function($app, $config) {
traceLog($config);
$client = new Google_Client();
$client->setClientId($config['clientId']);
$client->setClientSecret($config['clientSecret']);
$client->refreshToken($config['refreshToken']);
$service = new Google_Service_Drive($client);
$adapter = new GoogleDriveAdapter($service, $config['folderId']);
return new Filesystem($adapter);
});
}
}