[BUGFIX] Deprecate broken buildQueryParameters hook 12/55512/7
authorFrank Naegler <frank.naegler@typo3.org>
Wed, 31 Jan 2018 15:09:33 +0000 (16:09 +0100)
committerSusanne Moog <susanne.moog@typo3.org>
Thu, 8 Feb 2018 08:37:39 +0000 (09:37 +0100)
This change deprecates the "buildQueryParameters" hook in three
different classes and adds two new hooks in DatabaseRecordList
and PageLayoutView to modify the current query.

With #82334 a cleanup of AbstractRecordList has introduced
the same hook into multiple classes, which breaks existing
hooks, because of the sixth parameter which can be one of three
different classes without a common parent class or interface.
This makes it impossible to use a type hint in the hook class.

Another problem is: an extension which implements the hook
for the list module and uses a type hint will break the page module.

The same query manipulation can be achieved with the two
new hooks, which have a separate identifier.

Resolves: #83740
Related: #82334
Releases: master
Change-Id: Ie3b2c8082f86c6632400a8194dca4ca244b428bc
Reviewed-on: https://review.typo3.org/55512
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Joerg Boesche <typo3@joergboesche.de>
Reviewed-by: Mathias Schreiber <mathias.schreiber@typo3.com>
Tested-by: Mathias Schreiber <mathias.schreiber@typo3.com>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Reviewed-by: Alexander Opitz <opitz.alexander@googlemail.com>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
typo3/sysext/backend/Classes/View/PageLayoutView.php
typo3/sysext/core/Documentation/Changelog/master/Deprecation-83740-CleanupOfAbstractRecordListBreaksHook.rst [new file with mode: 0644]
typo3/sysext/core/Documentation/Changelog/master/Feature-83740-CleanupOfAbstractRecordListBreaksHook.rst [new file with mode: 0644]
typo3/sysext/install/Configuration/ExtensionScanner/Php/ArrayDimensionMatcher.php
typo3/sysext/recordlist/Classes/RecordList/AbstractDatabaseRecordList.php
typo3/sysext/recordlist/Classes/RecordList/DatabaseRecordList.php

index 99d9730..cce2ddc 100644 (file)
@@ -3407,6 +3407,8 @@ class PageLayoutView implements LoggerAwareInterface
 
         $hookName = DatabaseRecordList::class;
         foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][$hookName]['buildQueryParameters'] ?? [] as $className) {
+            // @deprecated since TYPO3 v9, will be removed in TYPO3 v10, the modifyQuery hook should be used instead.
+            trigger_error('The hook ($GLOBALS[\'TYPO3_CONF_VARS\'][\'SC_OPTIONS\'][' . $hookName . '][\'buildQueryParameters\']) will be removed in TYPO3 v10, the modifyQuery hook should be used instead.', E_USER_DEPRECATED);
             $hookObject = GeneralUtility::makeInstance($className);
             if (method_exists($hookObject, 'buildQueryParametersPostProcess')) {
                 $hookObject->buildQueryParametersPostProcess(
@@ -3420,6 +3422,19 @@ class PageLayoutView implements LoggerAwareInterface
                 );
             }
         }
+        foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][PageLayoutView::class]['modifyQuery'] ?? [] as $className) {
+            $hookObject = GeneralUtility::makeInstance($className);
+            if (method_exists($hookObject, 'modifyQuery')) {
+                $hookObject->modifyQuery(
+                    $parameters,
+                    $table,
+                    $pageId,
+                    $additionalConstraints,
+                    $fieldList,
+                    $queryBuilder
+                );
+            }
+        }
 
         // array_unique / array_filter used to eliminate empty and duplicate constraints
         // the array keys are eliminated by this as well to facilitate argument unpacking
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-83740-CleanupOfAbstractRecordListBreaksHook.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-83740-CleanupOfAbstractRecordListBreaksHook.rst
new file mode 100644 (file)
index 0000000..d19bfaa
--- /dev/null
@@ -0,0 +1,38 @@
+.. include:: ../../Includes.txt
+
+===============================================================
+Deprecation: #83740 - Cleanup of AbstractRecordList breaks hook
+===============================================================
+
+See :issue:`83740`
+
+Description
+===========
+
+The hook `$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList']['buildQueryParameters']`
+has been marked as deprecated. It was a hook to modify the current database query but used in multiple classes which
+leads to some issues. For this reason, the old hook is now deprecated and will be removed in v10.
+
+
+Impact
+======
+
+Registering a hook in `$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList']['buildQueryParameters']` will trigger a deprecation warning.
+
+
+Affected installations
+======================
+
+Instances with extensions using a `$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList']['buildQueryParameters']`-hook
+
+
+Migration
+=========
+
+Two new hooks are available to achieve the same things.
+
+Please see:
+
+Feature-83740-CleanupOfAbstractRecordListBreaksHook.rst
+
+.. index:: Backend, Database, PHP-API, FullyScanned
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Feature-83740-CleanupOfAbstractRecordListBreaksHook.rst b/typo3/sysext/core/Documentation/Changelog/master/Feature-83740-CleanupOfAbstractRecordListBreaksHook.rst
new file mode 100644 (file)
index 0000000..bfb4ce9
--- /dev/null
@@ -0,0 +1,54 @@
+.. include:: ../../Includes.txt
+
+===========================================================
+Feature: #83740 - Cleanup of AbstractRecordList breaks hook
+===========================================================
+
+See :issue:`83740`
+
+Description
+===========
+
+A new hook in :php:`DatabaseRecordList` and :php:`PageLayoutView` allows modify the current database query.
+
+Register the hook via
+
+* php:`$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][\TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList::class]['modifyQuery']`
+* php:`$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][\TYPO3\CMS\Backend\View\PageLayoutView::class]['modifyQuery']`
+
+in the extensions :file:`ext_localconf.php` file.
+
+Example
+=======
+
+An example implementation could look like this:
+
+:file:`EXT:my_site/ext_localconf.php`
+
+.. code-block:: php
+
+   $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][\TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList::class]['modifyQuery'][1313131313] =
+      \MyVendor\MySite\Hooks\DatabaseRecordListHook::class . '->modifyQuery';
+
+
+:file:`EXT:my_site/Classes/Hooks/DatabaseRecordListHook.php`
+
+.. code-block:: php
+
+   namespace MyVendor\MySite\Hooks;
+
+   class DatabaseRecordListHook
+   {
+      public function modifyQuery(
+         array $parameters,
+         string $table,
+         int $pageId,
+         array $additionalConstraints,
+         array $fieldList,
+         \TYPO3\CMS\Core\Database\Query\QueryBuilder $queryBuilder
+      ) {
+         // modify $queryBuilder
+      }
+   }
+
+.. index:: Backend, Database, PHP-API
index 13cc1e5..a514943 100644 (file)
@@ -144,4 +144,9 @@ return [
             'Deprecation-83252-Link-tagSyntaxProcesssing.rst',
         ],
     ],
+    '$GLOBALS[\'TYPO3_CONF_VARS\'][\'SC_OPTIONS\'][\'TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList\'][\'buildQueryParameters\']' => [
+        'restFiles' => [
+            'Deprecation-83740-CleanupOfAbstractRecordListBreaksHook.rst',
+        ],
+    ],
 ];
index 00828ef..926ed98 100644 (file)
@@ -803,6 +803,8 @@ class AbstractDatabaseRecordList extends AbstractRecordList
 
         $hookName = DatabaseRecordList::class;
         if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][$hookName]['buildQueryParameters'])) {
+            // @deprecated since TYPO3 v9, will be removed in TYPO3 v10, the modifyQuery hook should be used instead.
+            trigger_error('The hook ($GLOBALS[\'TYPO3_CONF_VARS\'][\'SC_OPTIONS\'][' . $hookName . '][\'buildQueryParameters\']) will be removed in TYPO3 v10, the modifyQuery hook should be used instead.', E_USER_DEPRECATED);
             foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][$hookName]['buildQueryParameters'] as $className) {
                 $hookObject = GeneralUtility::makeInstance($className);
                 if (method_exists($hookObject, 'buildQueryParametersPostProcess')) {
index b2fba7c..63424b3 100644 (file)
@@ -3262,8 +3262,10 @@ class DatabaseRecordList
             );
         }
 
-        $hookName = static::class;
+        $hookName = DatabaseRecordList::class;
         if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][$hookName]['buildQueryParameters'])) {
+            // @deprecated since TYPO3 v9, will be removed in TYPO3 v10, the modifyQuery hook should be used instead.
+            trigger_error('The hook ($GLOBALS[\'TYPO3_CONF_VARS\'][\'SC_OPTIONS\'][' . $hookName . '][\'buildQueryParameters\']) will be removed in TYPO3 v10, the modifyQuery hook should be used instead.', E_USER_DEPRECATED);
             foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][$hookName]['buildQueryParameters'] as $className) {
                 $hookObject = GeneralUtility::makeInstance($className);
                 if (method_exists($hookObject, 'buildQueryParametersPostProcess')) {
@@ -3279,6 +3281,19 @@ class DatabaseRecordList
                 }
             }
         }
+        foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS'][$hookName]['modifyQuery'] ?? [] as $className) {
+            $hookObject = GeneralUtility::makeInstance($className);
+            if (method_exists($hookObject, 'modifyQuery')) {
+                $hookObject->modifyQuery(
+                    $parameters,
+                    $table,
+                    $pageId,
+                    $additionalConstraints,
+                    $fieldList,
+                    $queryBuilder
+                );
+            }
+        }
 
         // array_unique / array_filter used to eliminate empty and duplicate constraints
         // the array keys are eliminated by this as well to facilitate argument unpacking