Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TASK] Add description for complex restrictions #840

Merged
merged 3 commits into from
Sep 1, 2020

Conversation

manuelselbach
Copy link
Contributor

With this change a description for very complex scenarios about
the usage of restrictions in combination of joins is added.

Furthermore a little hint is added regarding the interface
EnforceableQueryRestrictionInterface for restrictions and the
impact while using ->removeAll() and removeByType() of the
RestrictionsContainer on those restrictions.

With this change a description for very complex scenarios about
the usage of restrictions in combination of joins is added.

Furthermore a little hint is added regarding the interface
`EnforceableQueryRestrictionInterface` for restrictions and the
impact while using `->removeAll()` and `removeByType()` of the
RestrictionsContainer on those restrictions.
Copy link
Contributor

@sypets sypets left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, I left some general comments about spelling, formatting and things that were not immediately clear to me when reading.

Please tell us if you would like to make the necessary fixes yourself. Otherwise one of us can take care of it.

Apart from my nitpicks: the new text and code example is well readable and easy to understand. I have not thorougly checked, but superficially it looked straightforward.

Thanks for supplying this useful example! 👍

@@ -146,6 +146,11 @@ Restrictions
records need to be handled after the SQL results are fetched, by overlaying the records with
:php:`BackendUtility::getRecordWSOL()`, :php:`PageRepository->versionOL()` or `PlainDataResolver`.

If a Restriction needs to be enforced as it should always be applied, a restrition could implement the interface `EnforceableQueryRestrictionInterface`. Is this interface implemented for a Restrition, please take care of the following behavior:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are 2 small typos: restrition -> restriction.

@@ -146,6 +146,11 @@ Restrictions
records need to be handled after the SQL results are fetched, by overlaying the records with
:php:`BackendUtility::getRecordWSOL()`, :php:`PageRepository->versionOL()` or `PlainDataResolver`.

If a Restriction needs to be enforced as it should always be applied, a restrition could implement the interface `EnforceableQueryRestrictionInterface`. Is this interface implemented for a Restrition, please take care of the following behavior:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If a Restriction needs to be enforced as it should always be applied

I would shorten this to just "If a restriction needs to be enforced" or "If a restriction should always be applied". I think it is enough and makes for smoother reading.


* `->removeAll()` will remove all restrictions except the ones that implement the interface `EnforceableQueryRestrictionInterface`

* `->removeByType()` will remove a restriction completely, also restritions that implement the interface `EnforceableQueryRestrictionInterface`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

restritions -> restrictions

// build a custom restriction container
$myRestrictionContainer = new DefaultRestrictionContainer();

// remove all restricitons that should not been used
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

restricitons -> restrictions

// build a custom restriction container
$myRestrictionContainer = new DefaultRestrictionContainer();

// remove all restricitons that should not been used
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

been > be

@@ -223,3 +228,51 @@ deliver and use an own set of restrictions for own query statements if needed.
It can be very helpful to debug the final statements created by the `RestrictionBuilder` using
:php:`debug($queryBuilder->getSQL())` right before the final call to :php:`$queryBuilder->execute()`. Just
take care these calls **do not** :ref:`end up in production <database-query-builder-get-sql>` code.


A very complex example is that you might want to apply one or more restriction/s to only one table. Let's say,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A very complex example is that you might want to apply one or more restriction/s to only one table.

I am not sure I understand this sentence. What is complex about applying the restriction to only one table?

@@ -146,6 +146,11 @@ Restrictions
records need to be handled after the SQL results are fetched, by overlaying the records with
:php:`BackendUtility::getRecordWSOL()`, :php:`PageRepository->versionOL()` or `PlainDataResolver`.

If a Restriction needs to be enforced as it should always be applied, a restrition could implement the interface `EnforceableQueryRestrictionInterface`. Is this interface implemented for a Restrition, please take care of the following behavior:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this interface implemented for a Restrition, please take care of the following behavior:

I am not sure what is to be done here. To me, what follows is just a clarification what removeAll and removeByType will do. I would phrase it like this:

If a restriction implements EnforceableQueryRestrictionInterface, the following applies.

But this may also be a misunderstanding on my end.

that you have content in table `tt_content` that could have another record as parent record assigned in field
`parent`. Now you would like to get all records except the child records where the parent record is hidden.

// use TYPO3\CMS\Core\Utility\GeneralUtility;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be a code block. Just add a :: to the end of the previous sentence, e.g.

where the parent record is hidden::

This is the same as doing:

where the parent record is hidden:
.. code-block:: php

(because our default language for code blocks is defined as PHP in TYPO3 Explained)

This is a .rst gotcha because you do not need to do that in Markdown.

->leftJoin('c1', 'tt_content', 'c2', 'c1.parent = c2.uid')
->orWhere($queryBuilder->expr()->isNull('c2.uid'), $doctrineQueryBuilderExpressions);

With this you will end up with the following query:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Again, make sure the next block is formatted as code block. But here we cannot use PHP so we should use:

With this you will end up with the following query:

.. code-block: sql

@manuelselbach
Copy link
Contributor Author

I've applied and adapted the changes mentioned in the comments. Thanks for your detailed review and suggestions.

@lolli42 lolli42 merged commit b26e7b3 into TYPO3-Documentation:master Sep 1, 2020
lolli42 pushed a commit that referenced this pull request Sep 1, 2020
* [TASK] Add description for complex restrictions

With this change a description for very complex scenarios about
the usage of restrictions in combination of joins is added.

Furthermore a little hint is added regarding the interface
`EnforceableQueryRestrictionInterface` for restrictions and the
impact while using `->removeAll()` and `removeByType()` of the
RestrictionsContainer on those restrictions.
@jonaseberle jonaseberle mentioned this pull request Nov 25, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants