Retrieves an optimized array structure we the monitored pageId as key and the relevant site rootIds as value.

@param string $table
@param integer $uid
@return array
3533
protected function getSiteRootsByObservedPageIds($table, $uid)
    {
        $cacheId = 'RootPageResolver' . '_' . 'getSiteRootsByObservedPageIds' . '_' . $table . '_' . $uid;
        $methodResult = $this->runtimeCache->get($cacheId);
        if (!empty($methodResult)) {
            return $methodResult;
        }

        $methodResult = $this->buildSiteRootsByObservedPageIds($table, $uid);
        $this->runtimeCache->set($cacheId, $methodResult);

        return $methodResult;
    }
361175
public function getPage(int $uid, int $languageUid = null) {
    $page   = null;
    $record = $this->pageRepository->getPage($uid);

    if (is_array($record) && !empty($record)) {
      if (in_array($record['doktype'], self::PAGE_DOKTYPES)) {
        $page        = $record;
        $languageUid = isset($languageUid) ? $languageUid : $this->languageService->getLanguageUid();

        if ($languageUid > 0) {
          $page = $this->pageRepository->getPageOverlay($page, $languageUid);
        }
      }
    }

    return $page;
  }
42493
protected function getAlternatePrimaryKeys($table)
    {
        $alternatePrimaryKey = false;
        $primaryKeys = [];
        foreach ($table['columns'] as $column) {
            $columnName = $column['COLUMN_NAME'];
            $columnKey = $column['COLUMN_KEY'];
            if ($columnKey !== 'PRI') {
                continue;
            }
            if ($columnName !== 'id') {
                $alternatePrimaryKey = true;
            }
            $primaryKeys[] = '"' . $columnName . '"';
        }
        if ($alternatePrimaryKey) {
            return $primaryKeys;
        }

        return null;
    }
55935
public function getColumns($table)
    {
        $table = $this->prefixTable($table);

        if (empty($this->queriesResultCache[ 'tableColumns' ][ $table ])) {
            $result = $this->query('PRAGMA TABLE_INFO(' . $this->protectIdentifiers($table, true, null, false) . ')');

            if ($result->count()) {
                foreach ($result as $row) {
                    // Do we know from where to get the column's name?
                    if ( ! isset($key)) {
                        if (isset($row[ 'name' ])) {
                            $key = 'name';
                        }
                    }

                    $this->queriesResultCache[ 'tableColumns' ][ $table ][ $row->offsetGet($key) ] = $row;
                }
            }
        }

        return $this->queriesResultCache[ 'tableColumns' ][ $table ];
    }
1218795
public function getParentContentUidsByUids(array $uids)
    {
        $ids = array();

        $query  = 'SELECT j.parent_uid FROM content_has_subcontent j
                   LEFT JOIN content c ON c.uid = j.content_uid
                   WHERE classname != \'BackBee\ClassContent\Element\'';

        $where = array();
        foreach ($uids as $uid) {
            $where[] = $uid;
        }

        if (count($where) > 0) {
            $query .= ' AND j.content_uid  IN ("'.implode('","', $where).'")';
            $parents = $this->getEntityManager()
                ->getConnection()
                ->executeQuery($query)->fetchAll(\PDO::FETCH_COLUMN);
            if ($parents) {
                $ids = array_merge($ids, $parents, $this->getParentContentUidsByUids($parents));
            }
        }

        return array_unique($ids);
    }
237288
public function get_indexes($table) {
        $indexes = array();
        $sql = "SHOW INDEXES FROM {$this->prefix}$table";
        $this->query_start($sql, null, SQL_QUERY_AUX);
        $result = $this->mysqli->query($sql);
        try {
            $this->query_end($result);
        } catch (dml_read_exception $e) {
            return $indexes; // table does not exist - no indexes...
        }
        if ($result) {
            while ($res = $result->fetch_object()) {
                if ($res->Key_name === 'PRIMARY') {
                    continue;
                }
                if (!isset($indexes[$res->Key_name])) {
                    $indexes[$res->Key_name] = array('unique'=>empty($res->Non_unique), 'columns'=>array());
                }
                $indexes[$res->Key_name]['columns'][$res->Seq_in_index-1] = $res->Column_name;
            }
            $result->close();
        }
        return $indexes;
    }
