Skip to content

Commit 7c192cd

Browse files
committed
PoC: Add reuse_prototype field to /wiki API endpoint
Bug: T421877
1 parent e561547 commit 7c192cd

3 files changed

Lines changed: 28 additions & 1 deletion

File tree

app/Http/Controllers/PublicWikiController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function index(Request $request) {
2929
]);
3030

3131
$params = array_merge(self::$defaultParams, $request->input());
32-
$query = Wiki::query();
32+
$query = Wiki::query()->with('wikiLatestProfile');
3333

3434
if (array_key_exists('is_featured', $params)) {
3535
$query = $query->where([

app/Http/Resources/PublicWikiResource.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,21 @@ public function toArray($request): array {
1616
'sitename' => $this->sitename,
1717
'wiki_site_stats' => $this->wikiSiteStats,
1818
'logo_url' => $logoSetting ? $logoSetting->value : null,
19+
20+
// TODO: delete these three fields before merging; here to easily prove the `reuse_prototype` logic works
21+
'test_purpose' => $this->wikiLatestProfile ? $this->wikiLatestProfile->purpose : null,
22+
'test_temporality' => $this->wikiLatestProfile ? $this->wikiLatestProfile->temporality : null,
23+
'test_audience' => $this->wikiLatestProfile ? $this->wikiLatestProfile->audience : null,
24+
25+
// TODO: As the `$this->wikiLatestProfile` property can be accessed regardless of if
26+
// `->with('wikiLatestProfile')` is used in the controller, we are unable to return null if
27+
// `$this->wikiLatestProfile` isn't set. We should either look into addressing this, or remove the
28+
// `$this->wikiLatestProfile ? ... : null` conditional.
29+
'reuse_prototype' => $this->wikiLatestProfile
30+
? $this->wikiLatestProfile->purpose === 'data_hub'
31+
&& $this->wikiLatestProfile->temporality === 'permanent'
32+
&& $this->wikiLatestProfile->audience === 'wide'
33+
: null,
1934
];
2035
}
2136
}

app/Providers/AppServiceProvider.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use App\Http\Curl\CurlRequest;
66
use App\Http\Curl\HttpRequest;
7+
use Illuminate\Database\Events\QueryExecuted;
78
use Illuminate\Queue\Events\JobFailed;
89
use Illuminate\Support\Facades\Queue;
910
use Illuminate\Support\ServiceProvider;
@@ -25,5 +26,16 @@ public function boot(): void {
2526
$wrappedException = new \Exception("Executing Job '$name' failed.", 1, $event->exception);
2627
report($wrappedException);
2728
});
29+
30+
// TODO: delete this listener before merging or is it useful to keep in the local environment?
31+
if ($this->app->environment('local')) {
32+
\Event::listen(QueryExecuted::class, function (QueryExecuted $query) {
33+
\Log::debug('Query Executed: ', [
34+
'sql' => $query->sql,
35+
'bindings' => $query->bindings,
36+
'connection' => $query->connectionName,
37+
]);
38+
});
39+
}
2840
}
2941
}

0 commit comments

Comments
 (0)