mirror of
https://github.com/lkddi/nexusphp.git
synced 2026-04-03 14:10:57 +08:00
backup add feature: upload to google drive
This commit is contained in:
@@ -12,14 +12,14 @@ class BackuAll extends Command
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $signature = 'backup:all';
|
||||
protected $signature = 'backup:all {--upload-to-google-drive}';
|
||||
|
||||
/**
|
||||
* The console command description.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $description = 'Backup all data, include web root and database';
|
||||
protected $description = 'Backup all data, include web root and database. options: --upload-to-google-drive';
|
||||
|
||||
/**
|
||||
* Create a new command instance.
|
||||
@@ -38,9 +38,13 @@ class BackuAll extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
$uploadToGoogleDrive = $this->option('upload-to-google-drive');
|
||||
$rep = new ToolRepository();
|
||||
$result = $rep->backupAll();
|
||||
$log = sprintf('[%s], %s, result: %s', REQUEST_ID, __METHOD__, var_export($result, true));
|
||||
$result = $rep->backupAll($uploadToGoogleDrive);
|
||||
$log = sprintf(
|
||||
'[%s], %s, uploadToGoogleDrive: %s, result: %s',
|
||||
REQUEST_ID, __METHOD__, var_export($uploadToGoogleDrive, true), var_export($result, true)
|
||||
);
|
||||
$this->info($log);
|
||||
do_log($log);
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ class Test extends Command
|
||||
// $rep->assignCronjob();
|
||||
// $r = $rep->cronjobCheckout();
|
||||
$disk = Storage::disk('google_dirve');
|
||||
$r = $disk->files();
|
||||
$r = $disk->put('/', base_path('composer.json'));
|
||||
dd($r);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,8 @@ class Invite extends NexusModel
|
||||
];
|
||||
|
||||
protected $fillable = [
|
||||
'inviter', 'invitee', 'hash', 'time_invited', 'valid', 'invitee_register_uid', 'invitee_register_email', 'invitee_register_username'
|
||||
'inviter', 'invitee', 'hash', 'time_invited', 'valid',
|
||||
'invitee_register_uid', 'invitee_register_email', 'invitee_register_username'
|
||||
];
|
||||
|
||||
public function getValidTextAttribute()
|
||||
|
||||
@@ -14,7 +14,7 @@ class GoogleDriveServiceProvider extends ServiceProvider
|
||||
*/
|
||||
public function boot()
|
||||
{
|
||||
Storage::extend('google_dirve', function($app, $config) {
|
||||
Storage::extend('google_drive', function($app, $config) {
|
||||
$client = new \Google_Client();
|
||||
$client->setClientId($config['clientId']);
|
||||
$client->setClientSecret($config['clientSecret']);
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
namespace App\Repositories;
|
||||
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
class ToolRepository extends BaseRepository
|
||||
{
|
||||
@@ -54,7 +55,7 @@ class ToolRepository extends BaseRepository
|
||||
return compact('result_code', 'filename');
|
||||
}
|
||||
|
||||
public function backupAll()
|
||||
public function backupAll($uploadToGoogleDrive = false)
|
||||
{
|
||||
$backupWeb = $this->backupWebRoot();
|
||||
if ($backupWeb['result_code'] != 0) {
|
||||
@@ -76,7 +77,12 @@ class ToolRepository extends BaseRepository
|
||||
"command: %s, output: %s, result_code: %s, result: %s, filename: %s",
|
||||
$command, json_encode($output), $result_code, $result, $filename
|
||||
));
|
||||
return compact('result_code', 'filename');
|
||||
$upload_result = '';
|
||||
if ($uploadToGoogleDrive) {
|
||||
$disk = Storage::disk('google_drive');
|
||||
$upload_result = $disk->put(basename($filename), fopen($filename, 'r'));
|
||||
}
|
||||
return compact('result_code', 'filename', 'upload_result');
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,8 +51,8 @@ return [
|
||||
'url' => env('AWS_URL'),
|
||||
'endpoint' => env('AWS_ENDPOINT'),
|
||||
],
|
||||
'google_dirve' => [
|
||||
'driver' => 'google_dirve',
|
||||
'google_drive' => [
|
||||
'driver' => 'google_drive',
|
||||
'clientId' => env('GOOGLE_DRIVE_CLIENT_ID'),
|
||||
'clientSecret' => env('GOOGLE_DRIVE_CLIENT_SECRET'),
|
||||
'refreshToken' => env('GOOGLE_DRIVE_REFRESH_TOKEN'),
|
||||
|
||||
@@ -92,7 +92,8 @@ function hash_where($name, $hash) {
|
||||
return "($name = " . sqlesc($hash) . " OR $name = " . sqlesc($shhash) . ")";
|
||||
}
|
||||
|
||||
|
||||
//no need any more...
|
||||
/*
|
||||
function strip_magic_quotes($arr)
|
||||
{
|
||||
foreach ($arr as $k => $v)
|
||||
@@ -119,7 +120,7 @@ if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc())
|
||||
$_COOKIE = strip_magic_quotes($_COOKIE);
|
||||
}
|
||||
}
|
||||
|
||||
*/
|
||||
|
||||
function get_langfolder_list()
|
||||
{
|
||||
|
||||
@@ -199,6 +199,7 @@ if ($type == 'invite')
|
||||
'valid' => \App\Models\Invite::VALID_NO,
|
||||
'invitee_register_uid' => $id,
|
||||
'invitee_register_email' => $email,
|
||||
'invitee_register_username' => $wantusername,
|
||||
];
|
||||
\App\Models\Invite::query()->where('id', $inv['id'])->update($update);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user