/**
  * 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();
 }
 /**
  * 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;
 }
 /**
  * @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();
 }
 /**
  * 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));
     }
 }
Esempio n. 5
0
 /**
  * @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;
 }
Esempio n. 6
0
 /**
  * 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;
 }
 /**
  * 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;
     }
 }
Esempio n. 8
0
 /**
  * Render single news settings
  *
  * @return void
  */
 protected function getSingleNewsSettings()
 {
     $singleNewsRecord = (int) $this->getFieldFromFlexform('settings.singleNews');
     if ($singleNewsRecord > 0) {
         $newsRecord = $this->databaseConnection->exec_SELECTgetSingleRow('*', 'tx_mooxnews_domain_model_news', 'deleted=0 AND uid=' . $singleNewsRecord);
         if (is_array($newsRecord)) {
             $pageRecord = \TYPO3\CMS\Backend\Utility\BackendUtility::getRecord('pages', $newsRecord['pid']);
             if (is_array($pageRecord)) {
                 $iconPage = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForRecord('pages', $pageRecord, array('title' => 'Uid: ' . $pageRecord['uid']));
                 $iconNews = \TYPO3\CMS\Backend\Utility\IconUtility::getSpriteIconForRecord('tx_mooxnews_domain_model_news', $newsRecord, array('title' => 'Uid: ' . $newsRecord['uid']));
                 $onClickPage = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($iconPage, 'pages', $pageRecord['uid'], 1, '', '+info,edit,view', TRUE);
                 $onClickNews = $GLOBALS['SOBE']->doc->wrapClickMenuOnIcon($iconNews, 'tx_mooxnews_domain_model_news', $newsRecord['uid'], 1, '', '+info,edit', TRUE);
                 $content = '<a href="#" onclick="' . htmlspecialchars($onClickPage) . '">' . $iconPage . '</a>' . htmlspecialchars(\TYPO3\CMS\Backend\Utility\BackendUtility::getRecordTitle('pages', $pageRecord)) . ': ' . '<a href="#" onclick="' . htmlspecialchars($onClickNews) . '">' . $iconNews . htmlspecialchars(\TYPO3\CMS\Backend\Utility\BackendUtility::getRecordTitle('tx_mooxnews_domain_model_news', $newsRecord)) . '</a>';
             } else {
                 /** @var $message \TYPO3\CMS\Core\Messaging\FlashMessage */
                 $text = sprintf($GLOBALS['LANG']->sL(self::LLPATH . 'pagemodule.pageNotAvailable', TRUE), $newsRecord['pid']);
                 $message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $text, '', \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING);
                 $content = $message->render();
             }
         } else {
             /** @var $message \TYPO3\CMS\Core\Messaging\FlashMessage */
             $text = sprintf($GLOBALS['LANG']->sL(self::LLPATH . 'pagemodule.newsNotAvailable', TRUE), $singleNewsRecord);
             $message = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Messaging\\FlashMessage', $text, '', \TYPO3\CMS\Core\Messaging\FlashMessage::WARNING);
             $content = $message->render();
         }
         $this->tableData[] = array($GLOBALS['LANG']->sL(self::LLPATH . 'flexforms_general.singleNews'), $content);
     }
 }
