Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions app/Http/Controllers/WikiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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'] = [
Expand Down
66 changes: 66 additions & 0 deletions app/Jobs/ElasticSearchIndexInit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php

namespace App\Jobs;

class ElasticSearchIndexInit extends Job
{
private $wikiDomain;

/**
* @return void
*/
public function __construct($wikiDomain)
{
$this->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
}
}
}