From a98246b7d2094009214579a023a0f7e3c4575533 Mon Sep 17 00:00:00 2001 From: dena Date: Mon, 24 Nov 2025 18:23:33 +0100 Subject: [PATCH 1/3] cleanup --- .../Controllers/Backend/WikiController.php | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/app/Http/Controllers/Backend/WikiController.php b/app/Http/Controllers/Backend/WikiController.php index 8fccf7781..ea3c9067a 100644 --- a/app/Http/Controllers/Backend/WikiController.php +++ b/app/Http/Controllers/Backend/WikiController.php @@ -7,28 +7,23 @@ use Illuminate\Http\Request; class WikiController extends Controller { - private static $with = ['wikiDb', 'wikiQueryserviceNamespace', 'settings']; - public function getWikiForDomain(Request $request): \Illuminate\Http\JsonResponse { - $domain = $request->input('domain'); + $validated = $request->validate([ + 'domain' => 'required|string', + ]); + $domain = $validated['domain']; // XXX: this same logic is in quickstatements.php and platform api WikiController backend try { - if ($domain === 'localhost' || $domain === 'mediawiki') { - // If just using localhost then just get the first undeleted wiki - $result = Wiki::with(self::$with)->first(); - } else { - // TODO don't select the timestamps and redundant info for the settings? - $result = Wiki::where('domain', $domain)->with(self::$with)->first(); - } - } catch (\Exception $ex) { - return response()->json($ex->getMessage(), 500); + $wiki = Wiki::with(['wikiDb', 'wikiQueryserviceNamespace', 'settings'])->firstWhere('domain', $domain); + } catch (\Exception $e) { + return response()->json($e->getMessage(), 500); } - if (!$result) { + if (!$wiki) { return response()->json(['error' => 'Not found'], 404); } - return response()->json(['data' => $result], 200); + return response()->json(['data' => $wiki], 200); } } From c91dee7a9b9748dc624b478838debe8a3c49bcde Mon Sep 17 00:00:00 2001 From: dena Date: Mon, 24 Nov 2025 18:23:40 +0100 Subject: [PATCH 2/3] add test --- tests/Routes/Backend/WikiControllerTest.php | 53 +++++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 tests/Routes/Backend/WikiControllerTest.php diff --git a/tests/Routes/Backend/WikiControllerTest.php b/tests/Routes/Backend/WikiControllerTest.php new file mode 100644 index 000000000..9c2a0e438 --- /dev/null +++ b/tests/Routes/Backend/WikiControllerTest.php @@ -0,0 +1,53 @@ +create(['domain' => $domain]); + WikiDb::create([ + 'name' => $domain, + 'user' => 'someUser', + 'password' => 'somePassword', + 'prefix' => 'somePrefix', + 'version' => 'someVersion', + 'wiki_id' => $wiki->id, + ]); + } + + public function testGetWikiDomainSuccess() { + $wikiDomain = 'coffeebase.wikibase.cloud'; + + $this->createWiki($wikiDomain); + + $this->get("{$this->route}?domain={$wikiDomain}") + ->assertStatus(200) + ->assertJsonPath('data.domain', $wikiDomain) + ->assertJsonStructure([ + 'data' => [ + 'domain', + 'sitename', + 'wiki_queryservice_namespace', + ], + ]); + } + + public function testGetWikiDomainMissingWikiDomain() { + $this->getJson("{$this->route}") + ->assertStatus(422); + } + + public function testGetWikiDomainWikiNotFound() { + $this->getJson("{$this->route}?domain=somewiki") + ->assertStatus(404); + } +} From fc7e06f7d4ec06a78d4a4e8189debd0ca038daeb Mon Sep 17 00:00:00 2001 From: dena Date: Tue, 25 Nov 2025 10:41:57 +0100 Subject: [PATCH 3/3] remove comment --- app/Http/Controllers/Backend/WikiController.php | 1 - 1 file changed, 1 deletion(-) diff --git a/app/Http/Controllers/Backend/WikiController.php b/app/Http/Controllers/Backend/WikiController.php index ea3c9067a..b8e23761d 100644 --- a/app/Http/Controllers/Backend/WikiController.php +++ b/app/Http/Controllers/Backend/WikiController.php @@ -13,7 +13,6 @@ public function getWikiForDomain(Request $request): \Illuminate\Http\JsonRespons ]); $domain = $validated['domain']; - // XXX: this same logic is in quickstatements.php and platform api WikiController backend try { $wiki = Wiki::with(['wikiDb', 'wikiQueryserviceNamespace', 'settings'])->firstWhere('domain', $domain); } catch (\Exception $e) {