From eda240661a42ec85e7ca31fe2c4d580bff77aa92 Mon Sep 17 00:00:00 2001 From: dena Date: Mon, 24 Nov 2025 17:43:13 +0100 Subject: [PATCH 1/7] add backend route setWikiDbVersion --- routes/backend.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/routes/backend.php b/routes/backend.php index 478a4036..0be47914 100644 --- a/routes/backend.php +++ b/routes/backend.php @@ -11,6 +11,9 @@ $router->get('healthz', fn () => "It's Alive"); $router->get('getWikiHostsForDomain', ['uses' => 'MediaWikiHostsController@getWikiHostsForDomain']); +// PUT +$router->put('setWikiDbVersion', ['uses' => 'WikiDbVersionController@updateWikiDbVersion']); + $router->group(['prefix' => 'ingress'], function () use ($router) { // GET $router->get('getWikiVersionForDomain', ['uses' => 'IngressController@getWikiVersionForDomain']); From 8aaae5dd7582088e04ae3e055699b13d90a2b224 Mon Sep 17 00:00:00 2001 From: dena Date: Mon, 24 Nov 2025 17:43:31 +0100 Subject: [PATCH 2/7] add WikiDbVersionControllerTest --- .../Backend/WikiDbVersionControllerTest.php | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 tests/Routes/Backend/WikiDbVersionControllerTest.php diff --git a/tests/Routes/Backend/WikiDbVersionControllerTest.php b/tests/Routes/Backend/WikiDbVersionControllerTest.php new file mode 100644 index 00000000..4a1a6d54 --- /dev/null +++ b/tests/Routes/Backend/WikiDbVersionControllerTest.php @@ -0,0 +1,79 @@ +create(['domain' => $domain]); + WikiDb::create([ + 'name' => $domain, + 'user' => 'someUser', + 'password' => 'somePassword', + 'version' => $version, + 'prefix' => 'somePrefix', + 'wiki_id' => $wiki->id, + ]); + } + + public function testSetWikiDbVersionSuccess() { + $targetDbVersion = self::VALID_WIKI_DB_VERSION_STRING_143; + $wikiDomain = 'coffeebase.wikibase.cloud'; + + $this->createWiki($wikiDomain, self::VALID_WIKI_DB_VERSION_STRING_139); + + $this->putJson("{$this->route}?domain={$wikiDomain}&dbVersion={$targetDbVersion}") + ->assertStatus(200) + ->assertJson([ + 'result' => 'success', + ]); + } + + public function testSetWikiDbVersionWikiNotfound() { + $targetDbVersion = self::VALID_WIKI_DB_VERSION_STRING_143; + $wikiDomain = 'notFound.wikibase.cloud'; + + $this->putJson("{$this->route}?domain={$wikiDomain}&dbVersion={$targetDbVersion}") + ->assertStatus(404); + } + + public function testSetWikiDbVersionUnknownDbVersion() { + $targetDbVersion = 'unknownVersion'; + $wikiDomain = 'coffeebase.wikibase.cloud'; + + $this->createWiki($wikiDomain, self::VALID_WIKI_DB_VERSION_STRING_139); + + $this->putJson("{$this->route}?domain={$wikiDomain}&dbVersion={$targetDbVersion}") + ->assertStatus(400); + } + + public function testSetWikiDbVersionMissingDbVersion() { + $wikiDomain = 'coffeebase.wikibase.cloud'; + + $this->createWiki($wikiDomain, self::VALID_WIKI_DB_VERSION_STRING_139); + + $this->putJson("{$this->route}?domain={$wikiDomain}") + ->assertStatus(422); + } + + public function testSetWikiDbVersionMissingWikiDomain() { + $targetDbVersion = self::VALID_WIKI_DB_VERSION_STRING_143; + $wikiDomain = 'coffeebase.wikibase.cloud'; + + $this->createWiki($wikiDomain, self::VALID_WIKI_DB_VERSION_STRING_139); + + $this->putJson("{$this->route}?dbVersion={$targetDbVersion}") + ->assertStatus(422); + } +} From ae995121e1d71df1f07abc3d18c25a98c5854ff1 Mon Sep 17 00:00:00 2001 From: dena Date: Mon, 24 Nov 2025 17:44:03 +0100 Subject: [PATCH 3/7] Add Backend/WikiDbVersionController --- .../Backend/WikiDbVersionController.php | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100644 app/Http/Controllers/Backend/WikiDbVersionController.php diff --git a/app/Http/Controllers/Backend/WikiDbVersionController.php b/app/Http/Controllers/Backend/WikiDbVersionController.php new file mode 100644 index 00000000..abfa7136 --- /dev/null +++ b/app/Http/Controllers/Backend/WikiDbVersionController.php @@ -0,0 +1,44 @@ + '139', + 'mw1.43-wbs1' => '143', + ]; + + public function updateWikiDbVersion(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 (!array_key_exists($targetDbVersion, self::DB_VERSION_TO_MW_VERSION)) { + 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); + } +} From e472fabc7ef18a142740bbff2726ac46a080d933 Mon Sep 17 00:00:00 2001 From: dena Date: Mon, 24 Nov 2025 17:44:26 +0100 Subject: [PATCH 4/7] formatting --- tests/Routes/Backend/WikiDbVersionControllerTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/Routes/Backend/WikiDbVersionControllerTest.php b/tests/Routes/Backend/WikiDbVersionControllerTest.php index 4a1a6d54..92a8d305 100644 --- a/tests/Routes/Backend/WikiDbVersionControllerTest.php +++ b/tests/Routes/Backend/WikiDbVersionControllerTest.php @@ -11,6 +11,7 @@ class WikiDbVersionControllerTest extends TestCase { use RefreshDatabase; const VALID_WIKI_DB_VERSION_STRING_139 = 'mw1.39-wbs1'; + const VALID_WIKI_DB_VERSION_STRING_143 = 'mw1.43-wbs1'; protected $route = '/backend/setWikiDbVersion'; From 46f22d45c96aa68504dd30b19e306690d5bc9a7f Mon Sep 17 00:00:00 2001 From: dena Date: Mon, 24 Nov 2025 17:48:49 +0100 Subject: [PATCH 5/7] add link to duplication --- app/Http/Controllers/Backend/WikiDbVersionController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/app/Http/Controllers/Backend/WikiDbVersionController.php b/app/Http/Controllers/Backend/WikiDbVersionController.php index abfa7136..8d60841d 100644 --- a/app/Http/Controllers/Backend/WikiDbVersionController.php +++ b/app/Http/Controllers/Backend/WikiDbVersionController.php @@ -8,6 +8,7 @@ class WikiDbVersionController extends Controller { // TODO Deduplicate Version Mapping https://phabricator.wikimedia.org/T409078 + // https://github.com/wbstack/api/blob/bcbea7ccdd78708e36b0da3e627e00003da9932d/app/Services/MediaWikiHostResolver.php#L21 private const DB_VERSION_TO_MW_VERSION = [ 'mw1.39-wbs1' => '139', 'mw1.43-wbs1' => '143', From 0d6fe708d49211e4c8af6b1cf664befb2777eba8 Mon Sep 17 00:00:00 2001 From: dena Date: Tue, 25 Nov 2025 07:30:41 +0100 Subject: [PATCH 6/7] comments --- app/Http/Controllers/Backend/WikiDbVersionController.php | 3 +-- app/Services/MediaWikiHostResolver.php | 1 + 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Http/Controllers/Backend/WikiDbVersionController.php b/app/Http/Controllers/Backend/WikiDbVersionController.php index 8d60841d..3ecf214b 100644 --- a/app/Http/Controllers/Backend/WikiDbVersionController.php +++ b/app/Http/Controllers/Backend/WikiDbVersionController.php @@ -7,8 +7,7 @@ use Illuminate\Http\Request; class WikiDbVersionController extends Controller { - // TODO Deduplicate Version Mapping https://phabricator.wikimedia.org/T409078 - // https://github.com/wbstack/api/blob/bcbea7ccdd78708e36b0da3e627e00003da9932d/app/Services/MediaWikiHostResolver.php#L21 + // keep in sync with App\Services\MediaWikiHostResolver private const DB_VERSION_TO_MW_VERSION = [ 'mw1.39-wbs1' => '139', 'mw1.43-wbs1' => '143', diff --git a/app/Services/MediaWikiHostResolver.php b/app/Services/MediaWikiHostResolver.php index a07e6f9a..342ec737 100644 --- a/app/Services/MediaWikiHostResolver.php +++ b/app/Services/MediaWikiHostResolver.php @@ -17,6 +17,7 @@ class UnknownWikiDomainException extends Exception {} class MediaWikiHostResolver { // TODO: Move this mapping to a config file so that MW updates do not require code changes here. + // keep in sync with App\Http\Controllers\Backend\WikiDbVersionController /** @var array Map of DB version strings to MediaWiki version strings */ private const DB_VERSION_TO_MW_VERSION = [ 'mw1.39-wbs1' => '139', From 99b9fb4ec1acea69cca0599b54f1f0234f9a24cd Mon Sep 17 00:00:00 2001 From: dena Date: Tue, 25 Nov 2025 10:24:54 +0100 Subject: [PATCH 7/7] test successful change of wikiDb version string --- tests/Routes/Backend/WikiDbVersionControllerTest.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/tests/Routes/Backend/WikiDbVersionControllerTest.php b/tests/Routes/Backend/WikiDbVersionControllerTest.php index 92a8d305..6be65e96 100644 --- a/tests/Routes/Backend/WikiDbVersionControllerTest.php +++ b/tests/Routes/Backend/WikiDbVersionControllerTest.php @@ -26,19 +26,25 @@ private function createWiki(string $domain, string $version) { 'prefix' => 'somePrefix', 'wiki_id' => $wiki->id, ]); + + return $wiki; } public function testSetWikiDbVersionSuccess() { $targetDbVersion = self::VALID_WIKI_DB_VERSION_STRING_143; $wikiDomain = 'coffeebase.wikibase.cloud'; - $this->createWiki($wikiDomain, self::VALID_WIKI_DB_VERSION_STRING_139); + $wiki = $this->createWiki($wikiDomain, self::VALID_WIKI_DB_VERSION_STRING_139); $this->putJson("{$this->route}?domain={$wikiDomain}&dbVersion={$targetDbVersion}") ->assertStatus(200) ->assertJson([ 'result' => 'success', ]); + + $newDbVersion = Wiki::with('wikiDb')->firstWhere('id', $wiki->id)->wikiDb->version; + + $this->assertSame($targetDbVersion, $newDbVersion); } public function testSetWikiDbVersionWikiNotfound() {