Esempio n. 1
0
    /**
     * Stores the keywords from the current query to the database.
     *
     * @param string $keywords The current query's keywords
     * @return void
     */
    protected function storeKeywordsToDatabase($keywords)
    {
        $nextSequenceId = $this->getNextSequenceId();
        $this->database->sql_query('INSERT INTO tx_solr_last_searches (sequence_id, tstamp, keywords)
			VALUES (' . $nextSequenceId . ', ' . time() . ', ' . $this->database->fullQuoteStr($keywords, 'tx_solr_last_searches') . ')
			ON DUPLICATE KEY UPDATE tstamp = ' . time() . ', keywords = ' . $this->database->fullQuoteStr($keywords, 'tx_solr_last_searches'));
    }
Esempio n. 2
0
 /**
  * This method determines duplicates for a queue entry with the same parameters and this timestamp.
  * If the timestamp is in the past, it will check if there is any unprocessed queue entry in the past.
  * If the timestamp is in the future it will check, if the queued entry has exactly the same timestamp
  *
  * @param int $tstamp
  * @param string $parameters
  * @author Fabrizio Branca
  * @author Timo Schmidt
  * @return array;
  */
 protected function getDuplicateRowsIfExist($tstamp, $fieldArray)
 {
     $rows = array();
     $currentTime = $this->getCurrentTime();
     //if this entry is scheduled with "now"
     if ($tstamp <= $currentTime) {
         if ($this->extensionSettings['enableTimeslot']) {
             $timeBegin = $currentTime - 100;
             $timeEnd = $currentTime + 100;
             $where = ' ((scheduled BETWEEN ' . $timeBegin . ' AND ' . $timeEnd . ' ) OR scheduled <= ' . $currentTime . ') ';
         } else {
             $where = 'scheduled <= ' . $currentTime;
         }
     } elseif ($tstamp > $currentTime) {
         //entry with a timestamp in the future need to have the same schedule time
         $where = 'scheduled = ' . $tstamp;
     }
     if (!empty($where)) {
         $result = $this->db->exec_SELECTgetRows('qid', 'tx_crawler_queue', $where . ' AND NOT exec_time' . ' AND NOT process_id ' . ' AND page_id=' . intval($fieldArray['page_id']) . ' AND parameters_hash = ' . $this->db->fullQuoteStr($fieldArray['parameters_hash'], 'tx_crawler_queue'));
         if (is_array($result)) {
             foreach ($result as $value) {
                 $rows[] = $value['qid'];
             }
         }
     }
     return $rows;
 }
 /**
  * Get a user from DB by social identifier
  *
  * @param string $identifier social identifier
  * @param string $extraWhere Additional WHERE clause: " AND ...
  * @param array $dbUserSetup User db table definition: $this->db_user
  * @return mixed User array or FALSE
  */
 public function fetchUserRecordByIdentifier($identifier, $extraWhere = '', $dbUserSetup = '')
 {
     $result = FALSE;
     $identityClassName = 'Portrino\\PxHybridAuth\\Domain\\Model\\Identity\\' . ucfirst($this->getServiceProvider()) . 'Identity';
     if (class_exists($identityClassName) && defined($identityClassName . '::EXTBASE_TYPE')) {
         $extbaseType = constant($identityClassName . '::EXTBASE_TYPE');
         $identityClause = 'deleted=0 AND hidden=0 AND identifier=' . $this->db->fullQuoteStr($identifier, 'tx_pxhybridauth_domain_model_identity') . ' AND ' . 'tx_extbase_type=' . $this->db->fullQuoteStr($extbaseType, 'tx_pxhybridauth_domain_model_identity');
         $socialIdentities = $this->db->exec_SELECTgetRows('*', 'tx_pxhybridauth_domain_model_identity', $identityClause);
         foreach ($socialIdentities as $socialIdentity) {
             if (isset($socialIdentity['fe_user'])) {
                 $dbUser = is_array($dbUserSetup) ? $dbUserSetup : $this->db_user;
                 // Look up the user by the username and/or extraWhere:
                 $dbres = $this->db->exec_SELECTquery('*', $dbUser['table'], 'uid' . '=' . $this->db->fullQuoteStr($socialIdentity['fe_user'], $dbUser['table']) . $this->db->fullQuoteStr($dbUser['check_pid_clause'], $dbUser['table']) . $dbUser['enable_clause'] . $extraWhere);
                 if ($dbres) {
                     $result = $this->db->sql_fetch_assoc($dbres);
                     $this->db->sql_free_result($dbres);
                     if ($result) {
                         break;
                     }
                 }
             }
         }
     }
     return $result;
 }
 /**
  * Creates file identifier hashes for a single storage.
  *
  * @param ResourceStorage $storage The storage to update
  * @return array The executed database queries
  */
 protected function updateIdentifierHashesForStorage(ResourceStorage $storage)
 {
     $queries = array();
     if (!ExtensionManagementUtility::isLoaded('dbal')) {
         // if DBAL is not loaded, we're using MySQL and can thus use their
         // SHA1() function
         if ($storage->usesCaseSensitiveIdentifiers()) {
             $updateCall = 'SHA1(identifier)';
         } else {
             $updateCall = 'SHA1(LOWER(identifier))';
         }
         $queries[] = $query = sprintf('UPDATE sys_file SET identifier_hash = %s WHERE storage=%d', $updateCall, $storage->getUid());
         $this->db->sql_query($query);
         // folder hashes cannot be done with one call: so do it manually
         $files = $this->db->exec_SELECTgetRows('uid, storage, identifier', 'sys_file', sprintf('storage=%d AND folder_hash=%s', $storage->getUid(), $this->db->fullQuoteStr('', 'sys_file')));
         foreach ($files as $file) {
             $folderHash = $storage->hashFileIdentifier($storage->getFolderIdentifierFromFileIdentifier($file['identifier']));
             $queries[] = $query = $this->db->UPDATEquery('sys_file', 'uid=' . $file['uid'], array('folder_hash' => $folderHash));
             $this->db->sql_query($query);
         }
     } else {
         // manually hash the identifiers when using DBAL
         $files = $this->db->exec_SELECTgetRows('uid, storage, identifier', 'sys_file', sprintf('storage=%d AND identifier_hash=""', $storage->getUid()));
         foreach ($files as $file) {
             $hash = $storage->hashFileIdentifier($file['identifier']);
             $folderHash = $storage->hashFileIdentifier($storage->getFolderIdentifierFromFileIdentifier($file['identifier']));
             $queries[] = $query = $this->db->UPDATEquery('sys_file', 'uid=' . $file['uid'], array('identifier_hash' => $hash, 'folder_hash' => $folderHash));
             $this->db->sql_query($query);
         }
     }
     return $queries;
 }
Esempio n. 5
0
 /**
  * Gets user record for the user with the OpenID provided by the user
  *
  * @param string $openIDIdentifier OpenID identifier to search for
  * @return array Database fields from the table that corresponds to the current login mode (FE/BE)
  */
 protected function getUserRecord($openIDIdentifier)
 {
     $record = null;
     try {
         $openIDIdentifier = $this->normalizeOpenID($openIDIdentifier);
         // $openIDIdentifier always has a trailing slash
         // but tx_openid_openid field possibly not so check for both alternatives in database
         $record = $this->databaseConnection->exec_SELECTgetSingleRow('*', $this->authenticationInformation['db_user']['table'], 'tx_openid_openid IN (' . $this->databaseConnection->fullQuoteStr($openIDIdentifier, $this->authenticationInformation['db_user']['table']) . ',' . $this->databaseConnection->fullQuoteStr(rtrim($openIDIdentifier, '/'), $this->authenticationInformation['db_user']['table']) . ')' . $this->authenticationInformation['db_user']['check_pid_clause'] . $this->authenticationInformation['db_user']['enable_clause']);
         if ($record) {
             // Make sure to work only with normalized OpenID during the whole process
             $record['tx_openid_openid'] = $this->normalizeOpenID($record['tx_openid_openid']);
         }
     } catch (Exception $e) {
         // This should never happen and generally means hack attempt.
         // We just log it and do not return any records.
         $this->writeLog($e->getMessage());
     }
     // Hook to modify the user record, e.g. to register a new user
     if (isset($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['openid']['getUserRecord']) && is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['openid']['getUserRecord'])) {
         $_params = array('record' => &$record, 'response' => $this->openIDResponse, 'authInfo' => $this->authenticationInformation);
         foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['openid']['getUserRecord'] as $funcName) {
             GeneralUtility::callUserFunction($funcName, $_params, $this);
         }
     }
     return $record;
 }