Esempio n. 9
0
 /**
  * Render single news settings
  *
  * @return void
  */
 public function getSingleNewsSettings()
 {
     $singleNewsRecord = (int) $this->getFieldFromFlexform('settings.singleNews');
     if ($singleNewsRecord > 0) {
         $newsRecord = $this->databaseConnection->exec_SELECTgetSingleRow('*', 'tx_news_domain_model_news', 'deleted=0 AND uid=' . $singleNewsRecord);
         if (is_array($newsRecord)) {
             $pageRecord = BackendUtilityCore::getRecord('pages', $newsRecord['pid']);
             if (is_array($pageRecord)) {
                 $iconPage = '<span title="Uid: ' . htmlspecialchars($pageRecord['uid']) . '">' . $this->iconFactory->getIconForRecord('pages', $pageRecord, Icon::SIZE_SMALL)->render() . '</span>';
                 $iconNews = '<span title="Uid: ' . htmlspecialchars($newsRecord['uid']) . '">' . $this->iconFactory->getIconForRecord('tx_news_domain_model_news', $newsRecord, Icon::SIZE_SMALL)->render() . '</span>';
                 $pageTitle = htmlspecialchars(BackendUtilityCore::getRecordTitle('pages', $pageRecord));
                 $newsTitle = BackendUtilityCore::getRecordTitle('tx_news_domain_model_news', $newsRecord);
                 $content = BackendUtilityCore::wrapClickMenuOnIcon($iconPage, 'pages', $pageRecord['uid'], true, '', '+info,edit,view') . $pageTitle . ': ' . BackendUtilityCore::wrapClickMenuOnIcon($iconNews . ' ' . $newsTitle, 'tx_news_domain_model_news', $newsRecord['uid'], true, '', '+info,edit');
             } else {
                 /** @var $message FlashMessage */
                 $text = sprintf($this->getLanguageService()->sL(self::LLPATH . 'pagemodule.pageNotAvailable', true), $newsRecord['pid']);
                 $message = GeneralUtility::makeInstance(FlashMessage::class, $text, '', FlashMessage::WARNING);
                 $content = $message->render();
             }
         } else {
             /** @var $message FlashMessage */
             $text = sprintf($this->getLanguageService()->sL(self::LLPATH . 'pagemodule.newsNotAvailable', true), $singleNewsRecord);
             $message = GeneralUtility::makeInstance(FlashMessage::class, $text, '', FlashMessage::WARNING);
             $content = $message->render();
         }
         $this->tableData[] = [$this->getLanguageService()->sL(self::LLPATH . 'flexforms_general.singleNews'), $content];
     }
 }
 /**
  * Performs the database update.
  *
  * @param array $dbQueries queries done in this update
  * @param mixed $customMessages custom messages
  * @return boolean TRUE on success, FALSE on error
  */
 public function performUpdate(array &$dbQueries, &$customMessages)
 {
     $this->init();
     if (!PATH_site) {
         throw new \Exception('PATH_site was undefined.');
     }
     $fileadminDirectory = rtrim($GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'], '/');
     $targetDirectory = '/_migrated/RTE/';
     $fullTargetDirectory = PATH_site . $fileadminDirectory . $targetDirectory;
     // Create the directory, if necessary
     if (!is_dir($fullTargetDirectory)) {
         \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir_deep($fullTargetDirectory);
     }
     $oldRecords = $this->findMagicImagesInOldLocation();
     foreach ($oldRecords as $refRecord) {
         // Is usually uploads/RTE_magicC_123423324.png.png
         $sourceFileName = $refRecord['ref_string'];
         // Absolute path/filename
         $fullSourceFileName = PATH_site . $refRecord['ref_string'];
         $targetFileName = $targetDirectory . \TYPO3\CMS\Core\Utility\PathUtility::basename($refRecord['ref_string']);
         // Full directory
         $fullTargetFileName = $fullTargetDirectory . \TYPO3\CMS\Core\Utility\PathUtility::basename($refRecord['ref_string']);
         // maybe the file has been moved previously
         if (!file_exists($fullTargetFileName)) {
             // 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.
             if (!file_exists(PATH_site . $sourceFileName)) {
                 $this->logger->notice('File ' . $sourceFileName . ' does not exist. Reference was not migrated.', array());
                 $format = 'File \'%s\' does not exist. Referencing field: %s.%d.%s. The reference was not migrated.';
                 $message = sprintf($format, $sourceFileName, $refRecord['tablename'], $refRecord['recuid'], $refRecord['field']);
                 $customMessages .= PHP_EOL . $message;
                 continue;
             }
             rename($fullSourceFileName, $fullTargetFileName);
         }
         // Get the File object
         $file = $this->storage->getFile($targetFileName);
         if ($file instanceof \TYPO3\CMS\Core\Resource\File) {
             // And now update the referencing field
             $targetFieldName = $refRecord['field'];
             $targetRecord = $this->db->exec_SELECTgetSingleRow('uid, ' . $targetFieldName, $refRecord['tablename'], 'uid=' . (int) $refRecord['recuid']);
             if ($targetRecord) {
                 // Replace the old filename with the new one, and add data-* attributes used by the RTE
                 $searchString = 'src="' . $sourceFileName . '"';
                 $replacementString = 'src="' . $fileadminDirectory . $targetFileName . '"';
                 $replacementString .= ' data-htmlarea-file-uid="' . $file->getUid() . '"';
                 $replacementString .= ' data-htmlarea-file-table="sys_file"';
                 $targetRecord[$targetFieldName] = str_replace($searchString, $replacementString, $targetRecord[$targetFieldName]);
                 // Update the record
                 $this->db->exec_UPDATEquery($refRecord['tablename'], 'uid=' . (int) $refRecord['recuid'], array($targetFieldName => $targetRecord[$targetFieldName]));
                 $queries[] = str_replace(LF, ' ', $this->db->debug_lastBuiltQuery);
                 // Finally, update the sys_refindex table as well
                 $this->db->exec_UPDATEquery('sys_refindex', 'hash=' . $this->db->fullQuoteStr($refRecord['hash'], 'sys_refindex'), array('ref_table' => 'sys_file', 'softref_key' => 'rtehtmlarea_images', 'ref_uid' => $file->getUid(), 'ref_string' => $fileadminDirectory . $targetFileName));
                 $queries[] = str_replace(LF, ' ', $this->db->debug_lastBuiltQuery);
             }
         }
     }
     return TRUE;
 }
 /**
  * @test
  */
 public function addDataThrowsExceptionIfDatabaseFetchingReturnsInvalidRowResultData()
 {
     $input = ['tableName' => 'tt_content', 'command' => 'edit', 'vanillaUid' => 10];
     $this->dbProphecy->quoteStr(Argument::cetera())->willReturn($input['tableName']);
     $this->dbProphecy->exec_SELECTgetSingleRow(Argument::cetera())->willReturn('invalid result data');
     $this->setExpectedException(\UnexpectedValueException::class, '', 1437656323);
     $this->subject->addData($input);
 }
 /**
  * Creates configuration for the installation without domain records.
  *
  * @param array $template
  * @return array
  */
 protected function createConfigurationWithoutDomains(array $template)
 {
     $configuration = array('_DEFAULT' => $template);
     $row = $this->databaseConnection->exec_SELECTgetSingleRow('uid', 'pages', 'deleted=0 AND hidden=0 AND is_siteroot=1');
     if (is_array($row) > 0) {
         $configuration['_DEFAULT']['pagePath']['rootpage_id'] = $row['uid'];
     }
     return $configuration;
 }
 /**
  * @test
  */
 public function addDataSetsParentPageRowOnParentIfCommandIsEdit()
 {
     $input = ['tableName' => 'tt_content', 'command' => 'edit', 'vanillaUid' => 123, 'databaseRow' => ['uid' => 123, 'pid' => 321]];
     $parentPageRow = ['uid' => 321, 'pid' => 456];
     $this->dbProphecy->quoteStr(Argument::cetera())->willReturnArgument(0);
     $this->dbProphecy->exec_SELECTgetSingleRow('*', 'pages', 'uid=321')->willReturn($parentPageRow);
     $result = $this->subject->addData($input);
     $this->assertSame($parentPageRow, $result['parentPageRow']);
 }
 /**
  * @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. 15
0
 /**
  * Performs workspace and language overlay on the given row array. The language and workspace id is automatically
  * detected (depending on FE or BE context). You can also explicitly set the language/workspace id.
  *
  * @param Qom\SourceInterface $source The source (selector od join)
  * @param array $rows
  * @param \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings The TYPO3 CMS specific query settings
  * @param null|int $workspaceUid
  * @return array
  */
 protected function doLanguageAndWorkspaceOverlay(Qom\SourceInterface $source, array $rows, \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings, $workspaceUid = NULL)
 {
     if ($source instanceof Qom\SelectorInterface) {
         $tableName = $source->getSelectorName();
     } elseif ($source instanceof Qom\JoinInterface) {
         $tableName = $source->getRight()->getSelectorName();
     } else {
         // No proper source, so we do not have a table name here
         // we cannot do an overlay and return the original rows instead.
         return $rows;
     }
     $pageRepository = $this->getPageRepository();
     if (is_object($GLOBALS['TSFE'])) {
         if ($workspaceUid !== NULL) {
             $pageRepository->versioningWorkspaceId = $workspaceUid;
         }
     } else {
         if ($workspaceUid === NULL) {
             $workspaceUid = $GLOBALS['BE_USER']->workspace;
         }
         $pageRepository->versioningWorkspaceId = $workspaceUid;
     }
     // Fetches the move-placeholder in case it is supported
     // by the table and if there's only one row in the result set
     // (applying this to all rows does not work, since the sorting
     // order would be destroyed and possible limits not met anymore)
     if (!empty($pageRepository->versioningWorkspaceId) && !empty($GLOBALS['TCA'][$tableName]['ctrl']['versioningWS']) && $GLOBALS['TCA'][$tableName]['ctrl']['versioningWS'] >= 2 && count($rows) === 1) {
         $movePlaceholder = $this->databaseHandle->exec_SELECTgetSingleRow($tableName . '.*', $tableName, 't3ver_state=3 AND t3ver_wsid=' . $pageRepository->versioningWorkspaceId . ' AND t3ver_move_id=' . $rows[0]['uid']);
         if (!empty($movePlaceholder)) {
             $rows = array($movePlaceholder);
         }
     }
     $overlaidRows = array();
     foreach ($rows as $row) {
         // If current row is a translation select its parent
         if (isset($tableName) && isset($GLOBALS['TCA'][$tableName]) && isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField']) && isset($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']) && !isset($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerTable'])) {
             if (isset($row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']]) && $row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']] > 0) {
                 $row = $this->databaseHandle->exec_SELECTgetSingleRow($tableName . '.*', $tableName, $tableName . '.uid=' . (int) $row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']] . ' AND ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . '=0');
             }
         }
         $pageRepository->versionOL($tableName, $row, TRUE);
         if ($tableName == 'pages') {
             $row = $pageRepository->getPageOverlay($row, $querySettings->getLanguageUid());
         } elseif (isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField']) && $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] !== '' && !isset($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerTable'])) {
             if (in_array($row[$GLOBALS['TCA'][$tableName]['ctrl']['languageField']], array(-1, 0))) {
                 $overlayMode = $querySettings->getLanguageMode() === 'strict' ? 'hideNonTranslated' : '';
                 $row = $pageRepository->getRecordOverlay($tableName, $row, $querySettings->getLanguageUid(), $overlayMode);
             }
         }
         if ($row !== NULL && is_array($row)) {
             $overlaidRows[] = $row;
         }
     }
     return $overlaidRows;
 }
 /**
  * @test
  */
 public function addDataSetsTypeValueFromNestedTcaGroupField()
 {
     $input = ['processedTca' => ['ctrl' => ['type' => 'uid_local:type'], 'columns' => ['uid_local' => ['config' => ['type' => 'group', 'internal_type' => 'db', 'size' => 1, 'maxitems' => 1, 'minitems' => 0, 'allowed' => 'sys_file']]], 'types' => ['2' => 'foo']], 'databaseRow' => ['uid_local' => 'sys_file_222|my_test.jpg']];
     $foreignRecordResult = ['type' => 2];
     // Required for BackendUtility::getRecord
     $GLOBALS['TCA']['sys_file'] = array('foo');
     $this->dbProphecy->exec_SELECTgetSingleRow('type', 'sys_file', 'uid=222')->shouldBeCalled()->willReturn($foreignRecordResult);
     $expected = $input;
     $expected['recordTypeValue'] = '2';
     $this->assertSame($expected, $this->subject->addData($input));
 }
