]> BookStack Code Mirror - bookstack/blobdiff - app/Console/Commands/RegenerateSearch.php
Code cleanup, bug squashing
[bookstack] / app / Console / Commands / RegenerateSearch.php
index ccc2a20e59896b7ed0166fa565a7830dfd1c106c..3dc3ec0af0e98b33bd3f1d741540dd13e1d319c5 100644 (file)
@@ -2,7 +2,8 @@
 
 namespace BookStack\Console\Commands;
 
-use BookStack\Services\SearchService;
+use BookStack\Entities\Tools\SearchIndex;
+use DB;
 use Illuminate\Console\Command;
 
 class RegenerateSearch extends Command
@@ -12,26 +13,24 @@ class RegenerateSearch extends Command
      *
      * @var string
      */
-    protected $signature = 'bookstack:regenerate-search';
+    protected $signature = 'bookstack:regenerate-search {--database= : The database connection to use.}';
 
     /**
      * The console command description.
      *
      * @var string
      */
-    protected $description = 'Command description';
+    protected $description = 'Re-index all content for searching';
 
-    protected $searchService;
+    protected $searchIndex;
 
     /**
      * Create a new command instance.
-     *
-     * @param SearchService $searchService
      */
-    public function __construct(SearchService $searchService)
+    public function __construct(SearchIndex $searchIndex)
     {
         parent::__construct();
-        $this->searchService = $searchService;
+        $this->searchIndex = $searchIndex;
     }
 
     /**
@@ -41,6 +40,13 @@ class RegenerateSearch extends Command
      */
     public function handle()
     {
-        $this->searchService->indexAllEntities();
+        $connection = DB::getDefaultConnection();
+        if ($this->option('database') !== null) {
+            DB::setDefaultConnection($this->option('database'));
+        }
+
+        $this->searchIndex->indexAllEntities();
+        DB::setDefaultConnection($connection);
+        $this->comment('Search index regenerated');
     }
 }