-
Notifications
You must be signed in to change notification settings - Fork 3
chore: Backend WikiController cleanup #1013
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,28 +7,22 @@ | |
| 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', | ||
| ]); | ||
|
|
||
| // XXX: this same logic is in quickstatements.php and platform api WikiController backend | ||
| $domain = $validated['domain']; | ||
| 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); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. complement: |
||
| } 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); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| <?php | ||
|
|
||
| namespace Tests\Routes\Backend; | ||
|
|
||
| use App\Wiki; | ||
| use App\WikiDb; | ||
| use Illuminate\Foundation\Testing\RefreshDatabase; | ||
| use Tests\TestCase; | ||
|
|
||
| class WikiControllerTest extends TestCase { | ||
| use RefreshDatabase; | ||
|
|
||
| protected $route = '/backend/wiki/getWikiForDomain'; | ||
|
|
||
| private function createWiki(string $domain) { | ||
| $wiki = Wiki::factory()->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); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I did a bit of digging (e.g. in quickstatements.php) to see if I could find what this was about or where it is used and didn't succeed.
I guess this can go but I'm still a bit unsure if it's needed somewhere special (e.g. for building the
.sqlor some mystry place.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this was for special curl handling in case of running in the docker compose setup wbstack/magnustools#18
I don't think usage of magnustools is playing a role in creating the mw/wikibase sql schema