[TASK] Migrate LinkType handlers to doctrine 26/48626/4
authorRuud Silvrants <ruudsilvrants@gmail.com>
Tue, 21 Jun 2016 14:57:07 +0000 (16:57 +0200)
committerWouter Wolters <typo3@wouterwolters.nl>
Thu, 7 Jul 2016 17:58:24 +0000 (19:58 +0200)
Resolves: #76557
Releases: master
Change-Id: Id03180b6fb744667bc91066086a1464ea995fd19
Reviewed-on: https://review.typo3.org/48626
Reviewed-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: Bamboo TYPO3com <info@typo3.com>
Reviewed-by: Joerg Boesche <typo3@joergboesche.de>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
typo3/sysext/linkvalidator/Classes/Linktype/AbstractLinktype.php
typo3/sysext/linkvalidator/Classes/Linktype/InternalLinktype.php
typo3/sysext/linkvalidator/Classes/Linktype/LinkHandler.php

index 2dfa068..7cffc6d 100644 (file)
@@ -82,12 +82,4 @@ abstract class AbstractLinktype implements LinktypeInterface
     {
         return $GLOBALS['LANG'];
     }
-
-    /**
-     * @return \TYPO3\CMS\Core\Database\DatabaseConnection
-     */
-    protected function getDatabaseConnection()
-    {
-        return $GLOBALS['TYPO3_DB'];
-    }
 }
index 3494dcf..ad5d8c4 100644 (file)
@@ -15,6 +15,7 @@ namespace TYPO3\CMS\Linkvalidator\Linktype;
  */
 
 use TYPO3\CMS\Backend\Utility\BackendUtility;