893000
protected function getContentObject($uid)
    {
        $contentTable = 'tt_content';
        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($contentTable);
        $queryBuilder
            ->select('*')
            ->from($contentTable)
            ->where($queryBuilder->expr()->eq('uid', $uid));
        $queryBuilder->getRestrictions()->removeAll();
        $data = $queryBuilder->execute()->fetch();

        $this->inlineHelper->addFilesToData($data, 'tt_content');
        $this->inlineHelper->addIrreToData($data);

        return $data;
    }
862448
public function getByUID($uid)
    {
        return array_filter($this->getComponents(), function ($item) use ($uid) {
            if (!$itemUid = $item->select('UID')) {
                return false;
            }
            $itemUid = current($itemUid)->getValue();

            return $uid === $itemUid;
        });
    }
1284286
public static function isDraftRecord($table, $uid)
    {
        $isWorkspaceRecord = false;

        if ((ExtensionManagementUtility::isLoaded('workspaces')) && (BackendUtility::isTableWorkspaceEnabled($table))) {
            $record = BackendUtility::getRecord($table, $uid, 'pid, t3ver_state');

            if ($record['pid'] == '-1' || $record['t3ver_state'] > 0) {
                $isWorkspaceRecord = true;
            }
        }

        return $isWorkspaceRecord;
    }
1265773
public function getPrimaryKeys($table)
    {
        $pk = [];
        $cols = $this->getColumns($table);
        if ($cols) {
            foreach ($cols as $key => $val){
                if(isset($val['is_primary']) && $val['is_primary']) {
                    $pk[] = $key;
                }
            }
        }
        
        return $pk;
    }
839038
public static function getById($uid)
    {    
		if ($uid == USER_ANONYMOUS) return new User\Anonymous();
        $fields = self::getDbConnection()->fetchAssoc( 'SELECT * FROM '.User::TABLE.' WHERE id = ?', array( $uid ) );
        if (!$fields) throw new \Exception('User:'.$uid.' is not found'); 
        return self::fetch($fields);    
  	}
999274
protected function getIdsInfo($table, $fields_info = null, &$requested_fields = null, $requested_types = null)
    {
        $idsInfo = [];
        if (empty($requested_fields)) {
            $requested_fields = [];
            /** @type ColumnSchema[] $idsInfo */
            $idsInfo = static::getPrimaryKeys($fields_info);
            foreach ($idsInfo as $info) {
                $requested_fields[] = $info->getName(true);
            }
        } else {
            if (false !== $requested_fields = static::validateAsArray($requested_fields, ',')) {
                foreach ($requested_fields as $field) {
                    $ndx = strtolower($field);
                    if (isset($fields_info[$ndx])) {
                        $idsInfo[] = $fields_info[$ndx];
                    }
                }
            }
        }

        return $idsInfo;
    }
902669
public function findItemByUid(int $uid)
    {
        $queryBuilder = $this->getQueryBuilder();
        $indexQueueItemRecord = $queryBuilder
            ->select('*')
            ->from($this->table)
            ->where($queryBuilder->expr()->eq('uid', $uid))
            ->execute()->fetch();

        if (!isset($indexQueueItemRecord['uid'])) {
            return null;
        }

        /** @var Item $item*/
        $item = GeneralUtility::makeInstance(Item::class, /** @scrutinizer ignore-type */ $indexQueueItemRecord);
        return $item;
    }
356804
public function getPrimarykey($table=null) 
    {
        if ($table) {
            return $this->getDb()->getPrimaryKey($table);
        } else {
            if (!isset($this->options['primary_key'])) {
                $pk = $this->getDb()->getPrimaryKey($this->getTableName());
                $this->options['primary_key'] = $pk;
            }
            
            return $this->options['primary_key'];
        }
    }
1044981
public function is_member_of($table, $uid)
	{
		if (!in_array($table, array('applicants', 'members', 'managers', 'invitees')))
		{
			return false;
		}

		if (!is_numeric($uid))
		{
			$uid = User::oneByUsername($uid)->get('id');
		}

		return in_array($uid, $this->get($table));
	}
