Task #47842
Refactor findBy API
Status: | Resolved | Start date: | 2013-05-02 | |
---|---|---|---|---|
Priority: | Should have | Due date: | ||
Assigned To: | Fabien Udriot | % Done: | 100% |
|
Category: | - | |||
Target version: | 1.0.0 |
Description
Sorry for changing the API but I would like to do it before the public release. The main reason is to narrow the API towards what has Doctrine.
The change affect mainly the findFiltered
method which is replaced by findBy
according to:
http://www.doctrine-project.org/api/orm/2.3/source-class-Doctrine.ORM.EntityRepository.html#159-171
The patch will also improve MM finding in repository: $repository->findByCategories()
Quite roughly:
Before: $respository->findFiltered($filter, $order, $offset, $limit) After: $respository->findBy($match, $order, $limit, $offset)
Before: $filter->getConstraint() $filter->setConstraint() $filter->addConstraint() After (same signature): $match->getMatches() $match->setMatches() $match->addMatches()
Before: $pager->getItemsPerPage() $pager->setItemsPerPage() After (same signature): $pager->getLimit() $pager->setLimit()
Related issues
Associated revisions
[!!!][FEATURE] Refactor findBy API
This is a breaking change affecting method "findFiltered" which is
replaced by "findBy" according to Doctrine style. On the good side,
the patch also improves MM finding in repository: $repository->findByCategories()
Change-Id: I19aa566f59588942df5cbce6d888027fdc42ca73
Fixes: #47842
Reviewed-on: https://review.typo3.org/20432
Reviewed-by: Frans Saris
Tested-by: Frans Saris
Reviewed-by: Fabien Udriot
Tested-by: Fabien Udriot
History
#1 Updated by Gerrit Code Review over 2 years ago
Patch set 1 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/20432
#2 Updated by Frans Saris over 2 years ago
Is it with this change posible to query an aditional mm relation that are added to the tca?
For a client project I need to extent sys_file/asset with the posibility to add tags. So I need to implement a new mm relation.
I see the patch is wip, what needs to be done or is still missing? Maybe I can help.
If you plan to change the api, please do it now. Don't wait to long.
When do you want to release a first version?
#3 Updated by Fabien Udriot about 2 years ago
Hi Frans,
Is it with this change posible to query an aditional mm relation that are added to the tca?
That is the goal / idea, indeed.
I see the patch is wip, what needs to be done or is still missing? Maybe I can help.
It is basically finished. Though, I wanted to add some unit tests making sure the "mm" query would work and since I haven't really tested I am expecting some amendment to the patch. Here an example for Categories but could also work for Tags as long you have TCA configured.
/** @var $match \TYPO3\CMS\Media\QueryElement\Match */ $match = $this->objectManager->get('TYPO3\CMS\Media\QueryElement\Match'); $match->addMatch('categories', $uidOrObject); $match->addMatch('categories', $uidOrObject2); /** @var $assetRepository \TYPO3\CMS\Media\Domain\Model\AssetRepository */ $assetRepository = $this->objectManager->get('TYPO3\CMS\Media\Domain\Model\AssetRepository'); $assetRepository->findBy($match);
The same should work for findByCategories
- or findByTags
from your example:
/** @var $assetRepository \TYPO3\CMS\Media\Domain\Model\AssetRepository */ $assetRepository = $this->objectManager->get('TYPO3\CMS\Media\Domain\Model\AssetRepository'); $assetRepository->findByCategories($uidOrObject);
It is a "difficult" patch to get into but if you have time helping / making sure the feature is there, it would be awesome. I could merge the others patches if it helps apply the change set easier. Let me know.
When do you want to release a first version?
The soonest as possible. I think we have a decent set of features making it usable for a daily life use. However, before doing so, I would like merging the remaining patches pending in Gerrit as well as this critical one.
#4 Updated by Frans Saris about 2 years ago
I wil have a look at it monday.
The critical patch I reviewed and tested already now hope a core dev has a look at it. For the others I wil make some time monday or you must 100% be sure they are ok :)
#5 Updated by Fabien Udriot about 2 years ago
Actually, if you would like to have another MM relation than categories working for the findBy method (see example above) you probably have to change a few things. The current implementation is a special case for categories but should not be too difficult to extend.
In EXT:media/Classes/QueryElement/Query.php
, consider updating getClauseCategories
to getClauseMM
and around line 205 replace the if (! empty($matches['categories']))
by
$matches = $this->match->getMatches(); foreach ($this->match->getMatches() as $field => $value) { if ($this->tcaFieldService->hasRelationManyToMany($field)) { // here the rest with some modification... } }
#6 Updated by Fabien Udriot about 2 years ago
A last thing: there is a bit of confusion with method naming with getClauseCategories
, getClauseSearch
, getClauseConstraints
which all have the same purpose. Don't worry, I will rename them. There are private methods anyway.
#7 Updated by Frans Saris about 2 years ago
Oke, will look into that.
Maybe you can help me on an other thing. What's the easiest/best way to preform a LIKE query on the asset repository?
I need something like:
SELECT * FROM..... Where sys_file.identifier LIKE '/sample_data_map/%'
#8 Updated by Fabien Udriot about 2 years ago
Not tested code:
/** @var $match \TYPO3\CMS\Media\QueryElement\Match */ $match = $this->objectManager->get('TYPO3\CMS\Media\QueryElement\Match'); $match->setSearchTerm('foo'); /** @var $assetRepository \TYPO3\CMS\Media\Domain\Model\AssetRepository */ $assetRepository = $this->objectManager->get('TYPO3\CMS\Media\Domain\Model\AssetRepository'); $assetRepository->findBy($match);
#9 Updated by Gerrit Code Review about 2 years ago
Patch set 2 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/20432
#10 Updated by Frans Saris about 2 years ago
- Status changed from New to Accepted
#11 Updated by Gerrit Code Review about 2 years ago
Patch set 3 for branch master has been pushed to the review server.
It is available at https://review.typo3.org/20432
#12 Updated by Fabien Udriot about 2 years ago
- Status changed from Accepted to Resolved
- % Done changed from 0 to 100
Applied in changeset 0dd6cc2cf43cc248564411141ee4d1bc8caa9013.