the browser-facing portion of osu!
at master 1.7 kB view raw
1<?php 2 3// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the GNU Affero General Public License v3.0. 4// See the LICENCE file in the repository root for full licence text. 5 6namespace App\Console\Commands; 7 8use App\Libraries\Elasticsearch\Es; 9use Illuminate\Console\Command; 10 11class EsCreateSearchBlacklist extends Command 12{ 13 /** 14 * The name and signature of the console command. 15 * 16 * @var string 17 */ 18 protected $signature = 'es:create-search-blacklist'; 19 20 /** 21 * The console command description. 22 * 23 * @var string 24 */ 25 protected $description = 'Creates the search blacklist index if it does not exist.'; 26 27 /** 28 * Execute the console command. 29 * 30 * @return mixed 31 */ 32 public function handle() 33 { 34 $alias = $GLOBALS['cfg']['osu']['elasticsearch']['prefix'].'blacklist'; 35 $client = Es::getClient(); 36 37 /** @var array $response The type-hint in the doc is wrong. */ 38 $response = $client->indices()->get(['index' => $alias, 'client' => ['ignore' => 404]]); 39 40 $statusCode = $response['status'] ?? null; 41 if ($statusCode === null) { 42 $this->info("{$alias} already exists, skipping."); 43 44 return; 45 } 46 47 $index = $alias.'_'.time(); 48 $this->info("{$alias} does exist, creating aliased index {$index}..."); 49 $client->indices()->create([ 50 'body' => [ 51 'aliases' => [$alias => new \stdClass()], 52 'settings' => [ 53 'number_of_replicas' => 0, 54 'number_of_shards' => 1, 55 ], 56 ], 57 'index' => $index, 58 ]); 59 } 60}