1226166
public function getPageContent($uid)
    {
        // get content elements for this page
        $fields = 'uid, pid, header, bodytext, CType, sys_language_uid, header_layout, fe_group, file_collections, filelink_sorting';

        // hook to modify the page content fields
        if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyPageContentFields'])) {
            foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyPageContentFields'] as $_classRef) {
                $_procObj = &\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($_classRef);
                $_procObj->modifyPageContentFields(
                    $fields,
                    $this
                );
            }
        }

        $table = 'tt_content';
        $queryBuilder = Db::getQueryBuilder($table);
        $where = [];
        $where[] = $queryBuilder->expr()->eq(
            'pid',
            $queryBuilder->createNamedParameter(
                $uid,
                \PDO::PARAM_INT
            )
        );
        $where[] = $this->whereClauseForCType;

        // If gridelements is installed, add the uid of the container to the field list
        if (ExtensionManagementUtility::isLoaded('gridelements')) {
            $fields .= ', tt_content.tx_gridelements_container';
        }

        // Get access restrictions for this page, this access restrictions apply to all
        // content elements of this pages. Individual access restrictions
        // set for the content elements will be ignored. Use the content
        // element indexer if you need that feature!
        $pageAccessRestrictions = $this->getInheritedAccessRestrictions($uid);

        // add ke_search tags current page
        $tags = $this->pageRecords[intval($uid)]['tags'];

        // add system categories as tags
        SearchHelper::makeSystemCategoryTags($tags, $uid, $table);

        // Compile content for this page from individual content elements with
        // respect to the language.
        // While doing so, fetch also content from attached files and write
        // their content directly to the index.
        $fieldArray = GeneralUtility::trimExplode(',', $fields);
        $ttContentRows = $queryBuilder
            ->select(...$fieldArray)
            ->from($table)
            ->where(...$where)
            ->execute()
            ->fetchAll();

        $pageContent = array();
        if (count($ttContentRows)) {
            foreach ($ttContentRows as $ttContentRow) {

                // If gridelements is installed, check if the content element sits inside a gridelements container.
                // If yes, check if the container is hidden or placed outsite the page (colPos: -2).
                // this adds a query for each content element which may result in slow indexing. But simply
                // joining the tt_content table to itself does not work either, since then all content elements which
                // are not located inside a gridelement won't be indexed then.
                if (ExtensionManagementUtility::isLoaded('gridelements') && $ttContentRow['tx_gridelements_container']) {
                    $queryBuilder = Db::getQueryBuilder($table);
                    $gridelementsContainer = $queryBuilder
                        ->select(...['colPos','hidden'])
                        ->from($table)
                        ->where($queryBuilder->expr()->eq(
                            'uid',
                            $queryBuilder->createNamedParameter($ttContentRow['tx_gridelements_container'])
                        )
                        )
                        ->execute()
                        ->fetch();

                    // If there's no gridelement container found, it means it is hidden or deleted or time restricted.
                    // In this case, skip the content elements inside the gridelements container
                    if ($gridelementsContainer === FALSE) {
                        continue;
                    } else {

                        // If the colPos of the gridelement container is -2, it is not on the page, so skip it.
                        if ($gridelementsContainer['colPos'] === -2) {
                            continue;
                        }

                    }
                }

                $content = '';

                // index header
                // add header only if not set to "hidden"
                if ($ttContentRow['header_layout'] != 100) {
                    $content .= strip_tags($ttContentRow['header']) . "\n";
                }

                // index content of this content element and find attached or linked files.
                // Attached files are saved as file references, the RTE links directly to
                // a file, thus we get file objects.
                // Files go into the index no matter if "index_content_with_restrictions" is set
                // or not, that means even if protected content elements do not go into the index,
                // files do. Since each file gets it's own index entry with correct access
                // restrictons, that's no problem from a access permission perspective (in fact, it's a feature).
                if (in_array($ttContentRow['CType'], $this->fileCTypes)) {
                    $fileObjects = $this->findAttachedFiles($ttContentRow);
                } else {
                    $fileObjects = $this->findLinkedFilesInRte($ttContentRow);
                    $content .= $this->getContentFromContentElement($ttContentRow) . "\n";
                }

                // index the files found
                if (!$pageAccessRestrictions['hidden']) {
                    $this->indexFiles($fileObjects, $ttContentRow, $pageAccessRestrictions['fe_group'], $tags);
                }

                // add content from this content element to page content
                // ONLY if this content element is not access protected
                // or protected content elements should go into the index
                // by configuration.
                if ($this->indexerConfig['index_content_with_restrictions'] == 'yes'
                    || $ttContentRow['fe_group'] == ''
                    || $ttContentRow['fe_group'] == '0'
                ) {
                    $pageContent[$ttContentRow['sys_language_uid']] .= $content;
                }
            }
        } else {
            $this->counterWithoutContent++;
            return;
        }

        // make it possible to modify the indexerConfig via hook
        $additionalFields = array();
        $indexerConfig = $this->indexerConfig;

        // make it possible to modify the default values via hook
        $indexEntryDefaultValues = array(
            'type' => 'page',
            'uid' => $uid,
            'params' => '',
            'feGroupsPages' => $pageAccessRestrictions['fe_group'],
            'debugOnly' => false
        );

        // hook for custom modifications of the indexed data, e. g. the tags
        if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyPagesIndexEntry'])) {
            foreach ($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['ke_search']['modifyPagesIndexEntry'] as $_classRef) {
                $_procObj = &\TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance($_classRef);
                $_procObj->modifyPagesIndexEntry(
                    $uid,
                    $pageContent,
                    $tags,
                    $this->cachedPageRecords,
                    $additionalFields,
                    $indexerConfig,
                    $indexEntryDefaultValues,
                    $this
                );
            }
        }


        // store record in index table
        if (count($pageContent)) {
            foreach ($pageContent as $language_uid => $content) {

                if (!$pageAccessRestrictions['hidden'] && $this->checkIfpageShouldBeIndexed($uid, $language_uid)) {
                    // overwrite access restrictions with language overlay values
                    $accessRestrictionsLanguageOverlay = $pageAccessRestrictions;
                    $pageAccessRestrictions['fe_group'] = $indexEntryDefaultValues['feGroupsPages'];
                    if ($language_uid > 0) {
                        if ($this->cachedPageRecords[$language_uid][$uid]['fe_group']) {
                            $accessRestrictionsLanguageOverlay['fe_group'] =
                                $this->cachedPageRecords[$language_uid][$uid]['fe_group'];
                        }
                        if ($this->cachedPageRecords[$language_uid][$uid]['starttime']) {
                            $accessRestrictionsLanguageOverlay['starttime'] =
                                $this->cachedPageRecords[$language_uid][$uid]['starttime'];
                        }
                        if ($this->cachedPageRecords[$language_uid][$uid]['endtime']) {
                            $accessRestrictionsLanguageOverlay['endtime'] =
                                $this->cachedPageRecords[$language_uid][$uid]['endtime'];
                        }
                    }

                    // use new "tx_kesearch_abstract" field instead of "abstract" if set
                    $abstract = $this->cachedPageRecords[$language_uid][$uid]['tx_kesearch_abstract'] ?
                        $this->cachedPageRecords[$language_uid][$uid]['tx_kesearch_abstract'] :
                        $this->cachedPageRecords[$language_uid][$uid]['abstract'];

                    $this->pObj->storeInIndex(
                        $indexerConfig['storagepid'],                               // storage PID
                        $this->cachedPageRecords[$language_uid][$uid]['title'],     // page title
                        $indexEntryDefaultValues['type'],                           // content type
                        $indexEntryDefaultValues['uid'],                            // target PID / single view
                        $content,                        // indexed content, includes the title (linebreak after title)
                        $tags,                                                      // tags
                        $indexEntryDefaultValues['params'],                         // typolink params for singleview
                        $abstract,                                                  // abstract
                        $language_uid,                                              // language uid
                        $accessRestrictionsLanguageOverlay['starttime'],            // starttime
                        $accessRestrictionsLanguageOverlay['endtime'],              // endtime
                        $accessRestrictionsLanguageOverlay['fe_group'],             // fe_group
                        $indexEntryDefaultValues['debugOnly'],                      // debug only?
                        $additionalFields                                           // additional fields added by hooks
                    );
                    $this->counter++;
                }
            }
        }

        return;
    }
752270
protected function _fetchTableIndexes($table)
    {
        $result = array();
        $sql    = $this->quoteName($this->getTableNeedle().$table);

        if ($indexes = $this->show('SHOW INDEX FROM '.$sql, AnDatabase::FETCH_OBJECT_LIST)) {
            foreach ($indexes as $index) {
                $result[$index->Key_name][$index->Seq_in_index] = $index;
            }
        }

        return $result;
    }