diff --git a/resources/sql/autopatches/20190412.dashboard.13.rebuild.php b/resources/sql/autopatches/20190412.dashboard.13.rebuild.php new file mode 100644 --- /dev/null +++ b/resources/sql/autopatches/20190412.dashboard.13.rebuild.php @@ -0,0 +1,7 @@ + 'infrastructure/query/order/PhabricatorQueryOrderVector.php', 'PhabricatorQuickSearchEngineExtension' => 'applications/search/engineextension/PhabricatorQuickSearchEngineExtension.php', 'PhabricatorRateLimitRequestExceptionHandler' => 'aphront/handler/PhabricatorRateLimitRequestExceptionHandler.php', + 'PhabricatorRebuildIndexesWorker' => 'applications/search/worker/PhabricatorRebuildIndexesWorker.php', 'PhabricatorRecaptchaConfigOptions' => 'applications/config/option/PhabricatorRecaptchaConfigOptions.php', 'PhabricatorRedirectController' => 'applications/base/controller/PhabricatorRedirectController.php', 'PhabricatorRefreshCSRFController' => 'applications/auth/controller/PhabricatorRefreshCSRFController.php', @@ -10503,6 +10504,7 @@ ), 'PhabricatorQuickSearchEngineExtension' => 'PhabricatorDatasourceEngineExtension', 'PhabricatorRateLimitRequestExceptionHandler' => 'PhabricatorRequestExceptionHandler', + 'PhabricatorRebuildIndexesWorker' => 'PhabricatorWorker', 'PhabricatorRecaptchaConfigOptions' => 'PhabricatorApplicationConfigOptions', 'PhabricatorRedirectController' => 'PhabricatorController', 'PhabricatorRefreshCSRFController' => 'PhabricatorAuthController', diff --git a/src/applications/search/worker/PhabricatorRebuildIndexesWorker.php b/src/applications/search/worker/PhabricatorRebuildIndexesWorker.php new file mode 100644 --- /dev/null +++ b/src/applications/search/worker/PhabricatorRebuildIndexesWorker.php @@ -0,0 +1,44 @@ + $query_class, + ), + array( + 'priority' => parent::PRIORITY_INDEX, + )); + } + + protected function doWork() { + $viewer = PhabricatorUser::getOmnipotentUser(); + + $data = $this->getTaskData(); + $query_class = idx($data, 'queryClass'); + + try { + $query = newv($query_class, array()); + } catch (Exception $ex) { + throw new PhabricatorWorkerPermanentFailureException( + pht( + 'Unable to instantiate query class "%s": %s', + $query_class, + $ex->getMessage())); + } + + $query->setViewer($viewer); + + $iterator = new PhabricatorQueryIterator($query); + foreach ($iterator as $object) { + PhabricatorSearchWorker::queueDocumentForIndexing( + $object->getPHID(), + array( + 'force' => true, + )); + } + } + +} diff --git a/src/infrastructure/daemon/workers/__tests__/PhabricatorWorkerTestCase.php b/src/infrastructure/daemon/workers/__tests__/PhabricatorWorkerTestCase.php --- a/src/infrastructure/daemon/workers/__tests__/PhabricatorWorkerTestCase.php +++ b/src/infrastructure/daemon/workers/__tests__/PhabricatorWorkerTestCase.php @@ -8,6 +8,20 @@ ); } + protected function willRunOneTest($test) { + parent::willRunOneTest($test); + + // Before we run these test cases, clear the queue. After D20412, we may + // have queued tasks from migrations. + $task_table = new PhabricatorWorkerActiveTask(); + $conn = $task_table->establishConnection('w'); + + queryfx( + $conn, + 'TRUNCATE %R', + $task_table); + } + public function testLeaseTask() { $task = $this->scheduleTask(); $this->expectNextLease($task, pht('Leasing should work.'));