grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026documentifier = new JsonSerializerDocumentifier(); $this->modulesToIndex = SearchWrapper::getModules(); $this->setupLogger(); } /** * Returns the short name (class name, without namespace) of the current Indexer. * * @return string */ public function getIndexerName() { return $this->getObjectClassName($this); } /** * Performs the indexing procedures for the whole database. * * All modules specified in `getModulesToIndex()` must be indexed. * This method should adhere to the options set in the indexer, such as partial indexing. * * @see AbstractIndexer:getModulesToIndex * @return void */ abstract public function index(); /** * Indexes a single module. * * If `$differentialIndexingEnabled` is set to `false` all beans in that module must be indexed. * * If `$differentialIndexingEnabled` is set to `true`, it should only perform indexing on beans * that have been created/modified/deleted after the last indexing run. * Additionally, beans that have been removed must be removed from the index too. * * @param string $module the name of the module, e.g. Accounts, Contacts, etc. * * @return void */ abstract public function indexModule($module); /** * Indexes a single bean. * * @param \SugarBean $bean * * @return void */ abstract public function indexBean(\SugarBean $bean); /** * Indexes an array of SugarBeans. * * This should not take in account of the differential indexing. * * @param string $module name of the module, e.g. Accounts, Contacts, etc. * @param \SugarBean[] $beans * * @return void */ abstract public function indexBeans($module, array $beans); /** * Removes a bean from the index. * * @param \SugarBean $bean * * @return void */ abstract public function removeBean(\SugarBean $bean); /** * Removes an array of beans from the index. * * @param array $beans * * @return void */ abstract public function removeBeans(array $beans); /** * Deletes all the records from the index. * * @return void */ abstract public function removeIndex(); /** * Returns whether the next indexing should be performed differentially or not. * * If it is set to `true`, the next indexing should only be performed on beans * that have been created/modified/deleted after the last indexing run. * Additionally, beans that have been removed must be removed from the index too. * * @return bool */ public function isDifferentialIndexing() { return $this->differentialIndexing; } /** * Sets whether the next indexing should be performed differentially or not. * * @param bool $differentialIndexing * * @see isDifferentialIndexing() */ public function setDifferentialIndexing($differentialIndexing) { $this->differentialIndexing = boolval($differentialIndexing); } /** * Returns the currently set Documentifier. * * @return AbstractDocumentifier */ public function getDocumentifier() { return $this->documentifier; } /** * Sets the documentifier to use for the future index runs. * * The documentifier converts a SugarBean into a index-friendly document. * * @param AbstractDocumentifier $documentifier */ public function setDocumentifier(AbstractDocumentifier $documentifier) { $this->documentifier = $documentifier; } /** * Returns the short (not fully qualified) name of the selected documentifier, i.e. the class name. * * @return string */ public function getDocumentifierName() { return $this->getObjectClassName($this->documentifier); } /** * Returns the modules that have to be indexed. * * This can be overridden in subclasses to index different modules. * * @return string[] */ public function getModulesToIndex() { return $this->modulesToIndex; } /** * Overrides the list of modules that have to be indexed for the next indexing runs. * * @param string[] $modules */ public function setModulesToIndex(array $modules) { if ($modules === null) { throw new InvalidArgumentException('Modules cannot be `null`.'); } if (isset($this->logger)) { $this->logger->debug('Modules have been set to ' . json_encode($modules)); } $this->modulesToIndex = $modules; } /** * Adds one or more module to index for the next indexing runs. * * @param string|string[] $modules */ public function addModulesToIndex($modules) { if (is_array($modules)) { $this->modulesToIndex = array_merge($this->modulesToIndex, $modules); return; } if (is_string($modules)) { $this->modulesToIndex[] = $modules; return; } throw new InvalidArgumentException("Wrong type provided to AddModulesToIndex"); } /** * Retrieves the Monolog instance. This can be used to provide additional logging in the Indexer channel. * * @return Logger */ public function getLogger() { return $this->logger; } /** * Sets up the internal logger. */ protected function setupLogger() { $this->logger = new Logger($this->getIndexerName()); // Set up SugarLog handler (this will forward messages to the default logging) $this->logger->pushHandler(new SugarLoggerHandler()); // Set up Monolog logfile logger try { $this->logger->pushHandler(new StreamHandler($this->logFile)); } catch (\Exception $exception) { $this->logger->error('Failed to create indexer log stream handler.'); $this->logger->error($exception); } // Set up Monolog CLI handler try { $this->logger->pushHandler(new CliLoggerHandler()); } catch (\Exception $exception) { $this->logger->error('Failed to create CLI logger handler.'); $this->logger->error($exception); } } /** * Method to retrieve the (short) class name of an object. * * @param object $obj * * @return string */ private function getObjectClassName($obj) { try { $reflect = new ReflectionClass($obj); return $reflect->getShortName(); } catch (\ReflectionException $exception) { return get_class($obj); } } }