-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Darren Miller
committed
Oct 24, 2019
1 parent
545f9dc
commit c46f827
Showing
1 changed file
with
57 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace App\Console\Commands; | ||
|
||
use Google_Client; | ||
use App\Models\Album; | ||
use App\Models\Photo; | ||
use Illuminate\Console\Command; | ||
use Google_Service_PhotosLibrary; | ||
use Illuminate\Support\Facades\Storage; | ||
|
||
class ReIndexAlbum extends Command | ||
{ | ||
/** | ||
* The name and signature of the console command. | ||
* | ||
* @var string | ||
*/ | ||
protected $signature = 'photos:reindex {albumId}'; | ||
|
||
/** | ||
* The console command description. | ||
* | ||
* @var string | ||
*/ | ||
protected $description = 'Destroy and re-index a troublesome album'; | ||
protected $photoservice; | ||
protected $storage; | ||
|
||
/** | ||
* Create a new command instance. | ||
* | ||
* @return void | ||
*/ | ||
public function __construct(Google_Client $gclient) | ||
{ | ||
parent::__construct(); | ||
$this->photoservice = new Google_Service_PhotosLibrary($gclient); | ||
$this->storage = Storage::disk('photos'); | ||
} | ||
|
||
/** | ||
* Execute the console command. | ||
* | ||
* @return mixed | ||
*/ | ||
public function handle() | ||
{ | ||
$albumId = $this->argument('albumId'); | ||
Album::where('id','=',$albumId)->delete(); | ||
Photo::where('album_id','=',$albumId)->delete(); | ||
if($this->storage->has($albumId)) { | ||
$this->storage->deleteDirectory($albumId); | ||
} | ||
$this->call('photos:index'); | ||
} | ||
} |