grthtrhthjhtyjytjytkergtrhtrjytjerhrfh4:24 29/09/2026searchModule($query, $module); } $end = microtime(true); $elapsed = $end - $start; return new SearchResults($results, true, $elapsed); } /** * Filters an array of table structures to only retrieve search-relevant fields. * * @param array $fields * * @return array */ protected function filterTableStructure(array $fields) { $filteredFields = []; foreach ($fields as $name => $type) { if (strpos($type, 'varchar') == 0) { $filteredFields[$name] = 'varchar'; } if (strpos($type, 'text') == 0) { $filteredFields[$name] = 'text'; } } return $filteredFields; } /** * Uses the DBManager getTableDescription method to retrieve the structure of the table in a name->type format. * * @see \DBManager::getTableDescription() * * @param string $table * * @return array */ protected function getTableStructure($table) { $descriptions = DBManagerFactory::getInstance()->getTableDescription($table); $fields = []; foreach ($descriptions as $description) { $fields[$description['name']] = $description['type']; } return $fields; } /** @inheritdoc */ protected function validateQuery(SearchQuery &$query) { parent::validateQuery($query); $query->convertEncoding(); } /** * Performs a search in a single module table and returns a list of ids. * * @param SearchQuery $query * @param string $module * * @return array */ private function searchModule(SearchQuery $query, $module) { $seed = BeanFactory::getBean($module); $table = $seed->table_name; $fields = $this->filterTableStructure($this->getTableStructure($table)); $sql = $this->makeSearchQuery($query, $table, $fields); $hits = []; $db = DBManagerFactory::getInstance(); $result = $db->query($sql); while ($row = $db->fetchRow($result)) { $hits [] = $row['id']; } return $hits; } /** * Makes the search SQL query. * * @param SearchQuery $query * @param string $table * @param array $fields * * @return string */ private function makeSearchQuery(SearchQuery $query, $table, array $fields) { $sql = 'SELECT id FROM %s WHERE %s AND deleted=0'; $wheres = []; // The database manager is not exposing any database-specific escaping functions, // so only addslashes() will be used here. $slashedString = addslashes($query->getSearchString()); foreach (array_keys($fields) as $name) { $wheres[] = sprintf("%s LIKE '%s'", $name, $slashedString); } $sql = sprintf($sql, $table, implode(' OR ', $wheres)); return $sql; } }