Esempio n. 6
0
 /**
  * Add a constraint to ensure that the record type of the returned tuples is matching the data type of the repository.
  *
  * @param string $className The class name
  * @param array &$sql The query parts
  * @return void
  */
 protected function addRecordTypeConstraint($className, &$sql)
 {
     if ($className !== NULL) {
         $dataMap = $this->dataMapper->getDataMap($className);
         if ($dataMap->getRecordTypeColumnName() !== NULL) {
             $recordTypes = array();
             if ($dataMap->getRecordType() !== NULL) {
                 $recordTypes[] = $dataMap->getRecordType();
             }
             foreach ($dataMap->getSubclasses() as $subclassName) {
                 $subclassDataMap = $this->dataMapper->getDataMap($subclassName);
                 if ($subclassDataMap->getRecordType() !== NULL) {
                     $recordTypes[] = $subclassDataMap->getRecordType();
                 }
             }
             if (!empty($recordTypes)) {
                 $recordTypeStatements = array();
                 foreach ($recordTypes as $recordType) {
                     $tableName = $dataMap->getTableName();
                     $recordTypeStatements[] = $tableName . '.' . $dataMap->getRecordTypeColumnName() . '=' . $this->databaseHandle->fullQuoteStr($recordType, $tableName);
                 }
                 $sql['additionalWhereClause'][] = '(' . implode(' OR ', $recordTypeStatements) . ')';
             }
         }
     }
 }
Esempio n. 7
0
 /**
  * Updates existing association.
  *
  * @param string $serverUrl Server URL
  * @param \Auth_OpenID_Association $association OpenID association
  * @return void
  */
 protected function updateExistingAssociation($serverUrl, \Auth_OpenID_Association $association)
 {
     $where = sprintf('server_url=%s AND assoc_handle=%s AND expires>%d', $this->databaseConnection->fullQuoteStr($serverUrl, self::ASSOCIATION_TABLE_NAME), $this->databaseConnection->fullQuoteStr($association->handle, self::ASSOCIATION_TABLE_NAME), time());
     $serializedAssociation = serialize($association);
     $values = array('content' => base64_encode($serializedAssociation), 'tstamp' => time());
     $this->databaseConnection->exec_UPDATEquery(self::ASSOCIATION_TABLE_NAME, $where, $values);
 }
Esempio n. 8
0
 /**
  * Replace query placeholders in a query part by the given
  * parameters.
  *
  * @param string &$sqlString The query part with placeholders
  * @param array $parameters The parameters
  * @param string $tableName
  *
  * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Exception
  * @deprecated since 6.2, will be removed two versions later
  * @todo add deprecation notice after getUidOfAlreadyPersistedValueObject is adjusted
  */
 protected function replacePlaceholders(&$sqlString, array $parameters, $tableName = 'foo')
 {
     // @todo profile this method again
     if (substr_count($sqlString, '?') !== count($parameters)) {
         throw new \TYPO3\CMS\Extbase\Persistence\Generic\Exception('The number of question marks to replace must be equal to the number of parameters.', 1242816074);
     }
     $offset = 0;
     foreach ($parameters as $parameter) {
         $markPosition = strpos($sqlString, '?', $offset);
         if ($markPosition !== FALSE) {
             if ($parameter === NULL) {
                 $parameter = 'NULL';
             } elseif (is_array($parameter) || $parameter instanceof \ArrayAccess || $parameter instanceof \Traversable) {
                 $items = array();
                 foreach ($parameter as $item) {
                     $items[] = $this->databaseHandle->fullQuoteStr($item, $tableName);
                 }
                 $parameter = '(' . implode(',', $items) . ')';
             } else {
                 $parameter = $this->databaseHandle->fullQuoteStr($parameter, $tableName);
             }
             $sqlString = substr($sqlString, 0, $markPosition) . $parameter . substr($sqlString, $markPosition + 1);
         }
         $offset = $markPosition + strlen($parameter);
     }
 }
 /**
  * @param \TYPO3\CMS\Core\Resource\File|\TYPO3\CMS\Core\Resource\FileInterface $file
  * @param string $taskType The task that should be executed on the file
  * @param array $configuration
  *
  * @return ProcessedFile
  */
 public function findOneByOriginalFileAndTaskTypeAndConfiguration(FileInterface $file, $taskType, array $configuration)
 {
     $databaseRow = $this->databaseConnection->exec_SELECTgetSingleRow('*', $this->table, 'original=' . (int) $file->getUid() . ' AND task_type=' . $this->databaseConnection->fullQuoteStr($taskType, $this->table) . ' AND configurationsha1=' . $this->databaseConnection->fullQuoteStr(sha1(serialize($configuration)), $this->table));
     if (is_array($databaseRow)) {
         $processedFile = $this->createDomainObject($databaseRow);
     } else {
         $processedFile = $this->createNewProcessedFileObject($file, $taskType, $configuration);
     }
     return $processedFile;
 }