Esempio n. 17
0
 /**
  * Collects tt_content data from a single tt_content element
  *
  * @param string $shortcutItem : The tt_content element to fetch the data from
  * @param array $collectedItems : The collected item data row
  * @param string $showHidden : query String containing enable fields
  * @param string $deleteClause : query String to check for deleted items
  * @param int $parentUid : uid of the referencing tt_content record
  *
  * @return void
  */
 public function collectContentData($shortcutItem, &$collectedItems, &$showHidden, &$deleteClause, $parentUid)
 {
     $shortcutItem = str_replace('tt_content_', '', $shortcutItem);
     if ((int) $shortcutItem !== (int) $parentUid) {
         $itemRow = $this->databaseConnection->exec_SELECTgetSingleRow('*', 'tt_content', 'uid=' . $shortcutItem . $showHidden . $deleteClause);
         if ($this->helper->getBackendUser()->workspace > 0) {
             BackendUtility::workspaceOL('tt_content', $itemRow, $this->helper->getBackendUser()->workspace);
         }
         $collectedItems[] = $itemRow;
     }
 }
Esempio n. 18
0
 /**
  * Get the news object from the given id
  *
  * @param integer $id
  * @return mixed|null
  */
 protected function getObject($id)
 {
     $record = NULL;
     $rawRecord = $this->databaseConnection->exec_SELECTgetSingleRow('*', 'tx_news_domain_model_news', 'uid=' . (int) $id);
     if (is_array($rawRecord)) {
         $className = 'GeorgRinger\\News\\Domain\\Model\\News';
         $records = $this->dataMapper->map($className, array($rawRecord));
         $record = array_shift($records);
     }
     return $record;
 }
