EBernhardson has submitted this change and it was merged.

Change subject: Allow QueriesManager to run with no User available
......................................................................


Allow QueriesManager to run with no User available

When running console commands no user will be available. Rather than
bailing when creating it, due to passing null where a User is expected,
delay the error until calling something that actually requires a User
instance.

Change-Id: I61dec64f743e0da890d7d6f694af5e70fb42cb1a
---
M src/RelevanceScoring/QueriesManager.php
1 file changed, 18 insertions(+), 3 deletions(-)

Approvals:
  EBernhardson: Verified; Looks good to me, approved



diff --git a/src/RelevanceScoring/QueriesManager.php 
b/src/RelevanceScoring/QueriesManager.php
index 962bf43..cda4893 100644
--- a/src/RelevanceScoring/QueriesManager.php
+++ b/src/RelevanceScoring/QueriesManager.php
@@ -27,7 +27,7 @@
      */
     const RELIABILITY_BAD = 'bad';
 
-    /** @var User */
+    /** @var User|null */
     private $user;
     /** @var ResultsRepository */
     private $resultsRepository;
@@ -47,7 +47,7 @@
     private $queuePriority;
 
     /**
-     * @param User                   $user
+     * @param User|null              $user
      * @param QueriesRepository      $queriesRepo
      * @param ResultsRepository      $resultsRepo
      * @param ScoresRepository       $scoresRepo
@@ -58,7 +58,7 @@
      * @param int                    $queuePriority
      */
     public function __construct(
-        User $user,
+        User $user = null,
         QueriesRepository $queriesRepo,
         ResultsRepository $resultsRepo,
         ScoresRepository $scoresRepo,
@@ -81,6 +81,9 @@
 
     public function nextQueryId()
     {
+        if ( $this->user === null ) {
+            throw new \RuntimeException( 'No user available' );
+        }
         return $this->scoringQueueRepo->pop($this->user);
     }
 
@@ -91,6 +94,9 @@
 
     public function getQueryResults($queryId)
     {
+        if ( $this->user === null ) {
+            throw new \RuntimeException( 'No user available' );
+        }
         $maybeResults = $this->resultsRepo->getQueryResults($queryId);
         if ($maybeResults->isEmpty()) {
             return $maybeResults;
@@ -106,12 +112,18 @@
 
     public function skipQuery($queryId)
     {
+        if ( $this->user === null ) {
+            throw new \RuntimeException( 'No user available' );
+        }
         $this->queriesRepo->markQuerySkipped($this->user, $queryId);
         $this->scoringQueueRepo->unassignUser($this->user);
     }
 
     public function saveScores($queryId, array $scores)
     {
+        if ( $this->user === null ) {
+            throw new \RuntimeException( 'No user available' );
+        }
         $this->scoresRepo->storeQueryScores($this->user, $queryId, $scores);
         $this->scoringQueueRepo->markScored($this->user, $queryId);
         $this->updateReliability($queryId);
@@ -119,6 +131,9 @@
 
     public function updateUserStorage()
     {
+        if ( $this->user === null ) {
+            throw new \RuntimeException( 'No user available' );
+        }
         $this->userRepo->updateUser($this->user);
     }
     /**

-- 
To view, visit https://gerrit.wikimedia.org/r/320263
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I61dec64f743e0da890d7d6f694af5e70fb42cb1a
Gerrit-PatchSet: 1
Gerrit-Project: wikimedia/discovery/discernatron
Gerrit-Branch: master
Gerrit-Owner: EBernhardson <ebernhard...@wikimedia.org>
Gerrit-Reviewer: EBernhardson <ebernhard...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to