/** * @param string $localSite The wikiId to add/remove from local_sites_with_dupe * @param string $indexName The name of the index to perform updates to * @param aray $otherActions A list of arrays each containing the id within elasticsearch ('id') and the article id within $localSite ('articleId') * @return Status */ public function sendOtherIndexUpdates($localSite, $indexName, array $otherActions) { if (!$this->areIndexesAvailableForWrites(array($indexName), true)) { return Status::newFatal('cirrussearch-indexes-frozen'); } $client = $this->connection->getClient(); $status = Status::newGood(); foreach (array_chunk($otherActions, 30) as $updates) { $bulk = new \Elastica\Bulk($client); $articleIDs = array(); foreach ($updates as $update) { $title = Title::makeTitle($update['ns'], $update['dbKey']); $action = $this->decideRequiredSetAction($title); $this->log->debug("Performing `{$action}` for {$update['dbKey']} in ns {$update['ns']} on {$localSite} against id {$update['id']} in {$indexName}"); $script = new \Elastica\Script('super_detect_noop', array('source' => array('local_sites_with_dupe' => array($action => $localSite)), 'handlers' => array('local_sites_with_dupe' => 'set')), 'native'); $script->setId($update['id']); $script->setParam('_type', 'page'); $script->setParam('_index', $indexName); $bulk->addScript($script, 'update'); $titles[] = $title; } // Execute the bulk update $exception = null; try { $this->start("updating {numBulk} documents in other indexes", array('numBulk' => count($updates))); $bulk->send(); } catch (\Elastica\Exception\Bulk\ResponseException $e) { if (!$this->bulkResponseExceptionIsJustDocumentMissing($e)) { $exception = $e; } } catch (\Elastica\Exception\ExceptionInterface $e) { $exception = $e; } if ($exception === null) { $this->success(); } else { $this->failure($e); $this->failedLog->warning("OtherIndex update for articles: " . implode(',', $titles), array('exception' => $e)); $status->error('cirrussearch-failed-update-otherindex'); } } return $status; }