Esempio n. 19
0
 /**
  * Initializes the Storage
  *
  * @return void
  */
 protected function initializeLocalCache()
 {
     if (static::$storageRowCache === null) {
         static::$storageRowCache = $this->db->exec_SELECTgetRows('*', $this->table, '1=1' . $this->getWhereClauseForEnabledFields(), '', 'name', '', 'uid');
         // if no storage is created before or the user has not access to a storage
         // static::$storageRowCache would have the value array()
         // so check if there is any record. If no record is found, create the fileadmin/ storage
         // selecting just one row is enoung
         if (static::$storageRowCache === array()) {
             $storageObjectsExists = $this->db->exec_SELECTgetSingleRow('uid', $this->table, '');
             if ($storageObjectsExists !== null) {
                 if ($this->createLocalStorage('fileadmin/ (auto-created)', $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'], 'relative', 'This is the local fileadmin/ directory. This storage mount has been created automatically by TYPO3.', true) > 0) {
                     // reset to null to force reloading of storages
                     static::$storageRowCache = null;
                     // call self for initialize Cache
                     $this->initializeLocalCache();
                 }
             }
         }
     }
 }
 /**
  * Get form uid of a localized form
  *
  * @param int $uid
  * @param int $sysLanguageUid
  * @return int
  */
 protected function getLocalizedFormUid($uid, $sysLanguageUid)
 {
     if ($sysLanguageUid > 0) {
         $select = 'uid';
         $from = 'tx_powermail_domain_model_forms';
         $where = 'sys_language_uid=' . (int) $sysLanguageUid . ' and l10n_parent=' . (int) $uid;
         $row = $this->databaseConnection->exec_SELECTgetSingleRow($select, $from, $where);
         if (!empty($row['uid'])) {
             $uid = (int) $row['uid'];
         }
     }
     return $uid;
 }
 /**
  * @test
  */
 public function addDataResolvesLanguageIsocodeFromStaticInfoTable()
 {
     if (ExtensionManagementUtility::isLoaded('static_info_tables') === false) {
         $this->markTestSkipped('no ext:static_info_tables available');
     }
     $dbRows = [['uid' => 3, 'title' => 'french', 'language_isocode' => '', 'static_lang_isocode' => 42, 'flag' => 'fr']];
     $this->dbProphecy->exec_SELECTgetRows('uid,title,language_isocode,static_lang_isocode,flag', 'sys_language', 'pid=0')->shouldBeCalled()->willReturn($dbRows);
     // Needed for backendUtility::getRecord()
     $GLOBALS['TCA']['static_languages'] = ['foo'];
     $this->dbProphecy->exec_SELECTgetSingleRow('lg_iso_2', 'static_languages', 'uid=42')->shouldBeCalled()->willReturn(['lg_iso_2' => 'FR']);
     $expected = ['systemLanguageRows' => [-1 => ['uid' => -1, 'title' => 'LLL:EXT:lang/locallang_mod_web_list.xlf:multipleLanguages', 'iso' => 'DEF', 'flagIconIdentifier' => 'flags-multiple'], 0 => ['uid' => 0, 'title' => 'LLL:EXT:lang/locallang_mod_web_list.xlf:defaultLanguage', 'iso' => 'DEF', 'flagIconIdentifier' => 'empty-empty'], 3 => ['uid' => 3, 'title' => 'french', 'flagIconIdentifier' => 'flags-fr', 'iso' => 'FR']]];
     $this->assertSame($expected, $this->subject->addData([]));
 }
 /**
  * Add registrant record (if new) and return corresponding uid
  *
  * @param         $data
  * @param integer $uid
  *
  * @return integer
  */
 private function addRegistrant($data, $uid = 1)
 {
     if ((int) $data['registrant'] > 0 && $this->databaseConnection->exec_SELECTcountRows('*', 'fe_users', 'uid=' . (int) $data['registrant'])) {
         $registrant = $this->databaseConnection->exec_SELECTgetSingleRow('*', 'fe_users', 'uid=' . (int) $data['registrant']);
     } else {
         $registrant = ['name' => $data['registrant_name'], 'company' => $data['registrant_company'], 'email' => $data['registrant_email'], 'telephone' => $data['registrant_phone']];
     }
     $checkForExistingRecord = $this->databaseConnection->exec_SELECTgetSingleRow('*', 'tx_projectregistration_domain_model_person', 'name="' . $registrant['name'] . '" AND email="' . $registrant['email'] . '" AND company="' . $registrant['company'] . '" AND phone="' . $registrant['telephone'] . '"');
     if ($checkForExistingRecord) {
         return (int) $checkForExistingRecord['uid'];
     } else {
         $this->databaseConnection->exec_INSERTquery('tx_projectregistration_domain_model_person', ['username' => $registrant['username'] ?: '', 'name' => $registrant['name'] ?: '', 'first_name' => $registrant['first_name'] ?: '', 'middle_name' => $registrant['middle_name'] ?: '', 'last_name' => $registrant['last_name'] ?: '', 'company' => $registrant['company'] ?: '', 'address' => $registrant['address'] ?: '', 'zip' => $registrant['zip'] ?: '', 'city' => $registrant['city'] ?: '', 'country' => abs((int) $registrant['ecom_toolbox_country']), 'state' => abs((int) $registrant['ecom_toolbox_state']), 'email' => $registrant['email'] ?: '', 'phone' => $registrant['telephone'] ?: '', 'fax' => $registrant['fax'] ?: '', 'title' => $registrant['title'] ?: '', 'www' => $registrant['www'] ?: '', 'fe_user' => abs((int) $data['registrant'])]);
         return $uid;
     }
 }
Esempio n. 23
0
 /**
  * Performs workspace and language overlay on the given row array. The language and workspace id is automatically
  * detected (depending on FE or BE context). You can also explicitly set the language/workspace id.
  *
  * @param \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface $source The source (selector od join)
  * @param array $rows
  * @param \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings The TYPO3 CMS specific query settings
  * @param null|integer $workspaceUid
  * @return array
  */
 protected function doLanguageAndWorkspaceOverlay(\TYPO3\CMS\Extbase\Persistence\Generic\Qom\SourceInterface $source, array $rows, \TYPO3\CMS\Extbase\Persistence\Generic\QuerySettingsInterface $querySettings, $workspaceUid = NULL)
 {
     if ($source instanceof \TYPO3\CMS\Extbase\Persistence\Generic\Qom\SelectorInterface) {
         $tableName = $source->getSelectorName();
     } elseif ($source instanceof \TYPO3\CMS\Extbase\Persistence\Generic\Qom\JoinInterface) {
         $tableName = $source->getRight()->getSelectorName();
     } else {
         // No proper source, so we do not have a table name here
         // we cannot do an overlay and return the original rows instead.
         return $rows;
     }
     $pageRepository = $this->getPageRepository();
     if (is_object($GLOBALS['TSFE'])) {
         if ($workspaceUid !== NULL) {
             $pageRepository->versioningWorkspaceId = $workspaceUid;
         }
     } else {
         if ($workspaceUid === NULL) {
             $workspaceUid = $GLOBALS['BE_USER']->workspace;
         }
         $pageRepository->versioningWorkspaceId = $workspaceUid;
     }
     $overlaidRows = array();
     foreach ($rows as $row) {
         // If current row is a translation select its parent
         if (isset($tableName) && isset($GLOBALS['TCA'][$tableName]) && isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField']) && isset($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']) && !isset($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerTable'])) {
             if (isset($row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']]) && $row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']] > 0) {
                 $row = $this->databaseHandle->exec_SELECTgetSingleRow($tableName . '.*', $tableName, $tableName . '.uid=' . (int) $row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']] . ' AND ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . '=0');
             }
         }
         $pageRepository->versionOL($tableName, $row, TRUE);
         if ($pageRepository->versioningPreview && isset($row['_ORIG_uid'])) {
             $row['uid'] = $row['_ORIG_uid'];
         }
         if ($tableName == 'pages') {
             $row = $pageRepository->getPageOverlay($row, $querySettings->getLanguageUid());
         } elseif (isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField']) && $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] !== '' && !isset($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerTable'])) {
             if (in_array($row[$GLOBALS['TCA'][$tableName]['ctrl']['languageField']], array(-1, 0))) {
                 $overlayMode = $querySettings->getLanguageMode() === 'strict' ? 'hideNonTranslated' : '';
                 $row = $pageRepository->getRecordOverlay($tableName, $row, $querySettings->getLanguageUid(), $overlayMode);
             }
         }
         if ($row !== NULL && is_array($row)) {
             $overlaidRows[] = $row;
         }
     }
     return $overlaidRows;
 }
 /**
  * @test
  * @return void
  */
 public function canLoadADummyCollectionFromDatabase()
 {
     /** @var $collection \TYPO3\CMS\Core\Category\Collection\CategoryCollection */
     $collection = \TYPO3\CMS\Core\Category\Collection\CategoryCollection::load($this->categoryUid, true, $this->tableName);
     // Check the number of record
     $this->assertEquals($this->numberOfRecords, $collection->count());
     // Check that the first record is the one expected
     $record = $this->database->exec_SELECTgetSingleRow('*', $this->tableName, 'uid=1');
     $collection->rewind();
     $this->assertEquals($record, $collection->current());
     // Add a new record
     $fakeRecord = array('uid' => $this->numberOfRecords + 1, 'pid' => 0, 'title' => $this->getUniqueId('title'), 'categories' => 0);
     // Check the number of records
     $collection->add($fakeRecord);
     $this->assertEquals($this->numberOfRecords + 1, $collection->count());
 }
 /**
  * Creates a frontend user based on the data of the social user
  *
  * @param array $user
  * @param string $provider
  * @param string $identifier
  *
  * @return array|FALSE the created identity record or false if it is not possible
  */
 protected function addIdentityToFrontendUser($user, $provider, $identifier)
 {
     $result = false;
     $identityClassName = 'Portrino\\PxHybridAuth\\Domain\\Model\\Identity\\' . $provider . 'Identity';
     if (class_exists($identityClassName) && defined($identityClassName . '::EXTBASE_TYPE')) {
         $extbaseType = constant($identityClassName . '::EXTBASE_TYPE');
         $this->database->exec_INSERTquery('tx_pxhybridauth_domain_model_identity', ['pid' => $user['pid'], 'tx_extbase_type' => $extbaseType, 'identifier' => $identifier, 'fe_user' => $user['uid'], 'hidden' => 0, 'deleted' => 0, 'tstamp' => time(), 'crdate' => time()]);
         $id = $this->database->sql_insert_id();
         $where = 'uid=' . intval($id);
         $result = $this->database->exec_SELECTgetSingleRow('*', 'tx_pxhybridauth_domain_model_identity', $where);
         if ($result) {
             $this->database->exec_UPDATEquery('fe_users', 'uid=' . intval($user['uid']), ['tx_pxhybridauth_identities' => 1]);
         }
     }
     return $result;
 }
