16
16
use Hyperf \Utils \ApplicationContext ;
17
17
use Psr \EventDispatcher \ListenerProviderInterface ;
18
18
use Symfony \Component \Console \Input \InputArgument ;
19
+ use Symfony \Component \Console \Input \InputOption ;
19
20
20
21
class ImportCommand extends Command
21
22
{
@@ -40,16 +41,27 @@ public function handle()
40
41
{
41
42
define ('SCOUT_COMMAND ' , true );
42
43
$ class = $ this ->input ->getArgument ('model ' );
44
+ $ chunk = (int ) $ this ->input ->getOption ('chunk ' );
45
+ $ column = (string ) $ this ->input ->getOption ('column ' );
43
46
$ model = new $ class ();
44
47
$ provider = ApplicationContext::getContainer ()->get (ListenerProviderInterface::class);
45
48
$ provider ->on (ModelsImported::class, function ($ event ) use ($ class ) {
49
+ /** @var ModelsImported $event */
46
50
$ key = $ event ->models ->last ()->getScoutKey ();
47
51
$ this ->line ('<comment>Imported [ ' . $ class . '] models up to ID:</comment> ' . $ key );
48
52
});
49
- $ model ::makeAllSearchable ();
53
+ $ model ::makeAllSearchable ($ chunk ?: null , $ column ?: null );
50
54
$ this ->info ('All [ ' . $ class . '] records have been imported. ' );
51
55
}
52
56
57
+ protected function getOptions ()
58
+ {
59
+ return [
60
+ ['column ' , 'c ' , InputOption::VALUE_OPTIONAL , 'Column used in chunking. (Default use primary key) ' ],
61
+ ['chunk ' , '' , InputOption::VALUE_OPTIONAL , 'The number of records to import at a time (Defaults to configuration value: `scout.chunk.searchable`) ' ],
62
+ ];
63
+ }
64
+
53
65
protected function getArguments ()
54
66
{
55
67
return [
0 commit comments