php TYPO3-CMS-Core-Database-DatabaseConnection类(方法)实例源码

下面列出了php TYPO3-CMS-Core-Database-DatabaseConnection 类(方法)源码代码实例,从而了解它的用法。

作者:rickymathe    项目:TYPO3.CM   
/**
  * Set up
  *
  * @return void
  */
 protected function setUp()
 {
     $this->database = $this->getMock(DatabaseConnection::class, array('exec_SELECTgetSingleRow'));
     $this->database->expects($this->any())->method('exec_SELECTgetSingleRow')->will($this->returnValue(array('uid' => 0, 'parent' => '')));
     $this->treeData = new TreeNode();
     $GLOBALS['TYPO3_DB'] = $this->database;
 }

作者:stigfaerc    项目:gridelement   
/**
  * initializes this class
  *
  * @param integer $pageUid
  *
  * @return void
  */
 public function init($pageUid)
 {
     $this->setDatabaseConnection($GLOBALS['TYPO3_DB']);
     if (!$this->layoutSetup instanceof LayoutSetup) {
         if ($pageUid < 0) {
             $triggerElement = $this->databaseConnection->exec_SELECTgetSingleRow('pid', 'tt_content', 'uid = ' . -$pageUid);
             $pageUid = (int) $triggerElement['pid'];
         }
         $this->injectLayoutSetup(GeneralUtility::makeInstance(LayoutSetup::class)->init($pageUid));
     }
 }

作者:sr-amuelle    项目:news_ttnewsimpor   
/**
  * Migrate tt_news_categorymounts to category_pems in either be_groups or be_users
  *
  * @param string $table either be_groups or be_users
  */
 public function migrateTtNewsCategoryMountsToSysCategoryPerms($table)
 {
     /** @var \TYPO3\CMS\Core\DataHandling\DataHandler $dataHandler */
     $dataHandler = GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\DataHandling\\DataHandler');
     $dataHandler->admin = TRUE;
     /* assign imported categories to be_groups or be_users */
     $whereClause = 'tt_news_categorymounts != \'\'' . BackendUtility::deleteClause($table);
     $beGroupsOrUsersWithTtNewsCategorymounts = $this->databaseConnection->exec_SELECTgetRows('*', $table, $whereClause);
     $data = array();
     foreach ((array) $beGroupsOrUsersWithTtNewsCategorymounts as $beGroupOrUser) {
         $ttNewsCategoryPermissions = GeneralUtility::trimExplode(',', $beGroupOrUser['tt_news_categorymounts']);
         $sysCategoryPermissions = array();
         foreach ($ttNewsCategoryPermissions as $ttNewsCategoryPermissionUid) {
             $whereClause = 'import_source = \'TT_NEWS_CATEGORY_IMPORT\' AND import_id = ' . $ttNewsCategoryPermissionUid;
             $sysCategory = $this->databaseConnection->exec_SELECTgetSingleRow('uid', 'sys_category', $whereClause);
             if (!empty($sysCategory)) {
                 $sysCategoryPermissions[] = $sysCategory['uid'];
             }
         }
         if (count($sysCategoryPermissions)) {
             $data[$table][$beGroupOrUser['uid']] = array('category_perms' => implode(',', $sysCategoryPermissions) . ',' . $beGroupOrUser['category_perms']);
         }
     }
     $dataHandler->start($data, array());
     $dataHandler->process_datamap();
 }

作者:sirdieg    项目:import   
/**
  * @test
  */
 public function truncate_multiple_tables_when_configured()
 {
     $configuration = ['truncate' => ['test', 'test2', 'test3']];
     $processor = $this->getMockBuilder(Configuration::class)->disableOriginalConstructor()->getMock();
     $this->connection->expects($this->exactly(3))->method('exec_TRUNCATEquery')->withConsecutive(['test'], ['test2'], ['test3']);
     $this->fixture->execute($processor, $configuration);
 }

