/** * @test */ public function doesFindByTypeAndTableNameReturnObjects() { $testUid = rand(1, 1000); $testTable = uniqid('sys_collection_'); $type = \TYPO3\CMS\Core\Collection\RecordCollectionRepository::TYPE_Static; $this->databaseMock->expects($this->once())->method('exec_SELECTgetRows')->will($this->returnCallback(array($this, 'getRowsCallback'))); $this->getRowsCallbackReturnValue = array(array('uid' => $testUid, 'type' => $type, 'table_name' => $this->testTableName), array('uid' => $testUid, 'type' => $type, 'table_name' => $this->testTableName)); $objects = $this->fixture->findByTypeAndTableName($type, $testTable); $this->assertEquals(2, count($objects)); $this->assertInstanceOf('TYPO3\\CMS\\Core\\Collection\\StaticRecordCollection', $objects[0]); $this->assertInstanceOf('TYPO3\\CMS\\Core\\Collection\\StaticRecordCollection', $objects[1]); }
/** * @throws Exception * @return array of options */ protected function getDataFromSqlServer() { $query = $this->dbObj->SELECTquery($this->selectPart, $this->fromPart, $this->wherePart, $this->groupByPart, $this->orderByPart, $this->limitPart); // this method only combines the parts $dataSource = Tx_PtExtlist_Domain_DataBackend_DataBackendFactory::getInstanceByListIdentifier($this->filterConfig->getListIdentifier())->getDataSource(); if (!method_exists($dataSource, 'executeQuery')) { throw new Exception('The defined dataSource has no method executeQuery and is therefore not usable with this dataProvider!', 1315216209); } $data = $dataSource->executeQuery($query)->fetchAll(); if (TYPO3_DLOG) { \TYPO3\CMS\Core\Utility\GeneralUtility::devLog('MYSQL QUERY : ' . $this->filterConfig->getListIdentifier() . ' -> Filter::ExplicitSQLQuery', 'pt_extlist', 1, array('executionTime' => $dataSource->getLastQueryExecutionTime(), 'query' => $query)); } return $data; }
/** * @test */ public function importingDataSet() { if (!t3lib_extMgm::isLoaded('ccc')) { $this->markTestSkipped('This test can only be run if the extension ccc from ' . 'tests/res is installed.'); } $this->importExtensions(array('ccc')); $this->importDataSet(t3lib_extMgm::extPath('phpunit') . 'Tests/Unit/Database/Fixtures/DataSet.xml'); $result = $this->db->exec_SELECTgetRows('*', 'tx_ccc_test', NULL); $this->assertSame(2, count($result), self::DB_PERMISSIONS_MESSAGE); $this->assertSame('1', $result[0]['uid']); $this->assertSame('2', $result[1]['uid']); $result = $this->db->exec_SELECTgetRows('*', 'tx_ccc_data', NULL); $this->assertSame(1, count($result)); $this->assertSame('1', $result[0]['uid']); $result = $this->db->exec_SELECTgetRows('*', 'tx_ccc_data_test_mm', NULL); $this->assertSame(2, count($result)); $this->assertSame('1', $result[0]['uid_local']); $this->assertSame('1', $result[0]['uid_foreign']); $this->assertSame('1', $result[1]['uid_local']); $this->assertSame('2', $result[1]['uid_foreign']); }
/** * @param $selectConf * @return array */ function getArchiveMenuRange($selectConf) { $range = array('minval' => 0, 'maxval' => 0); if ($this->conf['amenuStart']) { $range['minval'] = strtotime($this->conf['amenuStart']); } if ($this->conf['amenuEnd']) { $eTime = strtotime($this->conf['amenuEnd']); if ($eTime > $range['minval']) { $range['maxval'] = $eTime; } } if (!($range['minval'] && $range['maxval'])) { // find minval and/or maxval automatically $selectConf['selectFields'] = ''; if (!$range['minval']) { $selectConf['selectFields'] .= 'MIN(tt_news.datetime) AS minval'; if ($this->conf['ignoreNewsWithoutDatetimeInAmenu']) { $selectConf['where'] .= ' AND tt_news.datetime > 0'; } } if (!$range['maxval']) { $selectConf['selectFields'] .= ($selectConf['selectFields'] ? ', ' : '') . 'MAX(tt_news.datetime) AS maxval'; } $res = $this->exec_getQuery('tt_news', $selectConf); $range = $this->db->sql_fetch_assoc($res); } return $range; }
/** * Selects the database depending on TYPO3 version. * * @param string $databaseName the name of the database to select * @param t3lib_DB $database database object to process the change * * @return boolean */ protected function selectDatabase($databaseName, t3lib_DB $database) { if (t3lib_utility_VersionNumber::convertVersionNumberToInteger(TYPO3_version) < 6001000) { $result = $database->sql_select_db($databaseName); } else { $database->setDatabaseName($databaseName); $result = $database->sql_select_db(); } return $result; }
/** * Rewind the cursor to the first row */ public function rewind() { return $this->connection->sql_data_seek($this->resource, 0); }
/** * Executes a 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! * * This method was deprecated in TYPO3 4.1 but is considered experimental since TYPO3 4.4 * as it tries to handle the query correctly anyway. * * @param string Query to execute * @return pointer Result pointer / 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) && t3lib_div::inList('SELECT,UPDATE,INSERT,DELETE', $queryParts['type'])) { return $this->exec_query($queryParts); } switch ($this->handlerCfg['_DEFAULT']['type']) { case 'native': $sqlResult = mysql_query($query, $this->handlerInstance['_DEFAULT']['link']); 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; } if ($this->printErrors && $this->sql_error()) { debug(array($this->lastQuery, $this->sql_error())); } return $sqlResult; }
/** * Tests if a given table contains a given field. * * @param string $tablename Table name for which to check whether a given field exists in * @param string $fieldname Field name for which to check whether it exists in the given table * @param array $info Additional info, will be displayed as debug message, if a key "message" exists this will be appended to the error message */ public static function tableAndFieldExist($tablename, $fieldname, $info = array()) { self::initializeDbObj(); return self::isArrayKey($fieldname, self::$dbObj->admin_get_fields($tablename), $info); }
/** * Creates a TRUNCATE TABLE SQL-statement * * @param string See exec_TRUNCATEquery() * @return string Full SQL query for TRUNCATE TABLE */ public function TRUNCATEquery($table) { $table = $this->quoteFromTables($table); // Call parent method to build actual query $query = parent::TRUNCATEquery($table); if ($this->debugOutput || $this->store_lastBuiltQuery) { $this->debug_lastBuiltQuery = $query; } return $query; }
/** * Get tree data * * @param integer $uid * @param string $subLevelId * * @return array */ protected function getTreeData($uid, $subLevelId) { // Filter the results by preference and access $clauseExludePidList = ''; if ($pidList = $GLOBALS['BE_USER']->getTSConfigVal('options.hideRecords.pages')) { if ($pidList = $this->databaseHandle->cleanIntList($pidList)) { $clauseExludePidList = ' AND pages.uid NOT IN (' . $pidList . ')'; } } $clause = ' AND ' . $GLOBALS['BE_USER']->getPagePermsClause(1) . ' ' . $clauseExludePidList; /** * We want a page tree with all the excluded pages in there. This means * all pages that have the exclude flag set and also all pages that have the * excludeBranch flag set, including their children. * * 1). First fetch the page id's that have any exclusion options set */ $result = $this->databaseHandle->sql_query(' SELECT GROUP_CONCAT(uid) AS uids FROM pages WHERE tx_tablecleaner_exclude = 1 AND deleted = 0 ' . $clause . '; '); $row = $this->databaseHandle->sql_fetch_assoc($result); $excludePages = array(); if ($row['uids'] !== NULL) { $excludePages = explode(',', $row['uids']); } $this->databaseHandle->sql_free_result($result); $result = $this->databaseHandle->sql_query(' SELECT GROUP_CONCAT(uid) AS uids FROM pages WHERE tx_tablecleaner_exclude_branch = 1 AND deleted = 0 ' . $clause . '; '); $row = $this->databaseHandle->sql_fetch_assoc($result); $excludeBranchPages = array(); if ($row['uids'] !== NULL) { $excludeBranchPages = explode(',', $row['uids']); } $this->databaseHandle->sql_free_result($result); /** * 2). Fetch the id's up to the 'current root' page. * To build a complete page tree, we also need the parents of the * excluded pages. So we merge the found pages and fetch the rootlines for * all those pages. */ $allExcludedPages = array_merge($excludePages, $excludeBranchPages); $allExcludedPages = array_unique($allExcludedPages); $allUids = array(); foreach ($allExcludedPages as $pageId) { // Don't fetch the rootline if the pageId is already in the list if (!in_array($pageId, $allUids)) { // Get the rootline up to the starting uid $rootLine = t3lib_BEfunc::BEgetRootLine($pageId, ' AND NOT uid = ' . $uid . $clause); foreach ($rootLine as $record) { $allUids[] = $record['uid']; } } } /** * 3). Include self */ $allUids[] = $uid; /** * 4). Fetch all the children of the pages that have exclude_branch set. */ foreach ($excludeBranchPages as $pageId) { $allUids = array_merge($allUids, Tx_Tablecleaner_Utility_Base::fetchChildPages($pageId)); } $allUids = array_unique($allUids); $foundPages = $this->pageRepository->findByUids($allUids); $allPages = array(); foreach ($foundPages as $page) { $allPages[$page['uid']] = $page; } $tree = $this->reassembleTree($allPages, $uid, $subLevelId); $rootElement[$uid] = $allPages[$uid]; $rootElement[$uid][$subLevelId] = $tree; return $rootElement; }