]> BookStack Code Mirror - bookstack/blobdiff - app/Console/Commands/RegenerateSearch.php
Add the "Create Shelf" resp. "Create Book" to the home view
[bookstack] / app / Console / Commands / RegenerateSearch.php
index ccc2a20e59896b7ed0166fa565a7830dfd1c106c..d27d73edc01dcbf55443f9bbf8f916539d0c5295 100644 (file)
@@ -2,7 +2,7 @@
 
 namespace BookStack\Console\Commands;
 
-use BookStack\Services\SearchService;
+use BookStack\Entities\SearchService;
 use Illuminate\Console\Command;
 
 class RegenerateSearch extends Command
@@ -12,21 +12,21 @@ 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;
 
     /**
      * Create a new command instance.
      *
-     * @param SearchService $searchService
+     * @param \BookStack\Entities\SearchService $searchService
      */
     public function __construct(SearchService $searchService)
     {
@@ -41,6 +41,14 @@ class RegenerateSearch extends Command
      */
     public function handle()
     {
+        $connection = \DB::getDefaultConnection();
+        if ($this->option('database') !== null) {
+            \DB::setDefaultConnection($this->option('database'));
+            $this->searchService->setConnection(\DB::connection($this->option('database')));
+        }
+
         $this->searchService->indexAllEntities();
+        \DB::setDefaultConnection($connection);
+        $this->comment('Search index regenerated');
     }
 }