diff --git a/app/Http/Controllers/WikiController.php b/app/Http/Controllers/WikiController.php index a6fed7844..ae017da6c 100644 --- a/app/Http/Controllers/WikiController.php +++ b/app/Http/Controllers/WikiController.php @@ -6,6 +6,7 @@ use App\Jobs\MediawikiInit; use App\Jobs\ProvisionQueryserviceNamespaceJob; use App\Jobs\ProvisionWikiDbJob; +use App\Jobs\ElasticSearchIndexInit; use App\QueryserviceNamespace; use App\Wiki; use App\WikiDb; @@ -79,6 +80,14 @@ public function create(Request $request): \Illuminate\Http\Response 'value' => Str::random(64), ]); + // Enable elasticsearch for new wikis by default + // T285541 +// WikiSetting::create([ +// 'wiki_id' => $wiki->id, +// 'name' => 'wwExtEnableElasticSearch', +// 'value' => true, +// ]); + // Also track the domain forever in your domains table $wikiDomain = WikiDomain::create([ 'domain' => $wiki->domain, @@ -108,6 +117,8 @@ public function create(Request $request): \Illuminate\Http\Response $this->dispatch(new ProvisionWikiDbJob(null, null, 10)); $this->dispatch(new ProvisionQueryserviceNamespaceJob(null, 10)); +// $this->dispatch(new ElasticSearchIndexInit($wiki->domain)); + $res['success'] = true; $res['message'] = 'Success!'; $res['data'] = [ diff --git a/app/Jobs/ElasticSearchIndexInit.php b/app/Jobs/ElasticSearchIndexInit.php new file mode 100644 index 000000000..9d8b6c890 --- /dev/null +++ b/app/Jobs/ElasticSearchIndexInit.php @@ -0,0 +1,66 @@ +wikiDomain = $wikiDomain; + } + + /** + * @return void + */ + public function handle() + { + $curl = curl_init(); + curl_setopt_array($curl, [ + CURLOPT_URL => getenv('PLATFORM_MW_BACKEND_HOST').'/w/api.php?action=wbstackElasticSearchInit&format=json', + CURLOPT_RETURNTRANSFER => true, + CURLOPT_ENCODING => '', + CURLOPT_TIMEOUT => 10, + CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1, + CURLOPT_CUSTOMREQUEST => 'POST', + CURLOPT_HTTPHEADER => [ + 'content-type: application/x-www-form-urlencoded', + 'host: '.$this->wikiDomain, + ], + ]); + + $rawResponse = curl_exec($curl); + $err = curl_error($curl); + if ($err) { + $this->fail( + new \RuntimeException('curl error for '.$this->wikiDomain.': '.$err) + ); + + return; //safegaurd + } + + curl_close($curl); + + $response = json_decode($rawResponse, true); + + if (!array_key_exists('wbstackElasticSearchInit', $response)) { + $this->fail( + new \RuntimeException('wbstackElasticSearchInit call for '.$this->wikiDomain.'. No wbstackElasticSearchInit key in response: '.$rawResponse) + ); + + return; //safegaurd + } + + if ($response['wbstackElasticSearchInit']['success'] == 0) { + $this->fail( + new \RuntimeException('wbstackElasticSearchInit call for '.$this->wikiDomain.' was not successful:'.$rawResponse) + ); + + return; //safegaurd + } + } +}