作者:S3b    项目:project_registratio   
/**
  * @param \S3b0\ProjectRegistration\Scheduler\InfoMail\Task $task
  *
  * @return bool
  */
 public function run(\S3b0\ProjectRegistration\Scheduler\InfoMail\Task $task)
 {
     $settings = unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$this->extensionName]);
     $upperLimit = new \DateTime();
     $lowerLimit = new \DateTime();
     $daysLeft = $settings['warnXDaysBeforeExpireDate'];
     $sender = [$task->getSenderAddress()];
     $receiver = [$task->getReceiverAddress()];
     $subject = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('infomail.subject', $this->extensionName);
     $this->databaseConnection = $GLOBALS['TYPO3_DB'];
     // Upper limit (expiry) = Current date + Days left
     $upperLimit->setTimestamp($upperLimit->getTimestamp() + $daysLeft * 86400);
     // Lower limit (expiry) = Current date + Days left - Scheduler frequency
     $lowerLimit->setTimestamp($lowerLimit->getTimestamp() + $daysLeft * 86400 - $task->getExecution()->getInterval());
     $where = "date_of_expiry > '{$lowerLimit->format('Y-m-d h:i:s')}' AND date_of_expiry < '{$upperLimit->format('Y-m-d h:i:s')}'";
     if ($this->databaseConnection->exec_SELECTcountRows('*', 'tx_projectregistration_domain_model_project', $where)) {
         $expiredProjects = $this->databaseConnection->exec_SELECTgetRows('project.*, registrant.name as registrant_name, registrant.company as registrant_company', 'tx_projectregistration_domain_model_project as project join tx_projectregistration_domain_model_person as registrant on project.registrant=registrant.uid', $where);
         $list = [];
         /** @var array $expiredProject */
         foreach ($expiredProjects as $expiredProject) {
             $list[] = "#{$expiredProject['uid']} - '{$expiredProject['title']}' by {$expiredProject['registrant_name']} ({$expiredProject['registrant_company']})";
         }
         $mailContent = \TYPO3\CMS\Extbase\Utility\LocalizationUtility::translate('infomail.message', $this->extensionName, [$daysLeft, '<li>' . implode('</li><li>', $list) . '</li>']);
         /** @var \TYPO3\CMS\Core\Mail\MailMessage $mail */
         $mail = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Mail\MailMessage::class);
         $mail->setContentType('text/html');
         /**
          * Email to sender
          */
         $mail->setFrom($sender)->setTo($receiver)->setPriority(1)->setSubject($subject)->setBody($mailContent)->send();
     }
     return true;
 }

作者:dachcom-digita    项目:TYPO3.CM   
/**
  * @test
  */
 public function addDataSetsPageLanguageOverlayRows()
 {
     $input = ['effectivePid' => '23'];
     $expected = $input;
     $expected['pageLanguageOverlayRows'] = [0 => ['uid' => '1', 'pid' => '42', 'sys_language_uid' => '2']];
     $this->dbProphecy->exec_SELECTgetRows('*', 'pages_language_overlay', 'pid=23')->shouldBeCalled()->willReturn($expected['pageLanguageOverlayRows']);
     $this->assertSame($expected, $this->subject->addData($input));
 }

作者:beyond-agentu    项目:pt_extbas   
/**
  * @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;
 }

作者:t3d    项目:T3DD16.Backen   
/**
  * @param \TYPO3\Sso\Domain\Model\FrontendUser $frontendUser
  *
  * @throws EmptyUserException
  * @return void
  */
 public function registerSession($frontendUser)
 {
     if (!$frontendUser) {
         throw new EmptyUserException('No user given that can be dropped into the session.', 1329749957);
     }
     $row = $this->db->exec_SELECTgetSingleRow('*', 'fe_users', 'uid = ' . $frontendUser->getUid());
     $this->getFeUser()->createUserSession($row);
     $this->getFeUser()->setSessionCookie();
 }

作者:dachcom-digita    项目:TYPO3.CM   
/**
  * @test
  *
  * @return void
  */
 public function prepareSelectQueryCreateValidQuery()
 {
     $this->assertTrue($this->subject->admin_query("INSERT INTO {$this->testTable} ({$this->testField}) VALUES ('aTestValue')"));
     $preparedQuery = $this->subject->prepare_SELECTquery("{$this->testField},{$this->anotherTestField}", $this->testTable, 'id=:id', '', '', '', [':id' => 1]);
     $preparedQuery->execute();
     $result = $preparedQuery->fetch();
     $expectedResult = [$this->testField => 'aTestValue', $this->anotherTestField => null];
     $this->assertSame($expectedResult, $result);
 }

