Commit b0241e53 authored by Kevin Ditscheid's avatar Kevin Ditscheid

[TASK] Remove legacy TYPO3 DB

parent 496ca4d4
......@@ -29,7 +29,8 @@ namespace SGalinski\SgRoutes\Service;
use TYPO3\CMS\Backend\Utility\BackendUtility;
use TYPO3\CMS\Core\Controller\ErrorPageController;
use TYPO3\CMS\Core\Core\Bootstrap;
use TYPO3\CMS\Core\Database\DatabaseConnection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
use TYPO3\CMS\Core\Error\Http\ServiceUnavailableException;
use TYPO3\CMS\Core\TypoScript\TemplateService;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
......@@ -38,6 +39,7 @@ use TYPO3\CMS\Core\Utility\VersionNumberUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Frontend\Authentication\FrontendUserAuthentication;
use TYPO3\CMS\Frontend\ContentObject\ContentObjectRenderer;
use TYPO3\CMS\Frontend\Controller\ErrorController;
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
use TYPO3\CMS\Frontend\Page\PageGenerator;
use TYPO3\CMS\Frontend\Page\PageRepository;
......@@ -68,7 +70,7 @@ class RoutingService {
* Search Database for redirects and apply them if they exist
*
* @param array $parameters
* @param TypoScriptFrontendController $controller
* @param TypoScriptFrontendController|ErrorController $controller
*
* @return int
* @throws \ReflectionException
......@@ -108,24 +110,37 @@ class RoutingService {
$requestUri = \substr($requestUri, 0, -1);
}
$rootUid = $this->getRootUid($controller);
$rootUid = 0;
if ($controller instanceof TypoScriptFrontendController) {
$rootUid = $this->getRootUid($controller);
} elseif ($GLOBALS['TSFE'] instanceof TypoScriptFrontendController) {
// most probably got an ErrorController
$rootUid = $this->getRootUid($GLOBALS['TSFE']);
}
if ($rootUid) {
if ($GLOBALS['TYPO3_CONF_VARS']['FE']['tx_routes_executed'][$rootUid]) {
return $rootUid;
}
$GLOBALS['TYPO3_CONF_VARS']['FE']['tx_routes_executed'][$rootUid] = TRUE;
/** @var DatabaseConnection $databaseConnection */
$databaseConnection = $GLOBALS['TYPO3_DB'];
$tableName = 'tx_sgroutes_domain_model_route';
$where = 'deleted = 0 AND pid = ' . $rootUid;
$resultArray = $databaseConnection->exec_SELECTgetRows(
'uid, pid, use_regular_expression, source_url, source_url_case_sensitive, ' .
'destination_url, redirect_url_parameters, redirect_code, description',
$tableName, $where, '',
'sorting'
);
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_sgroutes_domain_model_route');
$queryBuilder->getRestrictions()->removeAll()->add(GeneralUtility::makeInstance(DeletedRestriction::class));
$resultArray = $queryBuilder->select(
'uid',
'pid',
'use_regular_expression',
'source_url',
'source_url_case_sensitive',
'destination_url',
'redirect_url_parameters',
'redirect_code',
'description')
->from('tx_sgroutes_domain_model_route')
->where(
$queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($rootUid, \PDO::PARAM_INT))
)
->orderBy('sorting')
->execute()->fetchAll();
if ($resultArray) {
foreach ($resultArray as $redirect) {
if ($redirect['source_url'] === '' || $redirect['destination_url'] === '') {
......@@ -293,11 +308,11 @@ class RoutingService {
* Error handler called by the pageErrorHandler()-method in TypoScriptFrontendController
*
* @param array $parameters
* @param TypoScriptFrontendController $controller
* @param TypoScriptFrontendController|ErrorController $controller
* @return void
* @throws \InvalidArgumentException
*/
public function pageErrorHandler(array $parameters, TypoScriptFrontendController $controller) {
public function pageErrorHandler(array $parameters, $controller) {
try {
$key = 'pageAccessFailureReasons';
$pageAccessFailureReasons = [];
......@@ -320,13 +335,12 @@ class RoutingService {
$rootUid = GeneralUtility::callUserFunction(self::class . '->hook', $_params, $controller);
$configurationFound = FALSE;
if ($rootUid) {
/** @var DatabaseConnection $databaseConnection */
$databaseConnection = $GLOBALS['TYPO3_DB'];
$tableName = 'tx_sgroutes_domain_model_pagenotfoundhandling';
$handling = $databaseConnection->exec_SELECTgetSingleRow(
'function, header', $tableName, 'pid = ' . (int) $rootUid
);
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_sgroutes_domain_model_pagenotfoundhandling');
$handling = $queryBuilder->select('function', 'header')
->from('tx_sgroutes_domain_model_pagenotfoundhandling')
->where(
$queryBuilder->expr()->eq('pid', $queryBuilder->createNamedParameter($rootUid, \PDO::PARAM_INT))
)->execute()->fetch();
if ($handling && $handling['function'] !== '') {
$configurationFound = TRUE;
$function = $handling['function'];
......@@ -345,27 +359,14 @@ class RoutingService {
}
}
// TYPO3 8 specific
$GLOBALS['TYPO3_CONF_VARS']['FE']['pageNotFound_handling'] = $function;
$GLOBALS['TYPO3_CONF_VARS']['FE']['pageNotFound_handling_statheader'] = $handling['header'];
// TYPO3 7 specific
/** @noinspection PhpUndefinedFieldInspection */
$controller->TYPO3_CONF_VARS['FE']['pageNotFound_handling'] = $function;
/** @noinspection PhpUndefinedFieldInspection */
$controller->TYPO3_CONF_VARS['FE']['pageNotFound_handling_statheader'] = $handling['header'];
}
}
if (!$configurationFound) {
// TYPO3 8 specific
$GLOBALS['TYPO3_CONF_VARS']['FE']['pageNotFound_handling'] =
$GLOBALS['TYPO3_CONF_VARS']['FE']['tx_routes_pageNotFound_handling_original'];
// TYPO3 7 specific
/** @noinspection PhpUndefinedFieldInspection */
$controller->TYPO3_CONF_VARS['FE']['pageNotFound_handling'] =
$GLOBALS['TYPO3_CONF_VARS']['FE']['tx_routes_pageNotFound_handling_original'];
}
} catch (\Exception $exception) {
// do nothing as the following code handles it and we can't use "finally" here
......@@ -403,9 +404,16 @@ class RoutingService {
* @throws \InvalidArgumentException
*/
private function logRedirect($routeRow, $requestUri, $redirectUri, $start, $end) {
/** @var DatabaseConnection $databaseConnection */
$databaseConnection = $GLOBALS['TYPO3_DB'];
$tableName = 'tx_sgroutes_domain_model_log';
$queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tx_sgroutes_domain_model_log');
$queryBuilder->getRestrictions()->removeAll();
$categories = $queryBuilder->select('c.title')
->from('tx_sgroutes_domain_model_category', 'c')
->innerJoin('c', 'tx_sgroutes_domain_model_route_category', 'mm', 'c.uid = mm.uid_foreign')
->where(
$queryBuilder->expr()->eq('mm.uid_local', $queryBuilder->createNamedParameter($routeRow['uid'], \PDO::PARAM_INT))
)
->orderBy('mm.sorting')
->execute()->fetchAll();
$insertRow = [
'pid' => $routeRow['pid'],
'use_regular_expression' => $routeRow['use_regular_expression'],
......@@ -415,21 +423,12 @@ class RoutingService {
'redirect_code' => $routeRow['redirect_code'],
'description' => $routeRow['description'],
'categories' => '',
'request_url' => $databaseConnection->quoteStr($requestUri, $tableName),
'redirect_url' => $databaseConnection->quoteStr($redirectUri, $tableName),
'request_url' => $requestUri,
'redirect_url' => $redirectUri,
'execution_duration' => 1000 * ($end - $start),
'crdate' => $GLOBALS['EXEC_TIME'],
];
/** @var array $categories */
$categories = $databaseConnection->exec_SELECTgetRows(
'c.title AS category_title',
'tx_sgroutes_domain_model_category c INNER JOIN tx_sgroutes_domain_model_route_category mm ' .
'ON c.uid = mm.uid_foreign',
'mm.uid_local = ' . $routeRow['uid'], '',
'mm.sorting'
);
if ($categories) {
/** @var array $category */
foreach ($categories as $i => $category) {
......@@ -438,9 +437,11 @@ class RoutingService {
}
$insertRow['categories'] .= $category['category_title'];
}
$insertRow['categories'] = $databaseConnection->quoteStr($insertRow['categories'], $tableName);
}
$databaseConnection->exec_INSERTquery($tableName, $insertRow);
$queryBuilder->resetQueryParts();
$queryBuilder->insert('tx_sgroutes_domain_model_log')
->values($insertRow)
->execute();
}
/**
......
......@@ -11,8 +11,7 @@
"issues": "https://gitlab.sgalinski.de/typo3/sg_routes"
},
"require": {
"typo3/cms-core": "^8.7.0 || ^9.5.1",
"friendsoftypo3/typo3db-legacy": "^1.1.1"
"typo3/cms-core": "^8.7.0 || ^9.5.1"
},
"replace": {
"sg_routes": "self.version"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment