get(SolrReindexHandler::class); } /** * @param SS_HTTPRequest $request */ public function run($request) { parent::run($request); $this->extend('updateBeforeSolrReindexTask', $request); // Reset state $originalState = SearchVariant::current_state(); $this->doReindex($request); SearchVariant::activate_state($originalState); $this->extend('updateAfterSolrReindexTask', $request); } /** * @param SS_HTTPRequest $request */ protected function doReindex($request) { $class = $request->getVar('class'); $index = $request->getVar('index'); //find the index classname by IndexName // this is for when index names do not match the class name (this can be done by overloading getIndexName() on // indexes if ($index && !ClassInfo::exists($index)) { foreach (ClassInfo::subclassesFor(SolrIndex::class) as $solrIndexClass) { $reflection = new ReflectionClass($solrIndexClass); //skip over abstract classes if (!$reflection->isInstantiable()) { continue; } //check the indexname matches the index passed to the request if (!strcasecmp(singleton($solrIndexClass)->getIndexName() ?? '', $index ?? '')) { //if we match, set the correct index name and move on $index = $solrIndexClass; break; } } } // Check if we are re-indexing a single group // If not using queuedjobs, we need to invoke Solr_Reindex as a separate process // Otherwise each group is processed via a SolrReindexGroupJob $groups = $request->getVar('groups'); $handler = $this->getHandler(); if ($groups) { // Run grouped batches (id % groups = group) $group = $request->getVar('group'); $indexInstance = singleton($index); $state = json_decode($request->getVar('variantstate') ?? '', true); $handler->runGroup($this->getLogger(), $indexInstance, $state, $class, $groups, $group); return; } // If run at the top level, delegate to appropriate handler $taskName = $this->config()->segment ?: get_class($this); $handler->triggerReindex($this->getLogger(), $this->config()->recordsPerRequest, $taskName, $class); } }