作者:bernhardberge    项目:powermai   
/**
  * Return Form Uid from content element
  *
  * @param int $ttContentUid
  * @return int
  */
 protected function getFormUidFromTtContentUid($ttContentUid)
 {
     $row = $this->databaseConnection->exec_SELECTgetSingleRow('pi_flexform', 'tt_content', 'uid=' . (int) $ttContentUid);
     $flexform = GeneralUtility::xml2array($row['pi_flexform']);
     if (is_array($flexform) && isset($flexform['data']['main']['lDEF']['settings.flexform.main.form']['vDEF'])) {
         return (int) $flexform['data']['main']['lDEF']['settings.flexform.main.form']['vDEF'];
     }
     return 0;
 }

作者:sitegeis    项目:ext-sol   
/**
  * @test
  */
 public function databaseResultIsUsedWhenNoCachedResultIsPresent()
 {
     $fakeConfiguration = array('select.' => array('checkRootPageId' => true, 'checkLanguage' => true, 'SELECT' => '', 'FROM' => '', 'ADD_WHERE' => '', 'GROUP_BY' => '', 'ORDER_BY' => ''), 'limit');
     $this->configurationMock->expects($this->once())->method('getSearchFrequentSearchesConfiguration')->will($this->returnValue($fakeConfiguration));
     $this->databaseMock->expects($this->once())->method('exec_SELECTgetRows')->will($this->returnValue(array(array('search_term' => 'my search', 'hits' => 22))));
     //we fake that we have no frequent searches in the cache and therefore expect that the database will be queried
     $this->fakeIdentifierNotInCache();
     $frequentTerms = $this->frequentSearchesService->getFrequentSearchTerms();
     $this->assertSame($frequentTerms, array('my search' => 22), 'Could not retrieve frequent search terms');
 }

作者:rabe6    项目:mm_foru   
/**
  * @param $uid
  * @param $parentUid
  */
 function validateParentUid($uid, $parentUid)
 {
     # Always validate for new forums.
     if ($uid == -1) {
         return;
     }
     $res = $this->databaseHandle->exec_SELECTquery('*', 'tx_mmforum_forums', 'parentID=' . intval($uid) . ' AND deleted=0 ' . $this->parent->getStoragePIDQuery());
     if ($this->databaseHandle->sql_num_rows($res) > 0 && $parentUid != 0) {
         $this->addErrorForField('parent', 'no-nested-forums', array($this->databaseHandle->sql_num_rows($res)));
     }
 }

作者:jweiland-ne    项目:clubdirector   
/**
  * add cities to selectbox.
  *
  * @param array                              $parentArray
  * @param \TYPO3\CMS\Backend\Form\FormEngine $fObj
  */
 public function addCityItems(array $parentArray, \TYPO3\CMS\Backend\Form\FormEngine $fObj)
 {
     $this->init();
     $rows = $this->database->exec_SELECTgetRows('city', 'tx_clubdirectory_domain_model_address', '1=1 ' . BackendUtility::BEenableFields('tx_clubdirectory_domain_model_address') . BackendUtility::deleteClause('tx_clubdirectory_domain_model_address'), 'city', 'city', '');
     foreach ($rows as $row) {
         $item = array();
         $item[0] = $row['city'];
         $item[1] = $row['city'];
         $item[2] = null;
         $parentArray['items'][] = $item;
     }
 }

作者:grauru    项目:testgit_t3   
/**
  * Check if the note plugin expects output. If there are no sys_note records on the given
  * pages, the extbase bootstrap doesn't have to run the complete plugin.
  * This mechanism should increase the performance of the hooked backend modules heavily.
  *
  * @param array $arguments Arguments for the extbase plugin
  * @return bool
  */
 protected function expectOutput(array $arguments = array())
 {
     // no pids set
     if (!isset($arguments['pids']) || empty($arguments['pids']) || empty($GLOBALS['BE_USER']->user['uid'])) {
         return false;
     }
     $pidList = $this->databaseConnection->cleanIntList($arguments['pids']);
     if (empty($pidList)) {
         return false;
     }
     // check if there are records
     return $this->databaseConnection->exec_SELECTcountRows('*', 'sys_note', 'pid IN (' . $pidList . ')' . BackendUtility::deleteClause('sys_note')) > 0;
 }

