@@ 9-32 (lines=24) @@ | ||
6 | use Leitom\Geo\Events\ModelsImported; |
|
7 | use Illuminate\Contracts\Events\Dispatcher; |
|
8 | ||
9 | class ImportCommand extends Command |
|
10 | { |
|
11 | protected $signature = 'geo:import {model}'; |
|
12 | ||
13 | protected $description = 'Import all records from the given model into the redis index'; |
|
14 | ||
15 | public function handle(Dispatcher $events) |
|
16 | { |
|
17 | $class = $this->argument('model'); |
|
18 | ||
19 | $model = new $class; |
|
20 | ||
21 | $events->listen(ModelsImported::class, function ($event) use ($class) { |
|
22 | $key = $event->models->last()->geoKey(); |
|
23 | $this->line('<comment>Imported ['.$class.'] models up to ID:</comment> '.$key); |
|
24 | }); |
|
25 | ||
26 | $model::geoImportAll(); |
|
27 | ||
28 | $events->forget(ModelsImported::class); |
|
29 | ||
30 | $this->info('All ['.$class.'] records have been imported.'); |
|
31 | } |
|
32 | } |
|
33 |
@@ 9-32 (lines=24) @@ | ||
6 | use Leitom\Geo\Events\ModelsRemoved; |
|
7 | use Illuminate\Contracts\Events\Dispatcher; |
|
8 | ||
9 | class RemoveCommand extends Command |
|
10 | { |
|
11 | protected $signature = 'geo:remove {model}'; |
|
12 | ||
13 | protected $description = 'Remove all records for the given model from the redis index'; |
|
14 | ||
15 | public function handle(Dispatcher $events) |
|
16 | { |
|
17 | $class = $this->argument('model'); |
|
18 | ||
19 | $model = new $class; |
|
20 | ||
21 | $events->listen(ModelsRemoved::class, function ($event) use ($class) { |
|
22 | $key = $event->models->last()->geoKey(); |
|
23 | $this->line('<comment>Removed ['.$class.'] models up to ID:</comment> '.$key); |
|
24 | }); |
|
25 | ||
26 | $model::geoRemoveAll(); |
|
27 | ||
28 | $events->forget(ModelsRemoved::class); |
|
29 | ||
30 | $this->info('All ['.$class.'] records have been removed.'); |
|
31 | } |
|
32 | } |
|
33 |