getResourceIterator($this->getLastIndexTime(), $time); $indexIterator = new IndexIterator($iterator); $indexIterator->setServiceLocator($this->getServiceLocator()); $searchService = $this->getServiceLocator()->get(Search::SERVICE_ID); $result = $searchService->index($indexIterator); $this->updateLastIndexTime($time); $this->logDebug($result . ' resources have been indexed by ' . static::class); return $result; } /** * @return \Iterator * @param boolean $sinceLast load resources updated/created since last indexation */ protected function getResourceIterator($from = null, $to = null) { if ($from === null || $from === 0) { return parent::getResourceIterator(); } if ($to === null) { $to = microtime(true); } $search = $this->getServiceLocator()->get(ComplexSearchService::class); $queryBuilder = $search->query(); $criteria = $queryBuilder->newQuery(); $criteria->addCriterion( TaoOntology::PROPERTY_UPDATED_AT, SupportedOperatorHelper::BETWEEN, [$from, $to] ); $iterator = new ResourceIterator($this->getIndexedClasses(), $criteria); $iterator->setServiceLocator($this->getServiceLocator()); return $iterator; } /** * Update time of the last indexation * @throws \common_Exception */ private function updateLastIndexTime($time) { $this->getPersistence()->set(self::LAST_LAUNCH_TIME_KEY, $time); } /** * Get time of the last indexation. 0 if no time in the storage. * @return integer */ private function getLastIndexTime() { $result = $this->getPersistence()->get(self::LAST_LAUNCH_TIME_KEY); return $result ? $result : 0; } /** * @return \common_persistence_KeyValuePersistence * @throws */ private function getPersistence() { if (!$this->hasOption(self::OPTION_LASTRUN_STORE)) { throw new \InvalidArgumentException('Persistence for ' . self::SERVICE_ID . ' is not configured'); } $persistenceId = $this->getOption(self::OPTION_LASTRUN_STORE); return $this->getServiceLocator()->get(\common_persistence_Manager::SERVICE_ID)->getPersistenceById($persistenceId); } }