Esempio n. 26
0
 /**
  * Get the news object from the given id
  *
  * @param int $id
  * @return mixed|null
  */
 protected function getObject($id)
 {
     $record = null;
     $rawRecord = $this->databaseConnection->exec_SELECTgetSingleRow('*', 'tx_news_domain_model_news', 'uid=' . (int) $id);
     if (is_object($GLOBALS['TSFE']) && $GLOBALS['TSFE']->sys_language_content > 0) {
         $overlay = $GLOBALS['TSFE']->sys_page->getRecordOverlay('tx_news_domain_model_news', $rawRecord, $GLOBALS['TSFE']->sys_language_content, $GLOBALS['TSFE']->sys_language_contentOL);
         if (!is_null($overlay)) {
             $rawRecord = $overlay;
         }
     }
     if (is_array($rawRecord)) {
         $className = 'GeorgRinger\\News\\Domain\\Model\\News';
         $records = $this->dataMapper->map($className, [$rawRecord]);
         $record = array_shift($records);
     }
     return $record;
 }
Esempio n. 27
0
 /**
  * Obtains path from the path cache.
  *
  * @param int $rootPageId
  * @param string $mountPoint
  * @param string $pagePath
  * @return PathCacheEntry|null
  */
 public function getPathFromCacheByPagePath($rootPageId, $mountPoint, $pagePath)
 {
     $cacheEntry = NULL;
     $row = $this->databaseConnection->exec_SELECTgetSingleRow('*', 'tx_realurl_pathcache', 'rootpage_id=' . (int) $rootPageId . ' AND pagepath=' . $this->databaseConnection->fullQuoteStr($pagePath, 'tx_realurl_pathcache'), '', 'expire');
     if (is_array($row)) {
         $cacheEntry = GeneralUtility::makeInstance('DmitryDulepov\\Realurl\\Cache\\PathCacheEntry');
         /** @var \DmitryDulepov\Realurl\Cache\PathCacheEntry $cacheEntry */
         $cacheEntry->setCacheId((int) $row['cache_id']);
         $cacheEntry->setExpiration((int) $row['expire']);
         $cacheEntry->setLanguageId((int) $row['language_id']);
         $cacheEntry->setMountPoint($row['mpvar']);
         $cacheEntry->setPageId((int) $row['page_id']);
         $cacheEntry->setPagePath($row['pagepath']);
         $cacheEntry->setRootPageId((int) $row['rootpage_id']);
     }
     return $cacheEntry;
 }
 /**
  * Fetches the record with the given UID from the given table.
  *
  * The filter option accepts two values:
  *
  * "disabled" will filter out disabled and deleted records.
  * "deleted" filters out deleted records but will return disabled records.
  * If nothing is specified all records will be returned (including deleted).
  *
  * @param string $tableName The name of the table from which the record should be fetched.
  * @param string $uid The UID of the record that should be fetched.
  * @param string $filter A filter setting, can be empty or "disabled" or "deleted".
  * @return array The result row as associative array.
  */
 protected function getRecordRow($tableName, $uid, $filter = '')
 {
     $whereStatement = 'uid = ' . (int) $uid;
     switch ($filter) {
         case 'disabled':
             $whereStatement .= BackendUtility::BEenableFields($tableName) . BackendUtility::deleteClause($tableName);
             break;
         case 'deleted':
             $whereStatement .= BackendUtility::deleteClause($tableName);
             break;
     }
     $row = $this->databaseConnection->exec_SELECTgetSingleRow('*', $tableName, $whereStatement);
     // Since exec_SELECTgetSingleRow can return NULL or FALSE we
     // make sure we always return NULL if no row was found.
     if ($row === FALSE) {
         $row = NULL;
     }
     return $row;
 }
