Skip to content

Commit

Permalink
Merge pull request #1800 from romain-pierre/fix-quote
Browse files Browse the repository at this point in the history
Fixes deprecated usages of the quote methods
  • Loading branch information
l3pp4rd authored Jul 2, 2017
2 parents f1c30b5 + 8ab7dda commit 5e2cc07
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions lib/Gedmo/Translatable/Query/TreeWalker/TranslationWalker.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace Gedmo\Translatable\Query\TreeWalker;

use Doctrine\ORM\Mapping\ClassMetadata;
use Gedmo\Translatable\Mapping\Event\Adapter\ORM as TranslatableEventAdapter;
use Gedmo\Translatable\TranslatableListener;
use Doctrine\DBAL\Types\Type;
Expand Down Expand Up @@ -296,41 +297,43 @@ private function prepareTranslatedComponents()
$em = $this->getEntityManager();
$ea = new TranslatableEventAdapter();
$ea->setEntityManager($em);
$quoteStrategy = $em->getConfiguration()->getQuoteStrategy();
$joinStrategy = $q->getHint(TranslatableListener::HINT_INNER_JOIN) ? 'INNER' : 'LEFT';

foreach ($this->translatedComponents as $dqlAlias => $comp) {
/** @var ClassMetadata $meta */
$meta = $comp['metadata'];
$config = $this->listener->getConfiguration($em, $meta->name);
$transClass = $this->listener->getTranslationClass($ea, $meta->name);
$transMeta = $em->getClassMetadata($transClass);
$transTable = $em->getConfiguration()->getQuoteStrategy()->getTableName($transMeta, $this->platform);
$transTable = $quoteStrategy->getTableName($transMeta, $this->platform);
foreach ($config['fields'] as $field) {
$compTblAlias = $this->walkIdentificationVariable($dqlAlias, $field);
$tblAlias = $this->getSQLTableAlias('trans'.$compTblAlias.$field);
$sql = " {$joinStrategy} JOIN ".$transTable.' '.$tblAlias;
$sql .= ' ON '.$tblAlias.'.'.$transMeta->getQuotedColumnName('locale', $this->platform)
$sql .= ' ON '.$tblAlias.'.'.$quoteStrategy->getColumnName('locale', $transMeta, $this->platform)
.' = '.$this->conn->quote($locale);
$sql .= ' AND '.$tblAlias.'.'.$transMeta->getQuotedColumnName('field', $this->platform)
$sql .= ' AND '.$tblAlias.'.'.$quoteStrategy->getColumnName('field', $transMeta, $this->platform)
.' = '.$this->conn->quote($field);
$identifier = $meta->getSingleIdentifierFieldName();
$idColName = $meta->getQuotedColumnName($identifier, $this->platform);
$idColName = $quoteStrategy->getColumnName($identifier, $meta, $this->platform);
if ($ea->usesPersonalTranslation($transClass)) {
$sql .= ' AND '.$tblAlias.'.'.$transMeta->getSingleAssociationJoinColumnName('object')
.' = '.$compTblAlias.'.'.$idColName;
} else {
$sql .= ' AND '.$tblAlias.'.'.$transMeta->getQuotedColumnName('objectClass', $this->platform)
$sql .= ' AND '.$tblAlias.'.'.$quoteStrategy->getColumnName('objectClass', $transMeta, $this->platform)
.' = '.$this->conn->quote($config['useObjectClass']);

$mappingFK = $transMeta->getFieldMapping('foreignKey');
$mappingPK = $meta->getFieldMapping($identifier);
$fkColName = $this->getCastedForeignKey($compTblAlias.'.'.$idColName, $mappingFK['type'], $mappingPK['type']);
$sql .= ' AND '.$tblAlias.'.'.$transMeta->getQuotedColumnName('foreignKey', $this->platform)
$sql .= ' AND '.$tblAlias.'.'.$quoteStrategy->getColumnName('foreignKey', $transMeta, $this->platform)
.' = '.$fkColName;
}
isset($this->components[$dqlAlias]) ? $this->components[$dqlAlias] .= $sql : $this->components[$dqlAlias] = $sql;

$originalField = $compTblAlias.'.'.$meta->getQuotedColumnName($field, $this->platform);
$substituteField = $tblAlias.'.'.$transMeta->getQuotedColumnName('content', $this->platform);
$originalField = $compTblAlias.'.'.$quoteStrategy->getColumnName($field, $meta, $this->platform);
$substituteField = $tblAlias.'.'.$quoteStrategy->getColumnName('content', $transMeta, $this->platform);

// Treat translation as original field type
$fieldMapping = $meta->getFieldMapping($field);
Expand Down

0 comments on commit 5e2cc07

Please sign in to comment.