Esempio n. 10
0
 /**
  * Sets the entry to cache.
  *
  * @param UrlCacheEntry $cacheEntry
  * @return void
  */
 public function putUrlToCache(UrlCacheEntry $cacheEntry)
 {
     $data = array('original_url' => $cacheEntry->getOriginalUrl(), 'page_id' => $cacheEntry->getPageId(), 'request_variables' => json_encode($cacheEntry->getRequestVariables()), 'rootpage_id' => $cacheEntry->getRootPageId(), 'speaking_url' => $cacheEntry->getSpeakingUrl());
     if ($cacheEntry->getCacheId()) {
         $this->databaseConnection->exec_UPDATEquery('tx_realurl_urlcache', 'uid=' . $this->databaseConnection->fullQuoteStr($cacheEntry->getCacheId(), 'tx_realurl_urlcache'), $data);
     } else {
         $this->databaseConnection->exec_INSERTquery('tx_realurl_urlcache', $data);
         $cacheEntry->setCacheId($this->databaseConnection->sql_insert_id());
     }
 }
 /**
  * Update the current_version field after update
  * For performance reason "native" TYPO3_DB is
  * used here directly.
  *
  * @param integer $repositoryUid
  * @return integer
  */
 public function insertLastVersion($repositoryUid = 1)
 {
     $groupedRows = $this->databaseConnection->exec_SELECTgetRows('extension_key, max(integer_version) as maxintversion', 'tx_extensionmanager_domain_model_extension', 'repository=' . intval($repositoryUid), 'extension_key');
     $extensions = count($groupedRows);
     if ($extensions > 0) {
         // set all to 0
         $this->databaseConnection->exec_UPDATEquery('tx_extensionmanager_domain_model_extension', 'current_version=1 AND repository=' . intval($repositoryUid), array('current_version' => 0));
         // Find latest version of extensions and set current_version to 1 for these
         foreach ($groupedRows as $row) {
             $this->databaseConnection->exec_UPDATEquery('tx_extensionmanager_domain_model_extension', 'extension_key=' . $this->databaseConnection->fullQuoteStr($row['extension_key'], 'tx_extensionmanager_domain_model_extension') . ' AND integer_version=' . intval($row['maxintversion']) . ' AND repository=' . intval($repositoryUid), array('current_version' => 1));
         }
     }
     return $extensions;
 }
Esempio n. 12
0
 /**
  * Perform update
  *
  * @param array &$dbQueries Queries done in this update
  * @param mixed &$customMessages Custom messages
  * @return boolean Whether the updated was made or not
  */
 public function performUpdate(array &$dbQueries, &$customMessages)
 {
     $rows = $this->db->exec_SELECTgetRows('uid,pi_flexform', $GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable'], 'CType = ' . $this->db->fullQuoteStr('media', $GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable']) . ' AND pi_flexform LIKE ' . $this->db->fullQuoteStr('%<sheet index="sDEF">%', $GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable']));
     /** @var $flexformTools \TYPO3\CMS\Core\Configuration\FlexForm\FlexFormTools */
     $flexformTools = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Configuration\\FlexForm\\FlexFormTools');
     foreach ($rows as $row) {
         $flexFormXML = $row['pi_flexform'];
         $data = \TYPO3\CMS\Core\Utility\GeneralUtility::xml2array($flexFormXML);
         $sDEF = $data['data']['sDEF']['lDEF'];
         unset($data['data']['sDEF']);
         $type = $sDEF['mmType']['vDEF'];
         $data['data']['sGeneral'] = array('lDEF' => array('mmType' => array('vDEF' => $type)));
         $width = $sDEF['mmWidth']['vDEF'];
         if ($width) {
             $data['data']['sGeneral']['lDEF']['mmWidth'] = array('vDEF' => (int) $width);
         }
         $height = $sDEF['mmHeight']['vDEF'];
         if ($height) {
             $data['data']['sGeneral']['lDEF']['mmHeight'] = array('vDEF' => (int) $height);
         }
         switch ($type) {
             case 'video':
                 $data['data']['sVideo'] = array('lDEF' => array('mmFile' => array('vDEF' => $sDEF['mmFile']['vDEF'])));
                 break;
             case 'audio':
                 $data['data']['sAudio'] = array('lDEF' => array('mmAudioFallback' => array('vDEF' => $sDEF['mmFile']['vDEF'])));
                 break;
             default:
                 continue;
         }
         $newXML = $flexformTools->flexArray2Xml($data, TRUE);
         $newXML = str_replace('encoding=""', 'encoding="utf-8"', $newXML);
         $this->db->exec_UPDATEquery($GLOBALS['TYPO3_CONF_VARS']['SYS']['contentTable'], 'uid = ' . $row['uid'], array('pi_flexform' => $newXML));
     }
     return TRUE;
 }
Esempio n. 13
0
 /**
  * Sets the entry to cache.
  *
  * @param UrlCacheEntry $cacheEntry
  * @return void
  */
 public function putUrlToCache(UrlCacheEntry $cacheEntry)
 {
     $data = array('expire' => $cacheEntry->getExpiration(), 'original_url' => $cacheEntry->getOriginalUrl(), 'page_id' => $cacheEntry->getPageId(), 'request_variables' => json_encode($cacheEntry->getRequestVariables()), 'rootpage_id' => $cacheEntry->getRootPageId(), 'speaking_url' => $cacheEntry->getSpeakingUrl());
     if ($cacheEntry->getCacheId()) {
         $this->databaseConnection->exec_UPDATEquery('tx_realurl_urldata', 'uid=' . $this->databaseConnection->fullQuoteStr($cacheEntry->getCacheId(), 'tx_realurl_urldata'), $data);
     } else {
         $this->databaseConnection->sql_query('START TRANSACTION');
         if ($this->limitTableRecords('tx_realurl_urldata')) {
             $this->databaseConnection->sql_query('DELETE FROM tx_realurl_uniqalias_cache_map WHERE url_cache_id NOT IN (SELECT uid FROM tx_realurl_urldata)');
         }
         $this->databaseConnection->exec_INSERTquery('tx_realurl_urldata', $data);
         $cacheEntry->setCacheId($this->databaseConnection->sql_insert_id());
         $this->databaseConnection->sql_query('COMMIT');
     }
 }
Esempio n. 14
0
 /**
  * Resolve relations as defined in TCA and add them to the provided $pageRecord array.
  *
  * @param int $uid Page id
  * @param array $pageRecord Array with page data to add relation data to.
  * @throws \RuntimeException
  * @return array $pageRecord with additional relations
  */
 protected function enrichWithRelationFields($uid, array $pageRecord)
 {
     $pageOverlayFields = GeneralUtility::trimExplode(',', $GLOBALS['TYPO3_CONF_VARS']['FE']['pageOverlayFields']);
     foreach ($GLOBALS['TCA']['pages']['columns'] as $column => $configuration) {
         if ($this->columnHasRelationToResolve($configuration)) {
             $configuration = $configuration['config'];
             if ($configuration['MM']) {
                 /** @var $loadDBGroup \TYPO3\CMS\Core\Database\RelationHandler */
                 $loadDBGroup = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\RelationHandler::class);
                 $loadDBGroup->start($pageRecord[$column], isset($configuration['allowed']) ? $configuration['allowed'] : $configuration['foreign_table'], $configuration['MM'], $uid, 'pages', $configuration);
                 $relatedUids = isset($loadDBGroup->tableArray[$configuration['foreign_table']]) ? $loadDBGroup->tableArray[$configuration['foreign_table']] : array();
             } else {
                 $columnIsOverlaid = in_array($column, $pageOverlayFields, true);
                 $table = $configuration['foreign_table'];
                 $field = $configuration['foreign_field'];
                 $whereClauseParts = array($field . ' = ' . (int) ($columnIsOverlaid ? $uid : $pageRecord['uid']));
                 if (isset($configuration['foreign_match_fields']) && is_array($configuration['foreign_match_fields'])) {
                     foreach ($configuration['foreign_match_fields'] as $field => $value) {
                         $whereClauseParts[] = $field . ' = ' . $this->databaseConnection->fullQuoteStr($value, $table);
                     }
                 }
                 if (isset($configuration['foreign_table_field'])) {
                     if ((int) $this->languageUid > 0 && $columnIsOverlaid) {
                         $whereClauseParts[] = trim($configuration['foreign_table_field']) . ' = \'pages_language_overlay\'';
                     } else {
                         $whereClauseParts[] = trim($configuration['foreign_table_field']) . ' = \'pages\'';
                     }
                 }
                 if (isset($GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled'])) {
                     $whereClauseParts[] = $table . '.' . $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled'] . ' = 0';
                 }
                 $whereClause = implode(' AND ', $whereClauseParts);
                 $whereClause .= $this->pageContext->deleteClause($table);
                 $orderBy = isset($configuration['foreign_sortby']) ? $configuration['foreign_sortby'] : '';
                 $rows = $this->databaseConnection->exec_SELECTgetRows('uid', $table, $whereClause, '', $orderBy);
                 if (!is_array($rows)) {
                     throw new \RuntimeException('Could to resolve related records for page ' . $uid . ' and foreign_table ' . htmlspecialchars($configuration['foreign_table']), 1343589452);
                 }
                 $relatedUids = array();
                 foreach ($rows as $row) {
                     $relatedUids[] = $row['uid'];
                 }
             }
             $pageRecord[$column] = implode(',', $relatedUids);
         }
     }
     return $pageRecord;
 }
Esempio n. 15
0
 /**
  * Upgrades configuration from v2.x to v3.0.
  *
  * @return string
  */
 protected function upgradeV2xToV30()
 {
     $table = 'tx_scheduler_task';
     $oldClassName = 'Tx_IgLdapSsoAuth_Task_ImportUsers';
     $newClassName = 'Causal\\IgLdapSsoAuth\\Task\\ImportUsers';
     $oldPattern = 'O:' . strlen($oldClassName) . ':"' . $oldClassName . '":';
     $newPattern = 'O:' . strlen($newClassName) . ':"' . $newClassName . '":';
     $oldTaskRecords = $this->databaseConnection->exec_SELECTgetRows('uid, serialized_task_object', $table, 'serialized_task_object LIKE ' . $this->databaseConnection->fullQuoteStr($oldPattern . '%', $table));
     $i = 0;
     foreach ($oldTaskRecords as $oldTaskRecord) {
         $data = array('serialized_task_object' => preg_replace('/^' . $oldPattern . '/', $newPattern, $oldTaskRecord['serialized_task_object']));
         $this->databaseConnection->exec_UPDATEquery($table, 'uid=' . (int) $oldTaskRecord['uid'], $data);
         $i++;
     }
     return $this->formatOk('Successfully updated ' . $i . ' user import scheduler task' . ($i > 1 ? 's' : ''));
 }
 /**
  * Update existing record
  *
  * @return int uid of updated record
  */
 protected function update()
 {
     // find existing record in database
     $searchterm = $this->databaseConnection->fullQuoteStr($this->getProperty($this->getUniqueField()), $this->getTable());
     $res = $this->databaseConnection->exec_SELECTquery('uid', $this->getTable(), $this->getUniqueField() . ' = ' . $searchterm . ' and deleted = 0 ' . $this->getAdditionalWhereClause(), '', '', 1);
     if ($res) {
         $row = $this->databaseConnection->sql_fetch_assoc($res);
     }
     // if there is no existing entry, insert new one
     if (empty($row['uid'])) {
         return $this->insert();
     }
     // update existing entry (only if mode is not "none")
     if ($this->getMode() !== 'none') {
         $this->databaseConnection->exec_UPDATEquery($this->getTable(), 'uid = ' . (int) $row['uid'], $this->getProperties());
     }
     return $row['uid'];
 }
 /**
  * Builds a condition for filtering records by the configured match field,
  * e.g. MM_match_fields, foreign_match_fields or foreign_table_field.
  *
  * @param ColumnMap $columnMap The column man for which the condition should be build.
  * @param string $childTableName The real name of the child record table.
  * @param string $childTableAlias The alias of the child record table used in the query.
  * @param string $parentTable The real name of the parent table (used for building the foreign_table_field condition).
  * @return string The match field conditions or an empty string.
  */
 protected function getAdditionalMatchFieldsStatement($columnMap, $childTableName, $childTableAlias, $parentTable = null)
 {
     $additionalWhereForMatchFields = '';
     $relationTableMatchFields = $columnMap->getRelationTableMatchFields();
     if (is_array($relationTableMatchFields) && !empty($relationTableMatchFields)) {
         $additionalWhere = array();
         foreach ($relationTableMatchFields as $fieldName => $value) {
             $additionalWhere[] = $childTableAlias . '.' . $fieldName . ' = ' . $this->databaseHandle->fullQuoteStr($value, $childTableName);
         }
         $additionalWhereForMatchFields .= ' AND ' . implode(' AND ', $additionalWhere);
     }
     if (isset($parentTable)) {
         $parentTableFieldName = $columnMap->getParentTableFieldName();
         if (isset($parentTableFieldName) && $parentTableFieldName !== '') {
             $additionalWhereForMatchFields .= ' AND ' . $childTableAlias . '.' . $parentTableFieldName . ' = ' . $this->databaseHandle->fullQuoteStr($parentTable, $childTableAlias);
         }
     }
     return $additionalWhereForMatchFields;
 }
 /**
  * Inserts a new word into the search index table and returns it's UID.
  * If the word already exists in the search index, just the UID is returned.
  * @param string $word The word to be inserted
  * @return int         The word's UID
  */
 function wordAdd($word)
 {
     // Attempt to load word from database
     $res = $this->databaseHandle->exec_SELECTquery('uid', 'tx_mmforum_wordlist', "word=" . $this->databaseHandle->fullQuoteStr($word, 'tx_mmforum_wordlist') . " " . $this->getPidQuery($this->conf));
     if (!$res) {
         echo $this->databaseHandle->sql_error() . '<hr>';
     }
     // If words already exists, just return the UID
     if ($this->databaseHandle->sql_num_rows($res) > 0) {
         list($uid) = $this->databaseHandle->sql_fetch_row($res);
     } else {
         // Compost insert query
         $insertArray = array('pid' => $this->getFirstPid($this->conf), 'word' => $word, 'metaphone' => metaphone($word));
         // Execute insert query
         $this->databaseHandle->exec_INSERTquery('tx_mmforum_wordlist', $insertArray);
         $uid = $this->databaseHandle->sql_insert_id();
     }
     return $uid;
 }
Esempio n. 19
0
 /**
  * Gets user record for the user with the OpenID provided by the user
  *
  * @param string $openIDIdentifier OpenID identifier to search for
  * @return array Database fields from the table that corresponds to the current login mode (FE/BE)
  */
 protected function getUserRecord($openIDIdentifier)
 {
     $record = NULL;
     try {
         $openIDIdentifier = $this->normalizeOpenID($openIDIdentifier);
         // $openIDIdentifier always has a trailing slash
         // but tx_openid_openid field possibly not so check for both alternatives in database
         $record = $this->databaseConnection->exec_SELECTgetSingleRow('*', $this->authenticationInformation['db_user']['table'], 'tx_openid_openid IN (' . $this->databaseConnection->fullQuoteStr($openIDIdentifier, $this->authenticationInformation['db_user']['table']) . ',' . $this->databaseConnection->fullQuoteStr(rtrim($openIDIdentifier, '/'), $this->authenticationInformation['db_user']['table']) . ')' . $this->authenticationInformation['db_user']['check_pid_clause'] . $this->authenticationInformation['db_user']['enable_clause']);
         if ($record) {
             // Make sure to work only with normalized OpenID during the whole process
             $record['tx_openid_openid'] = $this->normalizeOpenID($record['tx_openid_openid']);
         }
     } catch (Exception $e) {
         // This should never happen and generally means hack attempt.
         // We just log it and do not return any records.
         $this->writeLog($e->getMessage());
     }
     return $record;
 }
Esempio n. 20
0
 /**
  * Processes the actual transformation from CSV to sys_file_references
  *
  * @param array $source
  * @param array $destination
  * @param array $configuration
  *
  * @return void
  */
 protected function migrateFilesToFal(array $source, array $destination, array $configuration)
 {
     $path = PATH_site . $configuration['sourcePath'];
     $files = GeneralUtility::trimExplode(',', $source[$configuration['sourceField']], true);
     $i = 1;
     foreach ($files as $file) {
         if (file_exists($path . $file)) {
             GeneralUtility::upload_copy_move($path . $file, $this->targetDirectory . $file);
             /** @var \TYPO3\CMS\Core\Resource\File $fileObject */
             $fileObject = $this->storage->getFile(self::FILE_MIGRATION_FOLDER . $file);
             $this->fileIndexRepository->add($fileObject);
             $count = $this->database->exec_SELECTcountRows('*', 'sys_file_reference', 'tablenames = ' . $this->database->fullQuoteStr($configuration['destinationTable'], 'sys_file_reference') . ' AND fieldname = ' . $this->database->fullQuoteStr($configuration['destinationField'], 'sys_file_reference') . ' AND uid_local = ' . $fileObject->getUid() . ' AND uid_foreign = ' . $destination['uid']);
             if (!$count) {
                 $dataArray = array('uid_local' => $fileObject->getUid(), 'tablenames' => $configuration['destinationTable'], 'uid_foreign' => $destination['uid'], 'pid' => $source['pid'], 'fieldname' => $configuration['destinationField'], 'sorting_foreign' => $i, 'table_local' => 'sys_file');
                 $this->database->exec_INSERTquery('sys_file_reference', $dataArray);
             }
         }
         $i++;
     }
 }
 /**
  * Checks if an input variable already exists in the database
  *
  * @param  string $value The value that is to be checked.
  * @param  string $field The vdatabase field where the value should be unique
  * @return bool          TRUE, if the input is unique, otherwise FALSE.
  *
  * @author  Hauke Hain <*****@*****.**>
  * @version 2009-09-09
  */
 function isUnique($value, $field)
 {
     $value = $this->databaseHandle->fullQuoteStr(trim($value), 'fe_users');
     $uid = intval($GLOBALS['TSFE']->fe_user->user['uid']);
     //no user logged in
     if ($uid === 0) {
         $res = $this->databaseHandle->exec_SELECTquery($field, 'fe_users', $field . ' LIKE ' . $value);
         return $this->databaseHandle->sql_num_rows($res) < 1;
     }
     //user logged in
     $res = $this->databaseHandle->exec_SELECTquery('uid,' . $field, 'fe_users', $field . ' LIKE ' . $value);
     $count = intval($this->databaseHandle->sql_num_rows($res));
     if ($count === 0) {
         return true;
     } elseif ($count === 1) {
         // if the found value is from the current user, return true
         $arr = $this->databaseHandle->sql_fetch_assoc($res);
         if (intval($arr['uid']) === $uid) {
             return true;
         }
     }
     return false;
 }
Esempio n. 22
0
 /**
  *
  * Displays the user administration interface.
  * This includes a list of all registered users ordered descending by
  * username. The list includes the usergroups a user is member in and the
  * user's age. A search function is also included.
  *
  * @return string The HTML output.
  * @todo Outsource user management into own class!
  */
 function userManagement()
 {
     /* Get template */
     $template = file_get_contents(GeneralUtility::getFileAbsFileName('EXT:mm_forum/res/tmpl/mod1/users.html'));
     $template = tx_mmforum_BeTools::getSubpart($template, '###USERS_LIST###');
     $uTemplate = tx_mmforum_BeTools::getSubpart($template, '###USERS_LIST_ITEM###');
     // Retrieve global variables
     global $LANG, $BACK_PATH, $BE_USER;
     /** @var $LANG \TYPO3\CMS\Lang\LanguageService */
     // Generate SQL query
     $ug = $this->feGroups2Array();
     $mmforum = GeneralUtility::_GP('mmforum');
     if ($mmforum['no_filter']) {
         unset($mmforum['sword']);
         unset($mmforum['old_sword']);
     }
     if ($mmforum['old_sword'] && !$mmforum['sword']) {
         $mmforum['sword'] = $mmforum['old_sword'];
     }
     $gp = '';
     if ($mmforum['sword']) {
         $gp = '&mmforum[sword]=' . $mmforum['sword'];
     }
     $groups = implode(',', array(intval($this->confArr['userGroup']), intval($this->confArr['modGroup']), intval($this->confArr['adminGroup'])));
     if ($sword = $mmforum['sword']) {
         $sword = $this->databaseHandle->escapeStrForLike($sword, 'fe_users');
         $sword = $this->databaseHandle->fullQuoteStr($sword . '%', 'fe_users');
         $filter = 'username like ' . $sword;
     } else {
         $filter = '1';
     }
     // Determine sort order. The default is "ASC" order.
     switch (strtoupper(GeneralUtility::_GP('mmforum_style'))) {
         case 'DESC':
             $orderBy = 'DESC';
             break;
         case 'ASC':
         default:
             $orderBy = 'ASC';
             break;
     }
     if (GeneralUtility::_GP('mmforum_sort') == 'username') {
         $order = 'username ' . $orderBy . '';
         $uOrder = $orderBy == 'ASC' ? 'DESC' : 'ASC';
         $aOrder = 'ASC';
     } elseif (GeneralUtility::_GP('mmforum_sort') == 'age') {
         $order = 'crdate ' . $orderBy . '';
         $aOrder = $orderBy == 'ASC' ? 'DESC' : 'ASC';
         $uOrder = 'ASC';
     } else {
         $order = 'username ' . $orderBy . '';
         $aOrder = 'ASC';
         $uOrder = 'DESC';
     }
     #$userGroup_query = "(".$this->confArr['userGroup']." IN (usergroup) OR ".$this->confArr['modGroup']." IN (usergroup) OR ".$this->confArr['adminGroup']." IN (usergroup))";
     $userGroup_query = "(FIND_IN_SET('" . $this->confArr['userGroup'] . "',usergroup) OR FIND_IN_SET('" . $this->confArr['modGroup'] . "',usergroup) OR FIND_IN_SET('" . $this->confArr['adminGroup'] . "',usergroup))";
     #$userGroup_query = "1";
     $res = $this->databaseHandle->exec_SELECTquery('count(*)', 'fe_users', "{$filter} and pid='" . $this->confArr['userPID'] . "' and " . $userGroup_query . " and deleted=0");
     $row = $this->databaseHandle->sql_fetch_row($res);
     $records = $row[0];
     $pages = ceil($records / $this->confArr['recordsPerPage']);
     $offset = intval($mmforum['offset']);
     // Page navigation
     $pb = $LANG->getLL('page.page') . ' <a href="index.php?mmforum[offset]=0' . $gp . '">[' . $LANG->getLL('page.first') . ']</a> ';
     $end = $offset + 6 >= $pages ? $pages : $offset + 6;
     $start = $offset - 5;
     if ($start < 0) {
         $start = 0;
     }
     if ($start > 0) {
         $pb .= '... ';
     }
     for ($i = $start; $i < $end; $i++) {
         $pb .= '<a href="index.php?mmforum[offset]=' . $i . $gp . '">' . ($i == $offset ? '<b>' . ($i + 1) . '</b>' : $i + 1) . '</a> ';
     }
     if ($offset + 11 < $pages) {
         $pb .= ' ... <a href="index.php?mmforum[offset]=' . ($pages - 1) . $gp . '">[' . $LANG->getLL('page.last') . ']</a> ';
     }
     // Generate header table
     if ($records < $this->confArr['recordsPerPage']) {
         $mDisp = $records;
     } else {
         $mDisp = $offset * $this->confArr['recordsPerPage'] + $this->confArr['recordsPerPage'];
     }
     $userString = sprintf($LANG->getLL('useradmin.usercount'), $offset * $this->confArr['recordsPerPage'] + 1, $mDisp, $records);
     $out = '<table width="733"><tr>';
     $out .= '<td width="420">' . $pb . '</td>';
     $out .= '<td width="120" align="center"><b>' . $userString . '</b></td>';
     $out .= '<td align="right">' . $LANG->getLL('useradmin.searchfor') . ': <input type="text" id="sword" size="20" name="mmforum[sword]" /></td>';
     $out .= '</tr></table>';
     if ($mmforum['sword'] || $mmforum['old_sword']) {
         $out .= '<p>' . $LANG->getLL('useradmin.filter') . ': ' . $mmforum['sword'] . '* <a href="index.php?mmforum[no_filter]=1&' . $this->linkParams($mmforum) . '">' . $LANG->getLL('useradmin.filter.clear') . '</a></p>';
         $out .= '<input type="hidden" name="mmforum[old_sword]" value="' . $mmforum['sword'] . '" />';
     }
     // Display userdata table
     // Execute database query
     $res = $this->databaseHandle->exec_SELECTquery('*', 'fe_users', "{$filter} and pid='" . $this->confArr['userPID'] . "' and deleted=0 AND " . $userGroup_query, '', $order, $offset * $this->confArr['recordsPerPage'] . "," . $this->confArr['recordsPerPage']);
     if ($res) {
         $marker = array('###USERS_LLL_TITLE###' => $LANG->getLL('users.title'), '###USERS_LLL_USERNAME###' => '<a href="index.php?mmforum_sort=username&mmforum_style=' . $uOrder . '">' . $LANG->getLL('useradmin.username') . '</a>', '###USERS_LLL_REGISTERED###' => '<a href="index.php?mmforum_sort=age&mmforum_style=' . $aOrder . '">' . $LANG->getLL('useradmin.age') . '</a>', '###USERS_LLL_GROUPS###' => $LANG->getLL('useradmin.usergroup'), '###USERS_LLL_OPTIONS###' => '&nbsp;');
         $i = 0;
         $uContent = '';
         while ($row = $this->databaseHandle->sql_fetch_assoc($res)) {
             // Display user groups
             $g = explode(',', $row['usergroup']);
             $outg = '';
             foreach ($g as $sg) {
                 $outg .= $ug[$sg] . ', ';
             }
             $iconAltText = BackendUtility::getRecordIconAltText($row, $table);
             $elementTitle = BackendUtility::getRecordPath($row['uid'], '1=1', 0);
             $elementTitle = GeneralUtility::fixed_lgd_cs($elementTitle, -$BE_USER->uc['titleLen']);
             $elementIcon = IconUtility::getIconImage($table, $row, $BACK_PATH, 'class="c-recicon" title="' . $iconAltText . '"');
             $params = '&edit[fe_users][' . $row['uid'] . ']=edit';
             $editOnClick = BackendUtility::editOnClick($params, $BACK_PATH);
             // Generate row item
             $class_suffix = $i++ % 2 == 0 ? '2' : '';
             $link = "index.php?mmforum[cid]=" . $row['uid'];
             $js = 'onmouseover="this.className=\'mm_forum-listrow_active\'; this.style.cursor=\'pointer\';" onmouseout="this.className=\'mm_forum-listrow' . $class_suffix . '\'" onclick="' . htmlspecialchars($editOnClick) . '"';
             $icon = '<img src="../icon_tx_mmforum_forums.gif" />';
             $hidden = $row['hidden'] == 1 ? '<span style="color:blue;">[' . $LANG->getLL('boardadmin.hidden') . ']</span> ' : '';
             $uMarker = array('###USER_USERNAME###' => htmlspecialchars($row['username']), '###USER_REGISTERED###' => BackendUtility::dateTimeAge($row['crdate'], 1), '###USER_GROUPS###' => substr($outg, -2) == ', ' ? substr($outg, 0, strlen($outg) - 2) : $outg, '###USER_OPTIONS###' => '<img src="img/edit.png" onclick="' . htmlspecialchars($editOnClick) . '" style="cursor:pointer;" />');
             $uContent .= tx_mmforum_BeTools::substituteMarkerArray($uTemplate, $uMarker);
         }
         $template = tx_mmforum_BeTools::substituteSubpart($template, '###USERS_LIST_ITEM###', $uContent);
         $template = tx_mmforum_BeTools::substituteMarkerArray($template, $marker);
         $out .= $template;
     }
     return $out;
 }