作者:rsenner    项目:google_service   
/**
  * @param int               $startPage
  * @param array             $basePages
  * @param SitemapController $obj
  *
  * @return array
  */
 public function getRecords($startPage, $basePages, SitemapController $obj)
 {
     $nodes = array();
     foreach ($basePages as $uid) {
         if ($this->currentLanguageUid) {
             $fields = $this->cObject->enableFields('pages_language_overlay');
             $overlay = $this->database->exec_SELECTgetSingleRow('uid', 'pages_language_overlay', ' pid=' . intval($uid) . ' AND sys_language_uid=' . $this->currentLanguageUid . $fields);
             if (!is_array($overlay)) {
                 continue;
             }
         }
         // Build URL
         $url = $obj->getUriBuilder()->setTargetPageUid($uid)->build();
         // can't generate a valid url
         if (!strlen($url)) {
             continue;
         }
         // Get Record
         $record = BackendUtility::getRecord('pages', $uid);
         // exclude Doctypes
         if (in_array($record['doktype'], array(4))) {
             continue;
         }
         // Check FE Access
         if ($record['fe_group'] != 0) {
             continue;
         }
         $rootLineList = $GLOBALS['TSFE']->sys_page->getRootLine($record['uid']);
         $addToNode = true;
         foreach ($rootLineList as $rootPage) {
             if ($rootPage['extendToSubpages'] == 1 && $rootPage['fe_group'] != 0) {
                 $addToNode = false;
                 break;
             }
         }
         if ($addToNode == false) {
             continue;
         }
         // Build Node
         $node = new Node();
         $node->setLoc($url);
         $node->setPriority($this->getPriority($startPage, $record));
         $node->setChangefreq(SitemapDataService::mapTimeout2Period($record['cache_timeout']));
         $node->setLastmod($this->getModifiedDate($record));
         #$geo = new Geo();
         #$geo->setFormat('kml');
         #$node->setGeo($geo);
         $nodes[] = $node;
     }
     return $nodes;
 }

作者:kalypso6    项目:px_hybrid_aut   
/**
  * 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;
 }

作者:preinbot    项目:moox_new   
/**
  * Migrate news_category.image (CSV) to sys_category.images (sys_file_reference)
  *
  * @return void
  */
 protected function migrateCategoryImages()
 {
     $oldCategories = $this->databaseConnection->exec_SELECTgetRows('uid, pid, image, migrate_sys_category_uid', 'tx_mooxnews_domain_model_category', 'deleted=0 AND image!=""');
     // no images to process then skip
     if (!count($oldCategories)) {
         return;
     }
     $processedImages = 0;
     foreach ($oldCategories as $oldCategory) {
         $files = \TYPO3\CMS\Core\Utility\GeneralUtility::trimExplode(',', $oldCategory['image'], TRUE);
         $i = 0;
         foreach ($files as $file) {
             if (file_exists(PATH_site . 'uploads/tx_mooxnews/' . $file)) {
                 $fileObject = $this->getCategoryImageFolder()->addFile(PATH_site . 'uploads/tx_mooxnews/' . $file);
                 $dataArray = array('uid_local' => $fileObject->getUid(), 'tstamp' => $_SERVER['REQUEST_TIME'], 'crdate' => $_SERVER['REQUEST_TIME'], 'tablenames' => 'sys_category', 'uid_foreign' => $oldCategory['migrate_sys_category_uid'], 'pid' => $oldCategory['pid'], 'fieldname' => 'images', 'table_local' => 'sys_file', 'sorting_foreign' => $i);
                 $this->databaseConnection->exec_INSERTquery('sys_file_reference', $dataArray);
                 $processedImages++;
             }
             $i++;
         }
     }
     $message = 'Migrated ' . $processedImages . ' category images';
     $status = FlashMessage::INFO;
     $title = '';
     $this->messageArray[] = array($status, $title, $message);
 }