Esempio n. 29
0
 /**
  * Performs workspace and language overlay on the given row array. The language and workspace id is automatically
  * detected (depending on FE or BE context). You can also explicitly set the language/workspace id.
  *
  * @param SourceInterface $source The source (selector od join)
  * @param array $row
  * @param QuerySettingsInterface $querySettings The TYPO3 CMS specific query settings
  * @return array
  */
 protected function doLanguageAndWorkspaceOverlay(SourceInterface $source, array $row, $querySettings)
 {
     /** @var SelectorInterface $source */
     $tableName = $source->getSelectorName();
     $pageRepository = $this->getPageRepository();
     if (is_object($GLOBALS['TSFE'])) {
         $languageMode = $GLOBALS['TSFE']->sys_language_mode;
         if ($this->isBackendUserLogged() && $this->getBackendUser()->workspace !== 0) {
             $pageRepository->versioningWorkspaceId = $this->getBackendUser()->workspace;
         }
     } else {
         $languageMode = '';
         $workspaceUid = $this->getBackendUser()->workspace;
         $pageRepository->versioningWorkspaceId = $workspaceUid;
         if ($this->getBackendUser()->workspace !== 0) {
             $pageRepository->versioningPreview = 1;
         }
     }
     // If current row is a translation select its parent
     if (isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField']) && isset($GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField'])) {
         if (isset($row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']]) && $row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']] > 0) {
             $row = $this->databaseHandle->exec_SELECTgetSingleRow($tableName . '.*', $tableName, $tableName . '.uid=' . (int) $row[$GLOBALS['TCA'][$tableName]['ctrl']['transOrigPointerField']] . ' AND ' . $tableName . '.' . $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] . '=0');
         }
     }
     // Retrieve the original uid
     // @todo It looks for me this code will never be used! "_ORIG_uid" is something from extbase. Adjust me or remove me in 0.4 + 2 version!
     $pageRepository->versionOL($tableName, $row, TRUE);
     if ($pageRepository->versioningPreview && isset($row['_ORIG_uid'])) {
         $row['uid'] = $row['_ORIG_uid'];
     }
     // Special case for table "pages"
     if ($tableName == 'pages') {
         $row = $pageRepository->getPageOverlay($row, $querySettings->getLanguageUid());
     } elseif (isset($GLOBALS['TCA'][$tableName]['ctrl']['languageField']) && $GLOBALS['TCA'][$tableName]['ctrl']['languageField'] !== '') {
         if (in_array($row[$GLOBALS['TCA'][$tableName]['ctrl']['languageField']], array(-1, 0))) {
             $overlayMode = $languageMode === 'strict' ? 'hideNonTranslated' : '';
             $row = $pageRepository->getRecordOverlay($tableName, $row, $querySettings->getLanguageUid(), $overlayMode);
         }
     }
     return $row;
 }
 /**
  * @test
  */
 public function addDataSetsDoesNotAddHandledRowAsAdditionalLanguageRows()
 {
     $input = ['tableName' => 'tt_content', 'databaseRow' => ['uid' => 42, 'text' => 'localized text', 'sys_language_uid' => 2, 'l10n_parent' => 23], 'processedTca' => ['ctrl' => ['languageField' => 'sys_language_uid', 'transOrigPointerField' => 'l10n_parent']], 'userTsConfig' => ['options.' => ['additionalPreviewLanguages' => '2,3']], 'systemLanguageRows' => [0 => ['uid' => 0, 'title' => 'Default Language', 'iso' => 'DEV'], 2 => ['uid' => 2, 'title' => 'dansk', 'iso' => 'dk,'], 3 => ['uid' => 3, 'title' => 'french', 'iso' => 'fr']], 'defaultLanguageRow' => null, 'additionalLanguageRows' => []];
     $translationResult = ['translations' => [3 => ['uid' => 43]]];
     // For BackendUtility::getRecord()
     $GLOBALS['TCA']['tt_content'] = array('foo');
     $recordWsolResult = ['uid' => 43, 'text' => 'localized text in french'];
     $defaultLanguageRow = ['uid' => 23, 'text' => 'default language text', 'sys_language_uid' => 0];
     // Needed for BackendUtility::getRecord
     $GLOBALS['TCA']['tt_content'] = array('foo');
     $this->dbProphecy->exec_SELECTgetSingleRow('*', 'tt_content', 'uid=23')->shouldBeCalled()->willReturn($defaultLanguageRow);
     /** @var TranslationConfigurationProvider|ObjectProphecy $translationProphecy */
     $translationProphecy = $this->prophesize(TranslationConfigurationProvider::class);
     GeneralUtility::addInstance(TranslationConfigurationProvider::class, $translationProphecy->reveal());
     $translationProphecy->translationInfo('tt_content', 23, 3)->shouldBeCalled()->willReturn($translationResult);
     $translationProphecy->translationInfo('tt_content', 23, 2)->shouldNotBeCalled();
     // This is the real check: The "additional overlay" should be fetched
     $this->dbProphecy->exec_SELECTgetSingleRow('*', 'tt_content', 'uid=43')->shouldBeCalled()->willReturn($recordWsolResult);
     $expected = $input;
     $expected['defaultLanguageRow'] = $defaultLanguageRow;
     $expected['additionalLanguageRows'] = [3 => ['uid' => 43, 'text' => 'localized text in french']];
     $this->assertEquals($expected, $this->subject->addData($input));
 }