/** * Runs the update. */ public function main() { if ($this->pathCacheNeedsUpdates()) { $this->databaseConnection->sql_query('ALTER TABLE tx_realurl_pathcache CHANGE cache_id uid int(11) NOT NULL'); $this->databaseConnection->sql_query('ALTER TABLE tx_realurl_pathcache DROP PRIMARY KEY'); $this->databaseConnection->sql_query('ALTER TABLE tx_realurl_pathcache MODIFY uid int(11) NOT NULL auto_increment primary key'); } }
/** * @return boolean TRUE on success, FALSE otherwise */ public function release() { $res = $this->connection->sql_query(sprintf('SELECT RELEASE_LOCK("%s") AS res', $this->identifier)); if ($res) { $releaseLockRes = $res->fetch_assoc(); return (int) $releaseLockRes['res'] === 1; } return false; }
/** * Sores the association for future use * * @param string $serverUrl Server URL * @param \Auth_OpenID_Association $association OpenID association * @return void */ public function storeAssociation($serverUrl, $association) { /* @var $association \Auth_OpenID_Association */ $this->databaseConnection->sql_query('START TRANSACTION'); if ($this->doesAssociationExist($serverUrl, $association)) { $this->updateExistingAssociation($serverUrl, $association); } else { $this->storeNewAssociation($serverUrl, $association); } $this->databaseConnection->sql_query('COMMIT'); }
/** * @param $query * @return Tx_PtExtlist_Domain_DataBackend_DataSource_Typo3DataSource * @throws Exception */ public function executeQuery($query) { try { $this->startTimeMeasure(); $this->resource = $this->connection->sql_query($query); $this->stopTimeMeasure(); } catch (Exception $e) { throw new Exception('Error while retrieving data from database using typo3 db object.<br> Error: ' . $e->getMessage() . ' sql_error says: ' . $this->connection->sql_error() . ' 1280400023<br><br> SQL QUERY: <br> </strong><hr>' . nl2br($query) . '<hr><strong>', 1280400023); } return $this; }
/** * 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')); }
/** * Get column names * * @since 1.0.0 * * @param $table * * @return array */ protected function getColumnNames($table) { $table = preg_replace('/[^a-z0-9_]/', '', $table); if (isset($this->tableColumnCache[$table])) { return $this->tableColumnCache[$table]; } else { $result = $this->databaseConnection->exec_SELECTgetSingleRow('*', $table, '1 = 1'); if ($result) { $columnNames = array_keys($result); $this->tableColumnCache[$table] = $columnNames; } else { $columnNames = array(); $result = $this->databaseConnection->sql_query('SELECT DATABASE();'); $row = $this->databaseConnection->sql_fetch_row($result); $databaseName = $row[0]; $this->databaseConnection->sql_free_result($result); $result = $this->databaseConnection->sql_query("SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = '" . $databaseName . "' AND TABLE_NAME = '" . $table . "';"); while ($row = $this->databaseConnection->sql_fetch_row($result)) { $columnNames[] = $row[0]; } $this->databaseConnection->sql_free_result($result); $this->tableColumnCache[$table] = $columnNames; } return $columnNames; } }
/** * 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=""', $storage->getUid())); 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; }
/** * Checks if the primary key needs updates (this is something that TYPO3 * sql parser fails to do for years) and does necessary changes. * * @return void */ protected function checkAndUpdatePathCachePrimaryKey() { if ($this->pathCacheNeedsUpdates()) { $this->databaseConnection->sql_query('ALTER TABLE tx_realurl_pathdata CHANGE cache_id uid int(11) NOT NULL'); $this->databaseConnection->sql_query('ALTER TABLE tx_realurl_pathdata DROP PRIMARY KEY'); $this->databaseConnection->sql_query('ALTER TABLE tx_realurl_pathdata MODIFY uid int(11) NOT NULL auto_increment PRIMARY KEY'); } }
/** * Remove dummy record and drop field * * @return void */ private function dropDummyField() { $sql = 'ALTER TABLE %s DROP COLUMN is_dummy_record'; foreach ($this->tables as $table) { $_sql = sprintf($sql, $table); $this->database->sql_query($_sql); } }
/** * @test */ public function importingExtension() { $this->importExtensions(array('extbase')); /** @var mysqli_result|resource $res */ $res = $this->db->sql_query('show tables'); $rows = $this->db->sql_num_rows($res); self::assertNotSame(0, $rows); }
/** * Limits amount of records in the table. This does not run often. * Records are removed in the uid order (oldest first). This is not a true * clean up, which would be based on the last access timestamp but good * enough to maintain performance. * * @param string $tableName * @return bool */ protected function limitTableRecords($tableName) { $cleanedUp = false; if (mt_rand(0, mt_getrandmax()) % 5 == 0) { $this->databaseConnection->sql_query('DELETE FROM ' . $tableName . ' WHERE uid <= (SELECT t2.uid FROM (SELECT uid FROM ' . $tableName . ' ORDER BY uid DESC LIMIT ' . self::$maximumNumberOfRecords . ',1) t2)'); $cleanedUp = $this->databaseConnection->sql_affected_rows() > 0; } return $cleanedUp; }
/** * Removes existing relations from the mm table from the database */ protected function deleteExistingRelations() { $deleteQuery = $this->typo3Db->DELETEquery($this->table, $this->uidLocalField . '=' . $this->localUid); $this->utilityFuncs->debugMessage('sql_request', array($deleteQuery)); $deleteResult = $this->typo3Db->sql_query($deleteQuery); if (!$deleteResult) { $this->utilityFuncs->throwException('Error in SQL query for deleting existing relations: ' . $this->typo3Db->sql_error()); } }
/** * Fetches the UIDs of all maximal versions for all extensions. * This is done by doing a LEFT JOIN to itself ("a" and "b") and comparing * both integer_version fields. * * @param int $repositoryUid * @return array */ protected function fetchMaximalVersionsForAllExtensions($repositoryUid) { $queryResult = $this->databaseConnection->sql_query('SELECT a.uid AS uid ' . 'FROM ' . self::TABLE_NAME . ' a ' . 'LEFT JOIN ' . self::TABLE_NAME . ' b ON a.repository = b.repository AND a.extension_key = b.extension_key AND a.integer_version < b.integer_version ' . 'WHERE a.repository = ' . (int) $repositoryUid . ' AND b.extension_key IS NULL ' . 'ORDER BY a.uid'); $extensionUids = array(); while ($row = $this->databaseConnection->sql_fetch_assoc($queryResult)) { $extensionUids[] = $row['uid']; } $this->databaseConnection->sql_free_result($queryResult); return $extensionUids; }
/** * Check if there are still resources left for the process with the given id * Used to determine timeouts and to ensure a proper cleanup if there's a timeout * * @param string identification string for the process * @return boolean determines if the process is still active / has resources */ function CLI_checkIfProcessIsActive($pid) { $ret = false; $this->db->sql_query('BEGIN'); $res = $this->db->exec_SELECTquery('process_id,active,ttl', 'tx_crawler_process', 'process_id = \'' . $pid . '\' AND deleted=0', '', 'ttl', '0,1'); if ($row = $this->db->sql_fetch_assoc($res)) { $ret = intVal($row['active']) == 1; } $this->db->sql_query('COMMIT'); return $ret; }
/** * Add is_dummy_record record and create dummy record * * @return void */ private function prepareTables() { $sql = 'ALTER TABLE %s ADD is_dummy_record tinyint(1) unsigned DEFAULT \'0\' NOT NULL'; foreach ($this->tables as $table) { $_sql = sprintf($sql, $table); $this->database->sql_query($_sql); } $values = array('title' => $this->getUniqueId('title'), 'l10n_diffsource' => '', 'description' => '', 'is_dummy_record' => 1); $this->database->exec_INSERTquery('sys_category', $values); $this->categoryUid = $this->database->sql_insert_id(); }
/** * Migrates backend and/or frontend users that were previously imported * with eu_ldap. * * @param array &$out * @return void */ protected function migrateEuLdapUsers(array &$out) { foreach (array('fe_users', 'be_users') as $table) { $query = <<<SQL UPDATE {$table} SET tx_igldapssoauth_dn=tx_euldap_dn WHERE tx_igldapssoauth_dn='' AND tx_euldap_dn<>'' SQL; $this->databaseConnection->sql_query($query); } $out[] = $this->formatOk('Successfully migrated eu_ldap users.'); }
/** * Find the affected page ids by going through all the flexforms of all * active fal gallery content elements and checking if the current folder * is contained in the settings folder. * * @param Folder $folder The folder to check * * @return array */ protected function getAffectedPageIds(Folder $folder) { $pids = array(); if ($folder->getStorage()->getDriverType() === 'Local') { $res = $this->databaseConnection->sql_query("\n\t\t\t\tSELECT\n\t\t\t\t\tpid,\n\t\t\t\t\tExtractValue(pi_flexform, '/T3FlexForms/data/sheet[@index=''list'']/language/field[@index=''settings.default.folder'']/value') as folder\n\t\t\t\tFROM\n\t\t\t\t\ttt_content\n\t\t\t\tWHERE\n\t\t\t\t\tlist_type = 'falgallery_pi1'\n\t\t\t\t\tAND deleted = 0\n\t\t\t\t\tAND hidden = 0\n\t\t\t\t\tAND ExtractValue(pi_flexform, '/T3FlexForms/data/sheet[@index=''list'']/language/field[@index=''settings.default.folder'']/value') LIKE 'file:" . $folder->getCombinedIdentifier() . "%'"); while ($row = $this->databaseConnection->sql_fetch_assoc($res)) { $pids[] = $row['pid']; } $this->databaseConnection->sql_free_result($res); } return $pids; }
/** * Query marker * * @return string */ public function queryMaker() { $output = ''; if (is_array($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['t3lib_fullsearch'])) { $this->hookArray = $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['t3lib_fullsearch']; } $msg = $this->procesStoreControl(); if (!$this->backendUserAuthentication->userTS['mod.']['dbint.']['disableStoreControl']) { $output .= '<h2>Load/Save Query</h2>'; $output .= '<div>' . $this->makeStoreControl() . '</div>'; $output .= $msg; } // Query Maker: $qGen = GeneralUtility::makeInstance(QueryGenerator::class); $qGen->init('queryConfig', $GLOBALS['SOBE']->MOD_SETTINGS['queryTable']); if ($this->formName) { $qGen->setFormName($this->formName); } $tmpCode = $qGen->makeSelectorTable($GLOBALS['SOBE']->MOD_SETTINGS); $output .= '<div id="query"></div>' . '<h2>Make query</h2><div>' . $tmpCode . '</div>'; $mQ = $GLOBALS['SOBE']->MOD_SETTINGS['search_query_makeQuery']; // Make form elements: if ($qGen->table && is_array($GLOBALS['TCA'][$qGen->table])) { if ($mQ) { // Show query $qGen->enablePrefix = 1; $qString = $qGen->getQuery($qGen->queryConfig); switch ($mQ) { case 'count': $qExplain = $this->databaseConnection->SELECTquery('count(*)', $qGen->table, $qString . BackendUtility::deleteClause($qGen->table)); break; default: $qExplain = $qGen->getSelectQuery($qString); if ($mQ == 'explain') { $qExplain = 'EXPLAIN ' . $qExplain; } } if (!$this->backendUserAuthentication->userTS['mod.']['dbint.']['disableShowSQLQuery']) { $output .= '<h2>SQL query</h2><div>' . $this->tableWrap(htmlspecialchars($qExplain)) . '</div>'; } $res = @$this->databaseConnection->sql_query($qExplain); if ($this->databaseConnection->sql_error()) { $out = '<p><strong>Error: <span class="text-danger">' . $this->databaseConnection->sql_error() . '</span></strong></p>'; $output .= '<h2>SQL error</h2><div>' . $out . '</div>'; } else { $cPR = $this->getQueryResultCode($mQ, $res, $qGen->table); $this->databaseConnection->sql_free_result($res); $output .= '<h2>' . $cPR['header'] . '</h2><div>' . $cPR['content'] . '</div>'; } } } return '<div class="query-builder">' . $output . '</div>'; }
/** * Update reference counters for given table and fieldmapping * * @param string $table * * @return void */ protected function updateReferenceCounters($table) { $set = array(); $this->controller->successMessage(LocalizationUtility::translate('updateReferenceCounters', 'dam_falmigration')); foreach ($this->fieldMapping as $old => $new) { if ($this->isFieldAvailable($new, $table)) { $set[] = $new . ' = ' . $old; } } if (count($set)) { $this->database->sql_query('UPDATE ' . $table . ' SET ' . implode(',', $set)); } }
/** * Updates the FlexForm data in the given outdated content element. * * @param array $outdatedContent * @param array &$dbQueries Queries done in this update */ protected function updateOutdatedContentFlexForm($outdatedContent, array &$dbQueries) { $flexFormArray = GeneralUtility::xml2array($outdatedContent['pi_flexform']); if (isset($flexFormArray['data']['rss']['lDEF']['settings.list.rss.channel'])) { $title = $flexFormArray['data']['rss']['lDEF']['settings.list.rss.channel']; unset($flexFormArray['data']['rss']['lDEF']['settings.list.rss.channel']); $flexFormArray['data']['rss']['lDEF']['settings.list.rss.channel.title'] = $title; } $flexFormData = $this->flexObj->flexArray2Xml($flexFormArray); $query = $this->db->UPDATEquery('tt_content', 'uid=' . (int) $outdatedContent['uid'], array('pi_flexform' => $flexFormData)); $this->db->sql_query($query); $dbQueries[] = $query; }
/** * Migrate locations with relations * * @return void */ protected function migrateLocations() { $locations = $this->fetchLocations(); while ($row = $this->database->sql_fetch_assoc($locations)) { $location = $this->mapFieldsPreImport($row, 'locations'); $table = 'tx_storefinder_domain_model_location'; if ($record = $this->isAlreadyImported($location, $table)) { unset($location['import_id']); $this->database->exec_UPDATEquery($table, 'uid = ' . $record['uid'], $location); $this->records['locations'][$row['uid']] = $location['uid'] = $record['uid']; } else { $this->database->exec_INSERTquery($table, $location); $this->records['locations'][$row['uid']] = $location['uid'] = $this->database->sql_insert_id(); } $this->mapFieldsPostImport($row, $location, 'locations'); $this->migrateFilesToFal($row, $location, $this->fileMapping['locations']['media']); $this->migrateFilesToFal($row, $location, $this->fileMapping['locations']['imageurl']); $this->migrateFilesToFal($row, $location, $this->fileMapping['locations']['icon']); } $this->database->sql_query(' update tx_storefinder_domain_model_location AS l LEFT JOIN ( SELECT uid_foreign, COUNT(*) AS count FROM sys_category_record_mm WHERE tablenames = \'tx_storefinder_domain_model_location\' AND fieldname = \'categories\' GROUP BY uid_foreign ) AS c ON l.uid = c.uid_foreign set l.categories = COALESCE(c.count, 0); '); $this->database->sql_query(' update tx_storefinder_domain_model_location AS l LEFT JOIN ( SELECT uid_local, COUNT(*) AS count FROM tx_storefinder_location_attribute_mm GROUP BY uid_local ) AS a ON l.uid = a.uid_local set l.attributes = COALESCE(a.count, 0); '); $this->database->sql_query(' update tx_storefinder_domain_model_location AS l LEFT JOIN ( SELECT uid_local, COUNT(*) AS count FROM tx_storefinder_location_location_mm GROUP BY uid_local ) AS a ON l.uid = a.uid_local set l.related = COALESCE(a.count, 0); '); $this->messageArray[] = array('message' => count($this->records['locations']) . ' locations migrated'); }
/** * Returns the number of tuples matching the query. * * @throws \TYPO3\CMS\Extbase\Persistence\Generic\Storage\Exception\BadConstraintException * @return int The number of matching tuples */ public function countResult() { $parameters = array(); $statementParts = $this->parseQuery($this->query, $parameters); $statementParts = $this->processStatementStructureForRecursiveMMRelation($statementParts); // Mmm... check if that is the right way of doing that. // Reset $statementParts for valid table return reset($statementParts); // if limit is set, we need to count the rows "manually" as COUNT(*) ignores LIMIT constraints if (!empty($statementParts['limit'])) { $statement = $this->buildQuery($statementParts); $this->replacePlaceholders($statement, $parameters, current($statementParts['tables'])); #print $statement; exit(); // @debug $result = $this->databaseHandle->sql_query($statement); $this->checkSqlErrors($statement); $count = $this->databaseHandle->sql_num_rows($result); } else { $statementParts['fields'] = array('COUNT(*)'); // having orderings without grouping is not compatible with non-MySQL DBMS $statementParts['orderings'] = array(); if (isset($statementParts['keywords']['distinct'])) { unset($statementParts['keywords']['distinct']); $distinctField = $this->query->getDistinct() ? $this->query->getDistinct() : 'uid'; $statementParts['fields'] = array('COUNT(DISTINCT ' . reset($statementParts['tables']) . '.' . $distinctField . ')'); } $statement = $this->buildQuery($statementParts); $this->replacePlaceholders($statement, $parameters, current($statementParts['tables'])); #print $statement; exit(); // @debug $result = $this->databaseHandle->sql_query($statement); $this->checkSqlErrors($statement); $count = 0; if ($result) { $row = $this->databaseHandle->sql_fetch_assoc($result); $count = current($row); } } $this->databaseHandle->sql_free_result($result); return (int) $count; }
/** * @param \GeorgRinger\News\Domain\Model\News $news * @param $pidList * @param $sortField * @return array */ protected function getNeighbours(\GeorgRinger\News\Domain\Model\News $news, $pidList, $sortField) { $pidList = empty($pidList) ? $news->getPid() : $pidList; $select = 'SELECT tx_news_domain_model_news.uid,tx_news_domain_model_news.title '; $from = 'FROM tx_news_domain_model_news'; $whereClause = 'tx_news_domain_model_news.pid IN(' . $this->databaseConnection->cleanIntList($pidList) . ') ' . $this->getEnableFieldsWhereClauseForTable(); $query = $select . $from . ' WHERE ' . $whereClause . ' && ' . $sortField . ' >= (SELECT MAX(' . $sortField . ') ' . $from . ' WHERE ' . $whereClause . ' AND ' . $sortField . ' < (SELECT ' . $sortField . ' FROM tx_news_domain_model_news WHERE tx_news_domain_model_news.uid = ' . $news->getUid() . ')) ORDER BY ' . $sortField . ' ASC LIMIT 3'; $query2 = $select . $from . ' WHERE ' . $whereClause . ' AND ' . $sortField . '= (SELECT MIN(' . $sortField . ') FROM tx_news_domain_model_news WHERE ' . $whereClause . ' AND ' . $sortField . ' > (SELECT ' . $sortField . ' FROM tx_news_domain_model_news WHERE tx_news_domain_model_news.uid = ' . $news->getUid() . ')) '; $res = $this->databaseConnection->sql_query($query); $out = array(); while ($row = $this->databaseConnection->sql_fetch_assoc($res)) { $out[] = $row; } $this->databaseConnection->sql_free_result($res); if (count($out) === 0) { $res = $this->databaseConnection->sql_query($query2); while ($row = $this->databaseConnection->sql_fetch_assoc($res)) { $out[] = $row; } $this->databaseConnection->sql_free_result($res); return $out; } return $out; }
/** * Checks if a Value Object equal to the given Object exists in the data base * * @param \TYPO3\CMS\Extbase\DomainObject\AbstractValueObject $object The Value Object * @return mixed The matching uid if an object was found, else FALSE * @todo this is the last monster in this persistence series. refactor! */ public function getUidOfAlreadyPersistedValueObject(\TYPO3\CMS\Extbase\DomainObject\AbstractValueObject $object) { $fields = array(); $parameters = array(); $dataMap = $this->dataMapper->getDataMap(get_class($object)); $properties = $object->_getProperties(); foreach ($properties as $propertyName => $propertyValue) { // @todo We couple the Backend to the Entity implementation (uid, isClone); changes there breaks this method if ($dataMap->isPersistableProperty($propertyName) && $propertyName !== 'uid' && $propertyName !== 'pid' && $propertyName !== 'isClone') { if ($propertyValue === NULL) { $fields[] = $dataMap->getColumnMap($propertyName)->getColumnName() . ' IS NULL'; } else { $fields[] = $dataMap->getColumnMap($propertyName)->getColumnName() . '=?'; $parameters[] = $this->dataMapper->getPlainValue($propertyValue); } } } $sql = array(); $sql['additionalWhereClause'] = array(); $tableName = $dataMap->getTableName(); $this->addVisibilityConstraintStatement(new \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings(), $tableName, $sql); $statement = 'SELECT * FROM ' . $tableName; $statement .= ' WHERE ' . implode(' AND ', $fields); if (!empty($sql['additionalWhereClause'])) { $statement .= ' AND ' . implode(' AND ', $sql['additionalWhereClause']); } $this->replacePlaceholders($statement, $parameters, $tableName); // debug($statement,-2); $res = $this->databaseHandle->sql_query($statement); $this->checkSqlErrors($statement); $row = $this->databaseHandle->sql_fetch_assoc($res); if ($row !== FALSE) { return (int) $row['uid']; } else { return FALSE; } }
/** * Run queries * * Since this method is mainly used without SQL SELECTs, there is no PHP resource available * and thus no mysql_free_result() is necessary. * * @return void */ protected function runQueries() { foreach ($this->queries as $query) { $this->connection->sql_query($query); } }
/** * Returns true if a specified database table contains record rows: the existence of a table ashould have been checked before using Tx_PtExtbase_Div::dbTableExists()! * * @param string database table name to check * @param string database name of the table to check * @param DatabaseConnection database object of type \TYPO3\CMS\Core\Database\DatabaseConnection to use (e.g. $GLOBALS['TYPO3_DB'] to use TYPO3 default database) * @return boolean TRUE if specified table contains record rows, FALSE if not * @throws \PunktDe\PtExtbase\Exception\Exception if the SHOW TABLE STATUS query fails/returns false */ public static function dbTableHasRecords($table, $dbName, DatabaseConnection $dbObj) { $tableHasRecords = false; $query = 'SHOW TABLE STATUS FROM ' . $dbObj->quoteStr($dbName, $table) . ' LIKE "' . $dbObj->quoteStr($table, $table) . '"'; // exec query using TYPO3 DB API $res = $dbObj->sql_query($query); if ($res == false) { throw new \PunktDe\PtExtbase\Exception\Exception('Query failed', 1, $dbObj->sql_error()); } $a_row = $dbObj->sql_fetch_assoc($res); $dbObj->sql_free_result($res); // check number of table rows if ($a_row['Rows'] > 0) { $tableHasRecords = true; } return $tableHasRecords; }
/** * @param string $tableName * @return bool */ protected function tableExists($tableName) { $res = $this->databaseConnection->sql_query(sprintf('SHOW TABLES LIKE \'%s\'', $tableName)); return (bool) $this->databaseConnection->sql_num_rows($res); }
/** * Conducts the data import from the CHC Forum extension. * * @author Nepa Design <*****@*****.**> * @version 2007-05-03 * @deprecated Was replaced by a better import procedure in version 0.1.4 */ function import_chc_deprecated() { $GLOBALS['TYPO3_DB']->exec_TRUNCATEquery('tx_mmforum_forums'); $GLOBALS['TYPO3_DB']->exec_TRUNCATEquery('tx_mmforum_posts'); $GLOBALS['TYPO3_DB']->exec_TRUNCATEquery('tx_mmforum_postread'); $GLOBALS['TYPO3_DB']->exec_TRUNCATEquery('tx_mmforum_posts_text'); $GLOBALS['TYPO3_DB']->exec_TRUNCATEquery('tx_mmforum_topics'); $anz_cat = $anz_forum = $anz_threads = $anz_posts = 0; $pid = $this->pid; //FORUM KATEGORIE $sql = 'SELECT * FROM tx_chcforum_category'; $query = $this->dbObj->sql_query($sql); while ($res = $this->dbObj->sql_fetch_assoc($query)) { $sql_insert = 'INSERT INTO tx_mmforum_forums SET uid = ' . $res['uid'] . ', pid = ' . $pid . ', deleted = ' . $res['deleted'] . ', hidden = ' . $res['hidden'] . ', tstamp = ' . $res['tstamp'] . ', crdate = ' . $res['crdate'] . ', forum_name = "' . $res['cat_title'] . '" '; $GLOBALS['TYPO3_DB']->sql_query($sql_insert); $anz_cat++; } //FORUM KONFERENZ $sql = 'SELECT *, w.forumgroup_groups as group_write, r.forumgroup_groups as group_read FROM tx_chcforum_conference, tx_chcforum_forumgroup w, tx_chcforum_forumgroup r WHERE w.uid = tx_chcforum_conference.auth_forumgroup_w AND r.uid = tx_chcforum_conference.auth_forumgroup_r'; $query = $this->dbObj->sql_query($sql); while ($res = $this->dbObj->sql_fetch_assoc($query)) { $anz_forum++; $sql_insert = 'INSERT INTO tx_mmforum_forums SET pid = ' . $pid . ', tstamp = ' . $res['tstamp'] . ', crdate = ' . $res['crdate'] . ', hidden = ' . $res['hidden'] . ', parentID = ' . $res['cat_id'] . ', deleted = ' . $res['deleted'] . ', grouprights_read = "' . $res['group_read'] . '", grouprights_write = "' . $res['group_write'] . '", forum_name = "' . $res['conference_name'] . '", forum_desc = "' . $res['conference_desc'] . '" '; $GLOBALS['TYPO3_DB']->sql_query($sql_insert); $conference_id = $res['uid']; $forum_uid = $GLOBALS['TYPO3_DB']->sql_insert_id(); $topics = 0; $posts_ges = 0; //FORUM THREADS ERZEUGEN $sql_topic = 'SELECT * FROM tx_chcforum_thread WHERE conference_id=' . $conference_id; $query_topic = $this->dbObj->sql_query($sql_topic); while ($res_topic = $this->dbObj->sql_fetch_assoc($query_topic)) { $sql_insert = 'INSERT INTO tx_mmforum_topics SET uid = ' . $res_topic['uid'] . ', pid = ' . $pid . ', tstamp = ' . $res_topic['tstamp'] . ', crdate = ' . $res_topic['crdate'] . ', deleted = ' . $res_topic['deleted'] . ', hidden = ' . $res_topic['hidden'] . ', forum_id = ' . $forum_uid . ', closed_flag = ' . $res_topic['thread_closed'] . ', topic_title = "' . $res_topic['thread_subject'] . '", topic_poster = ' . $res_topic['thread_author'] . ', cruser_id = ' . $res_topic['thread_author'] . ', topic_time = ' . $res_topic['thread_datetime'] . ', topic_last_post_id = ' . $res_topic['thread_lastpostid'] . ', topic_first_post_id = ' . $res_topic['thread_firstpostid'] . ' '; $GLOBALS['TYPO3_DB']->sql_query($sql_insert); $topics++; $anz_threads++; $posts = -1; //Forum Posts erzeugen $sql_post = 'SELECT * FROM tx_chcforum_post WHERE thread_id=' . $res_topic['uid']; $query_post = $this->dbObj->sql_query($sql_post); while ($res_post = $this->dbObj->sql_fetch_assoc($query_post)) { $sql_insert = 'INSERT INTO tx_mmforum_posts SET uid = ' . $res_post['uid'] . ', pid = ' . $pid . ', tstamp = ' . $res_post['tstamp'] . ', crdate = ' . $res_post['crdate'] . ', deleted = ' . $res_post['deleted'] . ', hidden = ' . $res_post['hidden'] . ', forum_id = ' . $forum_uid . ', topic_id = ' . $res_topic['uid'] . ', cruser_id = ' . $res_post['post_author'] . ', poster_id = ' . $res_post['post_author'] . ', poster_ip = "' . $res_post['post_author_ip'] . '", post_time = ' . $res_post['crdate'] . ', edit_time = ' . $res_post['post_edit_tstamp'] . ', edit_count = ' . $res_post['post_edit_count'] . ' '; $GLOBALS['TYPO3_DB']->sql_query($sql_insert); $sql_insert = 'INSERT INTO tx_mmforum_posts_text SET uid = ' . $res_post['uid'] . ', pid = ' . $pid . ', tstamp = ' . $res_post['tstamp'] . ', crdate = ' . $res_post['crdate'] . ', deleted = ' . $res_post['deleted'] . ', hidden = ' . $res_post['hidden'] . ', post_id = ' . $res_post['uid'] . ', post_text = "' . $GLOBALS['TYPO3_DB']->quoteStr($res_post['post_text'], '') . '" '; $GLOBALS['TYPO3_DB']->sql_query($sql_insert); $posts++; $anz_posts++; } $posts_ges = $posts_ges + $posts + 1; $sql_update = 'UPDATE tx_mmforum_topics SET topic_replies = ' . $posts . ', topic_views = ' . $posts . ' WHERE uid=' . $res_topic['uid']; $GLOBALS['TYPO3_DB']->sql_query($sql_update); } $sql_last = 'SELECT topic_last_post_id FROM tx_mmforum_topics WHERE forum_id=' . $forum_uid . ' ORDER BY crdate DESC LIMIT 1'; $query_last = $GLOBALS['TYPO3_DB']->sql_query($sql_last); $res_last = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($query_last); $sql_update = 'UPDATE tx_mmforum_forums SET forum_posts = ' . $posts_ges . ', forum_last_post_id=' . $res_last['topic_last_post_id'] . ' , forum_topics = ' . $topics . ' WHERE uid=' . $forum_uid; $GLOBALS['TYPO3_DB']->sql_query($sql_update); } //Benutzer die im Forum gepostet haben auslesen $sql = 'SELECT poster_id FROM tx_mmforum_posts WHERE deleted=0 AND hidden = 0 GROUP BY poster_id'; $query = $GLOBALS['TYPO3_DB']->sql_query($sql); while ($res = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($query)) { //Anzahl der Postings pro Benutzer auslesen $sql_count = 'SELECT COUNT(uid) AS anzahl FROM tx_mmforum_posts WHERE deleted=0 AND hidden=0 AND poster_id=' . $res['poster_id']; $query_count = $GLOBALS['TYPO3_DB']->sql_query($sql_count); $res_count = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($query_count); //Benutzer mit der Anzahl der Postings Updaten $sql = 'UPDATE fe_users SET tx_mmforum_posts=' . $res_count['anzahl'] . ' WHERE uid=' . $res['poster_id']; $GLOBALS['TYPO3_DB']->sql_query($sql); } $content = '<strong>' . $GLOBALS['LANG']->getLL('chc.success') . '</strong><br/>'; $content .= '<br />' . $GLOBALS['LANG']->getLL('chc.categories') . ': ' . $anz_cat; $content .= '<br />' . $GLOBALS['LANG']->getLL('chc.boards') . ': ' . $anz_forum; $content .= '<br />' . $GLOBALS['LANG']->getLL('chc.topics') . ': ' . $anz_threads; $content .= '<br />' . $GLOBALS['LANG']->getLL('chc.posts') . ': ' . $anz_posts; $content .= '<br />'; return $content; }
/** * Executes query * * EXPERIMENTAL - This method will make its best to handle the query correctly * but if it cannot, it will simply pass the query to DEFAULT handler. * * You should use exec_* function from this class instead! * If you don't, anything that does not use the _DEFAULT handler will probably break! * * MySQLi query() wrapper function * Beware: Use of this method should be avoided as it is experimentally supported by DBAL. You should consider * using exec_SELECTquery() and similar methods instead. * * @param string $query Query to execute * @return bool|\mysqli_result|object MySQLi result object / DBAL object */ public function sql_query($query) { $globalConfig = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['dbal']); if ($globalConfig['sql_query.']['passthrough']) { return parent::sql_query($query); } // This method is heavily used by Extbase, try to handle it with DBAL-native methods $queryParts = $this->SQLparser->parseSQL($query); if (is_array($queryParts) && GeneralUtility::inList('SELECT,UPDATE,INSERT,DELETE', $queryParts['type'])) { return $this->exec_query($queryParts); } $sqlResult = NULL; switch ($this->handlerCfg['_DEFAULT']['type']) { case 'native': if (!$this->isConnected()) { $this->connectDB(); } $sqlResult = $this->handlerInstance['_DEFAULT']['link']->query($query); break; case 'adodb': $sqlResult = $this->handlerInstance['_DEFAULT']->Execute($query); $sqlResult->TYPO3_DBAL_handlerType = 'adodb'; break; case 'userdefined': $sqlResult = $this->handlerInstance['_DEFAULT']->sql_query($query); $sqlResult->TYPO3_DBAL_handlerType = 'userdefined'; break; } $this->lastHandlerKey = '_DEFAULT'; if ($this->printErrors && $this->sql_error()) { debug(array($this->lastQuery, $this->sql_error())); } return $sqlResult; }
/** * Empties the URL cache for one page. * * @param int $pageId * @return void */ public function clearUrlCacheForPage($pageId) { $this->databaseConnection->sql_query('DELETE FROM tx_realurl_uniqalias_cache_map WHERE url_cache_id IN (SELECT cache_id FROM tx_realurl_urlcache WHERE page_id=' . (int) $pageId . ')'); $this->databaseConnection->exec_DELETEquery('tx_realurl_urlcache', 'page_id=' . (int) $pageId); }