Esempio n. 23
0
 /**
  * Get modified header for a copied record
  *
  * @param string $table Table name
  * @param int $pid PID value in which other records to test might be
  * @param string $field Field name to get header value for.
  * @param string $value Current field value
  * @param int $count Counter (number of recursions)
  * @param string $prevTitle Previous title we checked for (in previous recursion)
  * @return string The field value, possibly appended with a "copy label
  */
 public function getCopyHeader($table, $pid, $field, $value, $count, $prevTitle = '')
 {
     // Set title value to check for:
     if ($count) {
         $checkTitle = $value . rtrim(' ' . sprintf($this->prependLabel($table), $count));
     } else {
         $checkTitle = $value;
     }
     // Do check:
     if ($prevTitle != $checkTitle || $count < 100) {
         $rowCount = $this->databaseConnection->exec_SELECTcountRows('uid', $table, 'pid=' . (int) $pid . ' AND ' . $field . '=' . $this->databaseConnection->fullQuoteStr($checkTitle, $table) . $this->deleteClause($table));
         if ($rowCount) {
             return $this->getCopyHeader($table, $pid, $field, $value, $count + 1, $checkTitle);
         }
     }
     // Default is to just return the current input title if no other was returned before:
     return $checkTitle;
 }
 /**
  * Loads a cache variable from database.
  *
  * @author  Martin Helmich <*****@*****.**>
  * @version 2008-06-22
  * @param   string $key The key of the cache variable.
  * @return  mixed       The cache variable. Since the cache value is
  *                      stored in serialized form, this value can be of
  *                      any type. If the value was not found in the
  *                      cache table, this function will return NULL.
  */
 function getCacheValue($key)
 {
     $res = $this->databaseHandle->exec_SELECTquery('cache_value', 'tx_mmforum_cache', 'cache_key=' . $this->databaseHandle->fullQuoteStr($key, 'tx_mmforum_cache'));
     if ($this->databaseHandle->sql_num_rows($res)) {
         list($value) = $this->databaseHandle->sql_fetch_row($res);
         return unserialize($value);
     }
     return null;
 }
 /**
  * Remove a process from processlist
  *
  * @param string $processId Unique process Id.
  *
  * @return void
  */
 private function removeProcessFromProcesslist($processId)
 {
     $this->db->exec_DELETEquery('tx_crawler_process', 'process_id = ' . $this->db->fullQuoteStr($processId, 'tx_crawler_process'));
 }
 /**
  * Go through the soft refindex and find all occurences where the old filename
  * is still written in the ref_string
  *
  * @return array Entries from sys_refindex
  */
 protected function findMagicImagesInOldLocation()
 {
     $records = $this->db->exec_SELECTgetRows('hash, tablename, recuid, field, ref_table, ref_uid, ref_string', 'sys_refindex', 'ref_string LIKE ' . $this->db->fullQuoteStr($this->db->escapeStrForLike($this->oldPrefix, 'sys_refindex') . '%', 'sys_refindex'), '', 'ref_string ASC');
     return $records;
 }
 /**
  * Migrates a single field.
  *
  * @param string $table
  * @param array $row
  * @param string $fieldname
  * @param array $fieldConfiguration
  * @param string $customMessages
  * @return array A list of performed database queries
  * @throws \Exception
  */
 protected function migrateField($table, $row, $fieldname, $fieldConfiguration, &$customMessages)
 {
     $titleTextContents = [];
     $alternativeTextContents = [];
     $captionContents = [];
     $linkContents = [];
     $fieldItems = GeneralUtility::trimExplode(',', $row[$fieldname], true);
     if (empty($fieldItems) || is_numeric($row[$fieldname])) {
         return [];
     }
     if (isset($fieldConfiguration['titleTexts'])) {
         $titleTextField = $fieldConfiguration['titleTexts'];
         $titleTextContents = explode(LF, $row[$titleTextField]);
     }
     if (isset($fieldConfiguration['alternativeTexts'])) {
         $alternativeTextField = $fieldConfiguration['alternativeTexts'];
         $alternativeTextContents = explode(LF, $row[$alternativeTextField]);
     }
     if (isset($fieldConfiguration['captions'])) {
         $captionField = $fieldConfiguration['captions'];
         $captionContents = explode(LF, $row[$captionField]);
     }
     if (isset($fieldConfiguration['links'])) {
         $linkField = $fieldConfiguration['links'];
         $linkContents = explode(LF, $row[$linkField]);
     }
     $fileadminDirectory = rtrim($GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'], '/') . '/';
     $queries = [];
     $i = 0;
     if (!PATH_site) {
         throw new \Exception('PATH_site was undefined.');
     }
     $storageUid = (int) $this->storage->getUid();
     foreach ($fieldItems as $item) {
         $fileUid = null;
         $sourcePath = PATH_site . $fieldConfiguration['sourcePath'] . $item;
         $targetDirectory = PATH_site . $fileadminDirectory . $fieldConfiguration['targetPath'];
         $targetPath = $targetDirectory . basename($item);
         // maybe the file was already moved, so check if the original file still exists
         if (file_exists($sourcePath)) {
             if (!is_dir($targetDirectory)) {
                 GeneralUtility::mkdir_deep($targetDirectory);
             }
             // see if the file already exists in the storage
             $fileSha1 = sha1_file($sourcePath);
             $existingFileRecord = $this->database->exec_SELECTgetSingleRow('uid', 'sys_file', 'sha1=' . $this->database->fullQuoteStr($fileSha1, 'sys_file') . ' AND storage=' . $storageUid);
             // the file exists, the file does not have to be moved again
             if (is_array($existingFileRecord)) {
                 $fileUid = $existingFileRecord['uid'];
             } else {
                 // just move the file (no duplicate)
                 rename($sourcePath, $targetPath);
             }
         }
         if ($fileUid === null) {
             // get the File object if it hasn't been fetched before
             try {
                 // if the source file does not exist, we should just continue, but leave a message in the docs;
                 // ideally, the user would be informed after the update as well.
                 /** @var File $file */
                 $file = $this->storage->getFile($fieldConfiguration['targetPath'] . $item);
                 $fileUid = $file->getUid();
             } catch (\InvalidArgumentException $e) {
                 // no file found, no reference can be set
                 $this->logger->notice('File ' . $fieldConfiguration['sourcePath'] . $item . ' does not exist. Reference was not migrated.', ['table' => $table, 'record' => $row, 'field' => $fieldname]);
                 $format = 'File \'%s\' does not exist. Referencing field: %s.%d.%s. The reference was not migrated.';
                 $message = sprintf($format, $fieldConfiguration['sourcePath'] . $item, $table, $row['uid'], $fieldname);
                 $customMessages .= PHP_EOL . $message;
                 continue;
             }
         }
         if ($fileUid > 0) {
             $fields = ['fieldname' => $fieldname, 'table_local' => 'sys_file', 'pid' => $table === 'pages' ? $row['uid'] : $row['pid'], 'uid_foreign' => $row['uid'], 'uid_local' => $fileUid, 'tablenames' => $table, 'crdate' => time(), 'tstamp' => time(), 'sorting' => $i + 256, 'sorting_foreign' => $i];
             if (isset($titleTextField)) {
                 $fields['title'] = trim($titleTextContents[$i]);
             }
             if (isset($alternativeTextField)) {
                 $fields['alternative'] = trim($alternativeTextContents[$i]);
             }
             if (isset($captionField)) {
                 $fields['description'] = trim($captionContents[$i]);
             }
             if (isset($linkField)) {
                 $fields['link'] = trim($linkContents[$i]);
             }
             $this->database->exec_INSERTquery('sys_file_reference', $fields);
             $queries[] = str_replace(LF, ' ', $this->database->debug_lastBuiltQuery);
             ++$i;
         }
     }
     // Update referencing table's original field to now contain the count of references,
     // but only if all new references could be set
     if ($i === count($fieldItems)) {
         $this->database->exec_UPDATEquery($table, 'uid=' . $row['uid'], [$fieldname => $i]);
         $queries[] = str_replace(LF, ' ', $this->database->debug_lastBuiltQuery);
     } else {
         $this->recordOffset[$table]++;
     }
     return $queries;
 }
Esempio n. 28
0
 /**
  * Looks up an ID value (integer) in lookup-table based on input alias value.
  * (The lookup table for id<->alias is meant to contain UNIQUE alias strings for id integers)
  * In the lookup table 'tx_realurl_uniqalias' the field "value_alias" should be unique (per combination of field_alias+field_id+tablename)! However the "value_id" field doesn't have to; that is a feature which allows more aliases to point to the same id. The alias selected for converting id to alias will be the first inserted at the moment. This might be more intelligent in the future, having an order column which can be controlled from the backend for instance!
  *
  * @param array $configuration
  * @param string $aliasValue
  * @param boolean $onlyNonExpired
  * @return int ID integer. If none is found: false
  */
 protected function getFromAliasCacheByAliasValue(array $configuration, $aliasValue, $onlyNonExpired)
 {
     $row = $this->databaseConnection->exec_SELECTgetSingleRow('value_id', 'tx_realurl_uniqalias', 'value_alias=' . $this->databaseConnection->fullQuoteStr($aliasValue, 'tx_realurl_uniqalias') . ' AND field_alias=' . $this->databaseConnection->fullQuoteStr($configuration['alias_field'], 'tx_realurl_uniqalias') . ' AND field_id=' . $this->databaseConnection->fullQuoteStr($configuration['id_field'], 'tx_realurl_uniqalias') . ' AND tablename=' . $this->databaseConnection->fullQuoteStr($configuration['table'], 'tx_realurl_uniqalias') . ' AND ' . ($onlyNonExpired ? 'expire=0' : '(expire=0 OR expire>' . time() . ')'));
     return is_array($row) ? (int) $row['value_id'] : false;
 }
 /**
  * Get a user from DB by username
  * provided for usage from services
  *
  * @param array $dbUser User db table definition: $this->db_user
  * @param string $username user name
  * @param string $extraWhere Additional WHERE clause: " AND ...
  * @return mixed User array or FALSE
  * @todo Define visibility
  */
 public function fetchUserRecord($dbUser, $username, $extraWhere = '')
 {
     $user = FALSE;
     $usernameClause = $username ? $dbUser['username_column'] . '=' . $this->db->fullQuoteStr($username, $dbUser['table']) : '1=1';
     if ($username || $extraWhere) {
         // Look up the user by the username and/or extraWhere:
         $dbres = $this->db->exec_SELECTquery('*', $dbUser['table'], $usernameClause . $dbUser['check_pid_clause'] . $dbUser['enable_clause'] . $extraWhere);
         if ($dbres) {
             $user = $this->db->sql_fetch_assoc($dbres);
             $this->db->sql_free_result($dbres);
         }
     }
     return $user;
 }
 /**
  * @test
  * @dataProvider fullQuoteStrReturnsQuotedStringDataProvider
  *
  * @param string $values
  * @param string $expectedResult
  *
  * @return void
  */
 public function fullQuoteStrReturnsQuotedString($values, $expectedResult)
 {
     /** @var DatabaseConnection $subject */
     $quotedStr = $this->subject->fullQuoteStr($values[0], 'tt_content', $values[1]);
     $this->assertEquals($expectedResult, $quotedStr);
 }