+use TYPO3\CMS\Core\Database\ConnectionPool;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
@@ -108,7 +109,15 @@ class InternalLinktype extends AbstractLinktype
      */
     protected function checkPage($page)
     {
-        $row = $this->getDatabaseConnection()->exec_SELECTgetSingleRow('uid, title, deleted, hidden, starttime, endtime', 'pages', 'uid = ' . (int)$page);
+        // Get page ID on which the content element in fact is located
+        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('pages');
+        $queryBuilder->getRestrictions()->removeAll();
+        $row = $queryBuilder
+            ->select('uid', 'title', 'deleted', 'hidden', 'starttime', 'endtime')
+            ->from('pages')
+            ->where($queryBuilder->expr()->eq('uid', (int)$page))
+            ->execute()
+            ->fetch();
         $this->responsePage = true;
         if ($row) {
             if ($row['deleted'] == '1') {
@@ -116,7 +125,10 @@ class InternalLinktype extends AbstractLinktype
                 $this->errorParams['page']['title'] = $row['title'];
                 $this->errorParams['page']['uid'] = $row['uid'];
                 $this->responsePage = false;
-            } elseif ($row['hidden'] == '1' || $GLOBALS['EXEC_TIME'] < (int)$row['starttime'] || $row['endtime'] && (int)$row['endtime'] < $GLOBALS['EXEC_TIME']) {
+            } elseif ($row['hidden'] == '1'
+                || $GLOBALS['EXEC_TIME'] < (int)$row['starttime']
+                || $row['endtime'] && (int)$row['endtime'] < $GLOBALS['EXEC_TIME']
+            ) {
                 $this->errorParams['errorType']['page'] = self::HIDDEN;
                 $this->errorParams['page']['title'] = $row['title'];
                 $this->errorParams['page']['uid'] = $row['uid'];
@@ -140,16 +152,19 @@ class InternalLinktype extends AbstractLinktype
     protected function checkContent($page, $anchor)
     {
         // Get page ID on which the content element in fact is located
-        $res = $this->getDatabaseConnection()->exec_SELECTgetSingleRow(
-            'uid, pid, header, deleted, hidden, starttime, endtime',
-            'tt_content',
-            'uid = ' . (int)$anchor
-        );
+        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('tt_content');
+        $queryBuilder->getRestrictions()->removeAll();
+        $row = $queryBuilder
+            ->select('uid', 'pid', 'header', 'deleted', 'hidden', 'starttime', 'endtime')
+            ->from('tt_content')
+            ->where($queryBuilder->expr()->eq('uid', (int)$anchor))
+            ->execute()
+            ->fetch();
         $this->responseContent = true;
         // this content element exists
-        if ($res) {
+        if ($row) {
             // page ID on which this CE is in fact located.
-            $correctPageID = $res['pid'];
+            $correctPageID = $row['pid'];
             // Check if the element is on the linked page
             // (The element might have been moved to another page)
             if (!($correctPageID === $page)) {
@@ -160,15 +175,15 @@ class InternalLinktype extends AbstractLinktype
                 $this->responseContent = false;
             } else {
                 // The element is located on the page to which the link is pointing
-                if ($res['deleted'] == '1') {
+                if ($row['deleted'] == '1') {
                     $this->errorParams['errorType']['content'] = self::DELETED;
-                    $this->errorParams['content']['title'] = $res['header'];
-                    $this->errorParams['content']['uid'] = $res['uid'];
+                    $this->errorParams['content']['title'] = $row['header'];
+                    $this->errorParams['content']['uid'] = $row['uid'];
                     $this->responseContent = false;
-                } elseif ($res['hidden'] == '1' || $GLOBALS['EXEC_TIME'] < (int)$res['starttime'] || $res['endtime'] && (int)$res['endtime'] < $GLOBALS['EXEC_TIME']) {
+                } elseif ($row['hidden'] == '1' || $GLOBALS['EXEC_TIME'] < (int)$row['starttime'] || $row['endtime'] && (int)$row['endtime'] < $GLOBALS['EXEC_TIME']) {
                     $this->errorParams['errorType']['content'] = self::HIDDEN;
-                    $this->errorParams['content']['title'] = $res['header'];
-                    $this->errorParams['content']['uid'] = $res['uid'];
+                    $this->errorParams['content']['title'] = $row['header'];
+                    $this->errorParams['content']['uid'] = $row['uid'];
                     $this->responseContent = false;
                 }
             }
index 21d5f42..c533170 100644 (file)
@@ -14,7 +14,9 @@ namespace TYPO3\CMS\Linkvalidator\Linktype;
  * The TYPO3 project - inspiring people to share!
  */
 
-use TYPO3\CMS\Backend\Utility\BackendUtility;
+use TYPO3\CMS\Core\Database\ConnectionPool;
+use TYPO3\CMS\Core\Database\Query\Restriction\DeletedRestriction;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Core\Utility\StringUtility;
 
 /**
@@ -61,7 +63,7 @@ class LinkHandler extends AbstractLinktype
         // for hidden records is enabled.
         if ($reportHiddenRecords) {
             $row = $this->getRecordRow($tableName, $rowid, 'disabled');
-            if ($row === null) {
+            if ($row === false) {
                 $response = false;
                 $errorType = self::DISABLED;
             }
@@ -71,7 +73,7 @@ class LinkHandler extends AbstractLinktype
         // if we can find a non deleted record.
         if ($row === null) {
             $row = $this->getRecordRow($tableName, $rowid, 'deleted');
-            if ($row === null) {
+            if ($row === false) {
                 $response = false;
                 $errorType = self::DELETED;
             }
@@ -81,7 +83,7 @@ class LinkHandler extends AbstractLinktype
         // deleted one.
         if ($row === null) {
             $row = $this->getRecordRow($tableName, $rowid, 'all');
-            if ($row === null) {
+            if ($row === false) {
                 $response = false;
                 $errorType = '';
             }
@@ -171,32 +173,31 @@ class LinkHandler extends AbstractLinktype
      * @param string $tableName The name of the table from which the record should be fetched.
      * @param int $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|NULL The result row as associative array or NULL if nothing is found.
+     * @return array|bool The result row as associative array or false if nothing is found.
      */
     protected function getRecordRow($tableName, $uid, $filter = '')
     {
-        $whereStatement = 'uid = ' . (int)$uid;
+        $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($tableName);
 
         switch ($filter) {
             case self::DISABLED:
-                $whereStatement .= BackendUtility::BEenableFields($tableName) . BackendUtility::deleteClause($tableName);
+                // All default restrictions for the QueryBuilder stay active
                 break;
             case self::DELETED:
-                $whereStatement .= BackendUtility::deleteClause($tableName);
+                $queryBuilder->getRestrictions()
+                    ->removeAll()
+                    ->add(GeneralUtility::makeInstance(DeletedRestriction::class));
                 break;
+            default:
+                $queryBuilder->getRestrictions()->removeAll();
         }
 
-        $row = $this->getDatabaseConnection()->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;
-        }
+        $row = $queryBuilder
+            ->select('*')
+            ->from($tableName)
+            ->where($queryBuilder->expr()->eq('uid', (int)$uid))
+            ->execute()
+            ->fetch();
 
         return $row;
     }