2
2
3
3
namespace LaravelHunt \Console ;
4
4
5
- use Illuminate \Database \Eloquent \Model ;
6
-
7
5
class ImportCommand extends AbstractCommand
8
6
{
9
7
/**
@@ -12,7 +10,8 @@ class ImportCommand extends AbstractCommand
12
10
* @var string
13
11
*/
14
12
protected $ signature = 'hunt:import
15
- {model : Name or comma separated names of the model(s) to index} ' ;
13
+ {model : Name or comma separated names of the model(s) to index}
14
+ {--l|locales= : Single or comma separated locales to index} ' ;
16
15
17
16
/**
18
17
* The console command description.
@@ -28,9 +27,18 @@ class ImportCommand extends AbstractCommand
28
27
*/
29
28
public function handle ()
30
29
{
30
+ $ locales = $ this ->getLocaleOption ();
31
+
31
32
foreach ($ this ->getModelArgument () as $ model ) {
32
33
if ($ model = $ this ->validateModel ($ model )) {
33
- $ this ->index ($ model );
34
+ if (empty ($ locales ) === false ) {
35
+ foreach ($ locales as $ locale ) {
36
+ $ this ->index ($ model , $ locale );
37
+ }
38
+ }
39
+ else {
40
+ $ this ->index ($ model );
41
+ }
34
42
}
35
43
}
36
44
}
@@ -39,10 +47,11 @@ public function handle()
39
47
* Index all model entries to ElasticSearch.
40
48
*
41
49
* @param string $model
50
+ * @param string $locale
42
51
*
43
52
* @return bool
44
53
*/
45
- protected function index ($ model )
54
+ protected function index ($ model, $ locale = '' )
46
55
{
47
56
$ this ->comment ("Processing [ {$ model }] " );
48
57
@@ -55,6 +64,11 @@ protected function index($model)
55
64
$ this ->hunter ->putMapping ($ instance );
56
65
}
57
66
67
+ // Get entries by a specific locale
68
+ if ($ locale && ($ field = $ this ->hunter ->config ('locale_field ' ))) {
69
+ $ instance ->where ($ field , $ locale );
70
+ }
71
+
58
72
// Index model
59
73
$ this ->line (' - Importing ' );
60
74
0 commit comments