作者:Mr-Robot    项目:TYPO3.CM   
/**
  * Implement normalization according to OpenID 2.0 specification
  * See http://openid.net/specs/openid-authentication-2_0.html#normalization
  *
  * @param string $openIDIdentifier OpenID identifier to normalize
  * @return string Normalized OpenID identifier
  * @throws Exception
  */
 protected function normalizeOpenID($openIDIdentifier)
 {
     if (empty($openIDIdentifier)) {
         throw new Exception('Empty OpenID Identifier given.', 1381922460);
     }
     // Strip everything with and behind the fragment delimiter character "#"
     if (strpos($openIDIdentifier, '#') !== FALSE) {
         $openIDIdentifier = preg_replace('/#.*$/', '', $openIDIdentifier);
     }
     // A URI with a missing scheme is normalized to a http URI
     if (!preg_match('#^https?://#', $openIDIdentifier)) {
         $escapedIdentifier = $this->databaseConnection->quoteStr($openIDIdentifier, $this->authenticationInformation['db_user']['table']);
         $condition = 'tx_openid_openid IN (' . '\'http://' . $escapedIdentifier . '\',' . '\'http://' . $escapedIdentifier . '/\',' . '\'https://' . $escapedIdentifier . '\',' . '\'https://' . $escapedIdentifier . '/\'' . ')';
         $row = $this->databaseConnection->exec_SELECTgetSingleRow('tx_openid_openid', $this->authenticationInformation['db_user']['table'], $condition);
         if (is_array($row)) {
             $openIDIdentifier = $row['tx_openid_openid'];
         } else {
             // This only happens when the OpenID provider will select the final OpenID identity
             // In this case we require a valid URL as we cannot guess the scheme
             // So we throw an Exception and do not start the OpenID handshake at all
             throw new Exception('Trying to authenticate with OpenID but identifier is neither found in a user record nor it is a valid URL.', 1381922465);
         }
     }
     // An empty path component is normalized to a slash
     // (e.g. "http://domain.org" -> "http://domain.org/")
     if (preg_match('#^https?://[^/]+$#', $openIDIdentifier)) {
         $openIDIdentifier .= '/';
     }
     return $openIDIdentifier;
 }

作者:mbrodal    项目:t3ext-yaml-configuratio   
/**
  * 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;
     }
 }

作者:rabe6    项目:mm_foru   
/**
  * Determines if the current user may write in a certain topic.
  * @param  mixed   $topic The topic identifier. This may either be a topic UID pointing to
  *                        a record in the tx_mmforum_topics table or an associative array
  *                        already containing this record.
  * @return boolean        TRUE, if the user that is currently logged in may write in the
  *                        specified topic, otherwise FALSE.
  * @author Martin Helmich <m.helmich@mittwald.de>
  */
 function getMayWrite_topic($topic)
 {
     $userId = $this->getUserID();
     // If the $topic parameter is not an array, treat this parameter as a topic UID.
     if (!is_array($topic)) {
         $topic = intval($topic);
         // Look in the cache. In case of a hit, just return the result
         $cacheRes = $this->cache->restore('getMayWrite_topic_' . $topic . '_' . $userId);
         if ($cacheRes !== null) {
             return $cacheRes;
         }
         // Load the topic's forum UID
         $res = $this->databaseHandle->exec_SELECTquery('f.*', 'tx_mmforum_forums f, tx_mmforum_topics t', 't.uid="' . $topic . '" AND f.uid = t.forum_id');
         $arr = $this->databaseHandle->sql_fetch_assoc($res);
         $result = $this->getMayWrite_forum($arr);
         // Save the result to cache and return
         $this->cache->save('getMayWrite_topic_' . $topic . '_' . $userId, $result);
         return $result;
     } else {
         /* If the topic's forum UID is already known, just delegate to the
          * getMayWrite_forum function. Since the result of that function is
          * already being cached, there is no need to cache the result at this
          * place again. */
         return $this->getMayWrite_forum($topic['forum_id']);
     }
 }


问题


面经


文章

微信
公众号

扫码关注公众号