-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMediawikiSandboxLoadData.php
More file actions
63 lines (51 loc) · 1.8 KB
/
MediawikiSandboxLoadData.php
File metadata and controls
63 lines (51 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
namespace App\Jobs;
use App\Services\MediaWikiHostResolver;
class MediawikiSandboxLoadData extends Job {
private $wikiDomain;
private $dataSet;
/**
* @return void
*/
public function __construct($wikiDomain, $dataSet) {
$this->wikiDomain = $wikiDomain;
$this->dataSet = $dataSet;
}
/**
* @return void
*/
public function handle(MediaWikiHostResolver $mwHostResolver) {
$data = [
'dataSet' => $this->dataSet,
];
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => $mwHostResolver->getBackendHostForDomain($this->wikiDomain) . '/w/rest.php/wikibase-exampledata/v0/load',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_TIMEOUT => 10 * 60, // TODO Long 10 mins (probably shouldn't keep the request open...)
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'POST',
CURLOPT_POSTFIELDS => http_build_query($data),
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('wikibase-exampledata/v0/load curl error for ' . $this->wikiDomain . ': ' . $err)
);
return; // safegaurd
}
curl_close($curl);
if (!strstr($rawResponse, 'Done!')) {
$this->fail(
new \RuntimeException('wikibase-exampledata/v0/load call for ' . $this->wikiDomain . ' was not successful:' . $rawResponse)
);
return; // safegaurd
}
}
}