diff --git a/resources/sql/autopatches/20190412.dashboard.13.rebuild.php b/resources/sql/autopatches/20190412.dashboard.13.rebuild.php new file mode 100644 index 0000000000..ed32a9137f --- /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 @@ phutil_register_library_map(array( ), '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 index 0000000000..7d5cc64b0b --- /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 index 83d2585e18..976f1800a9 100644 --- a/src/infrastructure/daemon/workers/__tests__/PhabricatorWorkerTestCase.php +++ b/src/infrastructure/daemon/workers/__tests__/PhabricatorWorkerTestCase.php @@ -8,6 +8,20 @@ final class PhabricatorWorkerTestCase extends PhabricatorTestCase { ); } + 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.'));