33namespace App \Console \Commands ;
44
55use App \Constants \MediawikiNamespace ;
6+ use App \Jobs \SpawnQueryserviceUpdaterJob ;
7+ use App \QueryserviceNamespace ;
68use App \Traits ;
9+ use App \Wiki ;
10+ use App \WikiSetting ;
711use Illuminate \Console \Command ;
8- use Illuminate \Support \Facades \Http ;
912use Illuminate \Support \Facades \Log ;
1013use Illuminate \Support \Facades \Queue ;
11- use App \Wiki ;
12- use App \WikiSetting ;
13- use App \QueryserviceNamespace ;
14- use App \Jobs \SpawnQueryserviceUpdaterJob ;
1514
16- class RebuildQueryserviceData extends Command
17- {
15+ class RebuildQueryserviceData extends Command {
1816 use Traits \PageFetcher;
1917
2018 protected $ signature = 'wbs-qs:rebuild {--domain=*} {--chunkSize=50} {--queueName=manual-intervention} {--sparqlUrlFormat=http://queryservice.default.svc.cluster.local:9999/bigdata/namespace/%s/sparql} ' ;
2119
2220 protected $ description = 'Rebuild the queryservice data for a certain wiki or all wikis ' ;
2321
2422 protected int $ chunkSize ;
23+
2524 protected string $ sparqlUrlFormat ;
25+
2626 protected string $ queueName ;
2727
28- public function handle ()
29- {
28+ public function handle () {
3029 $ this ->chunkSize = intval ($ this ->option ('chunkSize ' ));
3130 $ this ->sparqlUrlFormat = $ this ->option ('sparqlUrlFormat ' );
3231 $ this ->queueName = $ this ->option ('queueName ' );
33- $ this ->apiUrl = getenv ('PLATFORM_MW_BACKEND_HOST ' ). '/w/api.php ' ;
32+ $ this ->apiUrl = getenv ('PLATFORM_MW_BACKEND_HOST ' ) . '/w/api.php ' ;
3433
3534 $ wikiDomains = $ this ->option ('domain ' );
3635 $ exitCode = 0 ;
@@ -48,7 +47,7 @@ public function handle()
4847 $ sparqlUrl = $ this ->getSparqlUrl ($ wiki );
4948 } catch (\Exception $ ex ) {
5049 Log::error (
51- 'Failed to get prerequisites for enqueuing wiki ' . $ wiki ->domain . ', will not dispatch jobs. ' ,
50+ 'Failed to get prerequisites for enqueuing wiki ' . $ wiki ->domain . ', will not dispatch jobs. ' ,
5251 [$ ex ],
5352 );
5453 $ exitCode = 1 ;
@@ -66,24 +65,24 @@ public function handle()
6665 }
6766 $ jobTotal += count ($ entityChunks );
6867 $ processedWikis += 1 ;
69- Log::info ('Dispatched ' . count ($ entityChunks ). ' job(s) for wiki ' . $ wiki ->domain . '. ' );
68+ Log::info ('Dispatched ' . count ($ entityChunks ) . ' job(s) for wiki ' . $ wiki ->domain . '. ' );
7069 }
7170
7271 Log::info (
73- 'Done. Jobs dispatched: ' . $ jobTotal. ' Wikis processed: ' . $ processedWikis. ' Wikis skipped: ' . $ skippedWikis
72+ 'Done. Jobs dispatched: ' . $ jobTotal . ' Wikis processed: ' . $ processedWikis . ' Wikis skipped: ' . $ skippedWikis
7473 );
74+
7575 return $ exitCode ;
7676 }
7777
78- private function getEntitiesForWiki (Wiki $ wiki ): array
79- {
78+ private function getEntitiesForWiki (Wiki $ wiki ): array {
8079 $ items = $ this ->fetchPagesInNamespace ($ wiki ->domain , MediawikiNamespace::item);
8180 $ properties = $ this ->fetchPagesInNamespace ($ wiki ->domain , MediawikiNamespace::property);
8281
8382 $ lexemesSetting = WikiSetting::where (
8483 [
8584 'wiki_id ' => $ wiki ->id ,
86- 'name ' => WikiSetting::wwExtEnableWikibaseLexeme
85+ 'name ' => WikiSetting::wwExtEnableWikibaseLexeme,
8786 ],
8887 )->first ();
8988 $ hasLexemesEnabled = $ lexemesSetting !== null && $ lexemesSetting ->value === '1 ' ;
@@ -93,22 +92,22 @@ private function getEntitiesForWiki (Wiki $wiki): array
9392
9493 $ merged = array_merge ($ items , $ properties , $ lexemes );
9594 $ this ->stripPrefixes ($ merged );
95+
9696 return $ merged ;
9797 }
9898
99- private function getSparqlUrl (Wiki $ wiki ): string
100- {
99+ private function getSparqlUrl (Wiki $ wiki ): string {
101100 $ match = QueryserviceNamespace::where (['wiki_id ' => $ wiki ->id ])->first ();
102101 if (!$ match ) {
103102 throw new \Exception (
104- 'Unable to find queryservice namespace record for wiki ' . $ wiki ->domain
103+ 'Unable to find queryservice namespace record for wiki ' . $ wiki ->domain
105104 );
106105 }
106+
107107 return sprintf ($ this ->sparqlUrlFormat , $ match ->namespace );
108108 }
109109
110- private static function stripPrefixes (array &$ items ): void
111- {
110+ private static function stripPrefixes (array &$ items ): void {
112111 foreach ($ items as &$ item ) {
113112 $ e = explode (': ' , $ item );
114113 $ item = end ($ e );
0 commit comments