-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathWikiController.php
More file actions
60 lines (46 loc) · 1.93 KB
/
WikiController.php
File metadata and controls
60 lines (46 loc) · 1.93 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
<?php
namespace App\Http\Controllers\Backend;
use App\Helper\WikiDbVersionHelper;
use App\Http\Controllers\Controller;
use App\Wiki;
use Illuminate\Http\Request;
class WikiController extends Controller {
public function getWikiForDomain(Request $request): \Illuminate\Http\JsonResponse {
$validated = $request->validate([
'domain' => 'required|string',
]);
$domain = $validated['domain'];
// XXX: this same logic is in quickstatements.php and platform api WikiController backend
try {
$result = Wiki::with(['wikiDb', 'wikiQueryserviceNamespace', 'settings'])->firstWhere('domain', $domain);
} catch (\Exception $e) {
return response()->json($e->getMessage(), 500);
}
if (!$result) {
return response()->json(['error' => 'Not found'], 404);
}
return response()->json(['data' => $result], 200);
}
public function setWikiDbVersionForDomain(Request $request): \Illuminate\Http\JsonResponse {
$validated = $request->validate([
'domain' => 'required|string',
'dbVersion' => 'required|string',
]);
$domain = $validated['domain'];
$targetDbVersion = $validated['dbVersion'];
try {
$wiki = Wiki::with('wikiDb')->firstWhere('domain', $domain);
if (!$wiki) {
return response()->json(['error' => "No wiki found with domain: '{$domain}'"], 404);
}
if (!WikiDbVersionHelper::isValidDbVersion($targetDbVersion)) {
return response()->json(['error' => "Invalid database version string: '{$targetDbVersion}'"], 400);
}
$wiki->wikiDb->version = $targetDbVersion;
$wiki->wikiDb->save();
} catch (\Exception $e) {
return response()->json($e->getMessage(), 500);
}
return response()->json(['result' => 'success'], 200);
}
}