[FEATURE] Use TYPO3 8 DB API 65/51165/3
authorStanislas Rolland <typo3@sjbr.ca>
Fri, 6 Jan 2017 17:54:59 +0000 (12:54 -0500)
committerStanislas Rolland <typo3@sjbr.ca>
Fri, 6 Jan 2017 18:01:03 +0000 (19:01 +0100)
Resolves: #79187
Change-Id: Ib0c1907b81a1cbcc163ba362f368df51ea8ba6d0
Reviewed-on: https://review.typo3.org/51165
Reviewed-by: Stanislas Rolland <typo3@sjbr.ca>
Tested-by: Stanislas Rolland <typo3@sjbr.ca>
ChangeLog
class.ext_update.php

index f9ccac0..88376e7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2017-01-06  Stanislas Rolland  <typo3(arobas)sjbr.ca>\r
+\r
+       * Resolves #79187: Use TYPO3 8 DB API\r
+\r
 2017-01-05  Stanislas Rolland  <typo3(arobas)sjbr.ca>\r
 \r
        * Resolves #79176: Missing renderType on TCA select definition\r
index fadf1e2..7ddea7a 100644 (file)
@@ -1,42 +1,49 @@
 <?php
-use \TYPO3\CMS\Core\Utility\GeneralUtility;
-use \TYPO3\CMS\Extbase\Utility\LocalizationUtility;
+namespace SJBR\SrLanguageMenu;
+
 /***************************************************************
-*  Copyright notice
-*
-*  (c) 2013 Stanislas Rolland <typo3@sjbr.ca>
-*  All rights reserved
-*
-*  This script is part of the Typo3 project. The Typo3 project is
-*  free software; you can redistribute it and/or modify
-*  it under the terms of the GNU General Public License as published by
-*  the Free Software Foundation; either version 2 of the License, or
-*  (at your option) any later version.
-*
-*  The GNU General Public License can be found at
-*  http://www.gnu.org/copyleft/gpl.html.
-*
-*  This script is distributed in the hope that it will be useful,
-*  but WITHOUT ANY WARRANTY; without even the implied warranty of
-*  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-*  GNU General Public License for more details.
-*
-*  This copyright notice MUST APPEAR in all copies of the script!
-***************************************************************/
+ *  Copyright notice
+ *
+ *  (c) 2013-2017 Stanislas Rolland <typo3@sjbr.ca>
+ *  All rights reserved
+ *
+ *  This script is part of the Typo3 project. The Typo3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+use TYPO3\CMS\Core\Database\ConnectionPool;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\VersionNumberUtility;
+use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
+
 /**
 * Class for updating the language menu flexform
 */
-class ext_update {
-        
+class ext_update
+{
        /**
         * Main function, returning the HTML content of the module
         *
         * @return string  HTML
         */
-       public function main() {
+       public function main()
+       {
                $content = array();
                $content[] = '<h3>' . LocalizationUtility::translate('update.upgradeTo6', 'SrLanguageMenu') . '</h3>';
-               if (GeneralUtility::_GP('proceed')) {   
+               if (GeneralUtility::_GP('proceed')) {
                        $content[] = $this->updatePluginInstances();
                        $content[] = $this->updateTsTemplates();
                        $content[] = '<p>' . LocalizationUtility::translate('update.pleaseRead', 'SrLanguageMenu') . '</p>';
@@ -55,13 +62,26 @@ class ext_update {
         *
         * @return string  HTML
         */
-       protected function updatePluginInstances() {
-
-               $pluginInstances = $this->getDatabaseConnection()->exec_SELECTgetRows(
-                       '*',
-                       'tt_content',
-                       'CType = ' . $this->getDatabaseConnection()->fullQuoteStr('sr_language_menu_pi1', 'tt_content')
-               );
+       protected function updatePluginInstances()
+       {
+               if (class_exists(\TYPO3\CMS\Core\Database\ConnectionPool::class)) {
+                       $queryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)->getQueryBuilderForTable('tt_content');
+                       $queryBuilder->getRestrictions()->removeAll();
+                       $pluginInstances = $queryBuilder
+                               ->select('*')
+                               ->from('tt_content')
+                               ->where(
+                                       $queryBuilder->expr()->eq('CType', $queryBuilder->createNamedParameter('sr_language_menu_pi1'))
+                               )
+                               ->execute()
+                               ->fetchAll();
+               } else {
+                       $pluginInstances = $this->getDatabaseConnection()->exec_SELECTgetRows(
+                               '*',
+                               'tt_content',
+                               'CType = ' . $this->getDatabaseConnection()->fullQuoteStr('sr_language_menu_pi1', 'tt_content')
+                       );
+               }
 
                foreach ($pluginInstances as $row) {
                        $update = array(
@@ -102,9 +122,20 @@ class ext_update {
     </data>
 </T3FlexForms>'
                        );
-                       $this->getDatabaseConnection()->exec_UPDATEquery('tt_content', 'uid=' . intval($row['uid']), $update);
+                       if (class_exists(\TYPO3\CMS\Core\Database\ConnectionPool::class)) {
+                               $queryBuilder
+                                  ->update('tt_content')
+                                  ->where(
+                                         $queryBuilder->expr()->eq('uid', (int)$row['uid'])
+                                  )
+                                  ->set('CType', $update['CType'])
+                                  ->set('list_type', $update['list_type'])
+                                  ->set('pi_flexform', $update['pi_flexform'])
+                                  ->execute();
+                       } else {
+                               $this->getDatabaseConnection()->exec_UPDATEquery('tt_content', 'uid=' . (int)$row['uid'], $update);
+                       }
                }
-
                $message = LocalizationUtility::translate('update.elementsUpdated', 'SrLanguageMenu', array(count($pluginInstances)));
                return '<p>' . $message . '</p>';
        }
@@ -114,21 +145,42 @@ class ext_update {
         *
         * @return string  HTML
         */
-       protected function updateTsTemplates() {
-
-               $tsTemplates = $this->getDatabaseConnection()->exec_SELECTgetRows(
-                       '*',
-                       'sys_template',
-                       '1=1'
-               );
+       protected function updateTsTemplates()
+       {
+               if (class_exists(\TYPO3\CMS\Core\Database\ConnectionPool::class)) {
+                       $queryBuilder = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class)->getQueryBuilderForTable('sys_template');
+                       $queryBuilder->getRestrictions()->removeAll();
+                       $tsTemplates = $queryBuilder
+                               ->select('*')
+                               ->from('sys_template')
+                               ->execute()
+                               ->fetchAll();
+               } else {
+                       $tsTemplates = $this->getDatabaseConnection()->exec_SELECTgetRows(
+                               '*',
+                               'sys_template',
+                               '1=1'
+                       );
+               }
                $count = 0;
                foreach ($tsTemplates as $row) {
-                       if (strstr($row['constants'], 'tx_srlanguagemenu_pi1') !== FALSE || strstr($row['config'], 'tx_srlanguagemenu_pi1') !== FALSE) {
+                       if (strstr($row['constants'], 'tx_srlanguagemenu_pi1') !== false || strstr($row['config'], 'tx_srlanguagemenu_pi1') !== false) {
                                $update = array();
                                $update['constants'] = str_replace('tx_srlanguagemenu_pi1', 'tx_srlanguagemenu', $row['constants']);
                                $update['config'] = str_replace('$plugin.tx_srlanguagemenu_pi1', '$plugin.tx_srlanguagemenu', $row['config']);
                                $update['config'] = str_replace('plugin.tx_srlanguagemenu_pi1', 'plugin.tx_srlanguagemenu.settings', $update['config']);
-                               $this->getDatabaseConnection()->exec_UPDATEquery('sys_template', 'uid=' . intval($row['uid']), $update);
+                               if (class_exists(\TYPO3\CMS\Core\Database\ConnectionPool::class)) {
+                                       $queryBuilder
+                                          ->update('sys_template')
+                                          ->where(
+                                                 $queryBuilder->expr()->eq('uid', (int)$row['uid'])
+                                          )
+                                          ->set('constants', $update['constants'])
+                                          ->set('config', $update['config'])
+                                          ->execute();
+                               } else {
+                                       $this->getDatabaseConnection()->exec_UPDATEquery('sys_template', 'uid=' . (int)$row['uid'], $update);
+                               }
                                $count++;
                        }
                }
@@ -136,8 +188,9 @@ class ext_update {
                return '<p>' . $message . '</p>';
        }
 
-       public function access() {
-               return TRUE;
+       public function access()
+       {
+               return true;
        }
 
        /**
@@ -145,8 +198,8 @@ class ext_update {
         *
         * @return \TYPO3\CMS\Core\Database\DatabaseConnection
         */
-       protected function getDatabaseConnection() {
+       protected function getDatabaseConnection()
+       {
                return $GLOBALS['TYPO3_DB'];
        }
-}
-?>
+}
\ No newline at end of file