Revert "[DDC-551] Initial support for filters in the JoinedSubclassPersister"
This reverts commit f6d5f0481e
.
This commit is contained in:
parent
bf1cc29a2a
commit
e98c775f0d
@ -1584,7 +1584,7 @@ class BasicEntityPersister
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function generateFilterConditionSQL(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '')
|
private function generateFilterConditionSQL(ClassMetadata $targetEntity, $targetTableAlias)
|
||||||
{
|
{
|
||||||
$filterSql = '';
|
$filterSql = '';
|
||||||
|
|
||||||
|
@ -328,17 +328,8 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
|
|||||||
|
|
||||||
$joinSql .= $baseTableAlias . '.' . $idColumn . ' = ' . $tableAlias . '.' . $idColumn;
|
$joinSql .= $baseTableAlias . '.' . $idColumn . ' = ' . $tableAlias . '.' . $idColumn;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filters for each parent table
|
|
||||||
$filterSql = $this->generateFilterConditionSQL($parentClass, $tableAlias, $parentClass->table['name']);
|
|
||||||
if('' !== $filterSql) {
|
|
||||||
if (!$first) $joinSql .= ' AND ';
|
|
||||||
$joinSql .= $filterSql;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//@todo: filters for the sub tables of childs
|
|
||||||
|
|
||||||
// OUTER JOIN sub tables
|
// OUTER JOIN sub tables
|
||||||
foreach ($this->_class->subClasses as $subClassName) {
|
foreach ($this->_class->subClasses as $subClassName) {
|
||||||
$subClass = $this->_em->getClassMetadata($subClassName);
|
$subClass = $this->_em->getClassMetadata($subClassName);
|
||||||
@ -398,13 +389,6 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
|
|||||||
$lockSql = ' ' . $this->_platform->getWriteLockSql();
|
$lockSql = ' ' . $this->_platform->getWriteLockSql();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Filters for the base table
|
|
||||||
$filterSql = $this->generateFilterConditionSQL($this->_class, $baseTableAlias, $this->_class->table['name']);
|
|
||||||
if('' !== $filterSql) {
|
|
||||||
if($conditionSql) $conditionSql .= ' AND ';
|
|
||||||
$conditionSql .= $filterSql;
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->_platform->modifyLimitQuery('SELECT ' . $this->_selectColumnListSql
|
return $this->_platform->modifyLimitQuery('SELECT ' . $this->_selectColumnListSql
|
||||||
. ' FROM ' . $this->_class->getQuotedTableName($this->_platform) . ' ' . $baseTableAlias
|
. ' FROM ' . $this->_class->getQuotedTableName($this->_platform) . ' ' . $baseTableAlias
|
||||||
. $joinSql
|
. $joinSql
|
||||||
@ -490,13 +474,13 @@ class JoinedSubclassPersister extends AbstractEntityInheritancePersister
|
|||||||
$this->_class->setFieldValue($entity, $this->_class->versionField, $value);
|
$this->_class->setFieldValue($entity, $this->_class->versionField, $value);
|
||||||
}
|
}
|
||||||
|
|
||||||
private function generateFilterConditionSQL(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '')
|
private function generateFilterConditionSQL(ClassMetadata $targetEntity, $targetTableAlias)
|
||||||
{
|
{
|
||||||
$filterSql = '';
|
$filterSql = '';
|
||||||
|
|
||||||
$first = true;
|
$first = true;
|
||||||
foreach($this->_em->getFilters()->getEnabledFilters() as $filter) {
|
foreach($this->_em->getFilters()->getEnabledFilters() as $filter) {
|
||||||
if("" !== $filterExpr = $filter->addFilterConstraint($targetEntity, $targetTableAlias, $targetTable)) {
|
if("" !== $filterExpr = $filter->addFilterConstraint($targetEntity, $targetTableAlias)) {
|
||||||
if ( ! $first) $filterSql .= ' AND '; else $first = false;
|
if ( ! $first) $filterSql .= ' AND '; else $first = false;
|
||||||
$filterSql .= '(' . $filterExpr . ')';
|
$filterSql .= '(' . $filterExpr . ')';
|
||||||
}
|
}
|
||||||
|
@ -73,5 +73,5 @@ abstract class SQLFilter
|
|||||||
/**
|
/**
|
||||||
* @return string The constraint if there is one, empty string otherwise
|
* @return string The constraint if there is one, empty string otherwise
|
||||||
*/
|
*/
|
||||||
abstract public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '');
|
abstract public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias);
|
||||||
}
|
}
|
||||||
|
@ -449,44 +449,6 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||||||
$this->assertEquals(1, count($user->groups->slice(0,10)));
|
$this->assertEquals(1, count($user->groups->slice(0,10)));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function testJoinSubclassPersister_FilterOnBaseTable()
|
|
||||||
{
|
|
||||||
$this->loadCompanyFixtureData();
|
|
||||||
$this->assertEquals(2, count($this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyManager')->findAll()));
|
|
||||||
|
|
||||||
// Enable the filter
|
|
||||||
$conf = $this->_em->getConfiguration();
|
|
||||||
$conf->addFilter("manager_title", "\Doctrine\Tests\ORM\Functional\CompanyManagerTitleFilter");
|
|
||||||
$this->_em->getFilters()
|
|
||||||
->enable("manager_title")
|
|
||||||
->setParameter("title", "devlead", \Doctrine\DBAL\Types\Type::getType(\Doctrine\DBAL\Types\Type::STRING)->getBindingType());
|
|
||||||
|
|
||||||
$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
|
|
||||||
|
|
||||||
$managers = $this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyManager')->findAll();
|
|
||||||
$this->assertEquals(1, count($managers));
|
|
||||||
$this->assertEquals("Guilherme", $managers[0]->getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
public function testJoinSubclassPersister_FilterOnParentTable()
|
|
||||||
{
|
|
||||||
$this->loadCompanyFixtureData();
|
|
||||||
$this->assertEquals(2, count($this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyManager')->findAll()));
|
|
||||||
|
|
||||||
// Enable the filter
|
|
||||||
$conf = $this->_em->getConfiguration();
|
|
||||||
$conf->addFilter("employee_department", "\Doctrine\Tests\ORM\Functional\CompanyEmployeeDepartmentFilter");
|
|
||||||
$this->_em->getFilters()
|
|
||||||
->enable("employee_department")
|
|
||||||
->setParameter("department", "parsers", \Doctrine\DBAL\Types\Type::getType(\Doctrine\DBAL\Types\Type::STRING)->getBindingType());
|
|
||||||
|
|
||||||
$this->_em->getConnection()->getConfiguration()->setSQLLogger(new \Doctrine\DBAL\Logging\EchoSQLLogger);
|
|
||||||
|
|
||||||
$managers = $this->_em->getRepository('Doctrine\Tests\Models\Company\CompanyManager')->findAll();
|
|
||||||
$this->assertEquals(1, count($managers));
|
|
||||||
$this->assertEquals("Guilherme", $managers[0]->getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
private function loadFixtureData()
|
private function loadFixtureData()
|
||||||
{
|
{
|
||||||
$user = new CmsUser;
|
$user = new CmsUser;
|
||||||
@ -574,7 +536,7 @@ class SQLFilterTest extends \Doctrine\Tests\OrmFunctionalTestCase
|
|||||||
|
|
||||||
class MySoftDeleteFilter extends SQLFilter
|
class MySoftDeleteFilter extends SQLFilter
|
||||||
{
|
{
|
||||||
public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '')
|
public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias)
|
||||||
{
|
{
|
||||||
if ($targetEntity->name != "MyEntity\SoftDeleteNewsItem") {
|
if ($targetEntity->name != "MyEntity\SoftDeleteNewsItem") {
|
||||||
return "";
|
return "";
|
||||||
@ -586,7 +548,7 @@ class MySoftDeleteFilter extends SQLFilter
|
|||||||
|
|
||||||
class MyLocaleFilter extends SQLFilter
|
class MyLocaleFilter extends SQLFilter
|
||||||
{
|
{
|
||||||
public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '')
|
public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias)
|
||||||
{
|
{
|
||||||
if (!in_array("LocaleAware", $targetEntity->reflClass->getInterfaceNames())) {
|
if (!in_array("LocaleAware", $targetEntity->reflClass->getInterfaceNames())) {
|
||||||
return "";
|
return "";
|
||||||
@ -598,7 +560,7 @@ class MyLocaleFilter extends SQLFilter
|
|||||||
|
|
||||||
class CMSCountryFilter extends SQLFilter
|
class CMSCountryFilter extends SQLFilter
|
||||||
{
|
{
|
||||||
public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '')
|
public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias)
|
||||||
{
|
{
|
||||||
if ($targetEntity->name != "Doctrine\Tests\Models\CMS\CmsAddress") {
|
if ($targetEntity->name != "Doctrine\Tests\Models\CMS\CmsAddress") {
|
||||||
return "";
|
return "";
|
||||||
@ -610,7 +572,7 @@ class CMSCountryFilter extends SQLFilter
|
|||||||
|
|
||||||
class CMSGroupPrefixFilter extends SQLFilter
|
class CMSGroupPrefixFilter extends SQLFilter
|
||||||
{
|
{
|
||||||
public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '')
|
public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias)
|
||||||
{
|
{
|
||||||
if ($targetEntity->name != "Doctrine\Tests\Models\CMS\CmsGroup") {
|
if ($targetEntity->name != "Doctrine\Tests\Models\CMS\CmsGroup") {
|
||||||
return "";
|
return "";
|
||||||
@ -621,7 +583,7 @@ class CMSGroupPrefixFilter extends SQLFilter
|
|||||||
}
|
}
|
||||||
class CMSArticleTopicFilter extends SQLFilter
|
class CMSArticleTopicFilter extends SQLFilter
|
||||||
{
|
{
|
||||||
public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '')
|
public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias)
|
||||||
{
|
{
|
||||||
if ($targetEntity->name != "Doctrine\Tests\Models\CMS\CmsArticle") {
|
if ($targetEntity->name != "Doctrine\Tests\Models\CMS\CmsArticle") {
|
||||||
return "";
|
return "";
|
||||||
@ -630,27 +592,3 @@ class CMSArticleTopicFilter extends SQLFilter
|
|||||||
return $targetTableAlias.'.topic = ' . $this->getParameter('topic'); // getParam uses connection to quote the value.
|
return $targetTableAlias.'.topic = ' . $this->getParameter('topic'); // getParam uses connection to quote the value.
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class CompanyManagerTitleFilter extends SQLFilter
|
|
||||||
{
|
|
||||||
public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '')
|
|
||||||
{
|
|
||||||
if ($targetEntity->name != "Doctrine\Tests\Models\Company\CompanyManager") {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
return $targetTableAlias.'.title = ' . $this->getParameter('title'); // getParam uses connection to quote the value.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class CompanyEmployeeDepartmentFilter extends SQLFilter
|
|
||||||
{
|
|
||||||
public function addFilterConstraint(ClassMetadata $targetEntity, $targetTableAlias, $targetTable = '')
|
|
||||||
{
|
|
||||||
if ($targetEntity->name != "Doctrine\Tests\Models\Company\CompanyEmployee") {
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
return $targetTableAlias.'.department = ' . $this->getParameter('department'); // getParam uses connection to quote the value.
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Loading…
Reference in New Issue
Block a user