Skip to content

Commit

Permalink
[BUGFIX] Deprecate broken buildQueryParameters hook
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
NeoBlack authored and susannemoog committed Feb 8, 2018
1 parent 629d6fd commit 4f17dd0
Show file tree
Hide file tree
Showing 6 changed files with 130 additions and 1 deletion.
15 changes: 15 additions & 0 deletions typo3/sysext/backend/Classes/View/PageLayoutView.php
Expand Up @@ -3407,6 +3407,8 @@ protected function prepareQueryBuilder(

$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(
Expand All @@ -3420,6 +3422,19 @@ protected function prepareQueryBuilder(
);
}
}
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
Expand Down
@@ -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
@@ -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
Expand Up @@ -144,4 +144,9 @@
'Deprecation-83252-Link-tagSyntaxProcesssing.rst',
],
],
'$GLOBALS[\'TYPO3_CONF_VARS\'][\'SC_OPTIONS\'][\'TYPO3\CMS\Recordlist\RecordList\DatabaseRecordList\'][\'buildQueryParameters\']' => [
'restFiles' => [
'Deprecation-83740-CleanupOfAbstractRecordListBreaksHook.rst',
],
],
];
Expand Up @@ -803,6 +803,8 @@ protected function prepareQueryBuilder(

$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')) {
Expand Down
Expand Up @@ -3262,8 +3262,10 @@ protected function prepareQueryBuilder(
);
}

$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')) {
Expand All @@ -3279,6 +3281,19 @@ protected function prepareQueryBuilder(
}
}
}
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
Expand Down

0 comments on commit 4f17dd0

Please sign in to comment.