Skip to content

[Translatable] added selective field translation to the translatable extension #2874

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions src/Translatable/Query/TreeWalker/TranslationWalker.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,13 @@
*/
public const HYDRATE_SIMPLE_OBJECT_TRANSLATION = '__gedmo.translatable.simple_object.hydrator';

/**
* Name for "only fields" hint
*
* @internal
*/
const HINT_ONLY_FIELDS = '__gedmo.translatable.only_fields';

/**
* Stores all component references from select clause
*
Expand Down Expand Up @@ -228,7 +235,7 @@
if (isset($decl->joinVariableDeclarations)) {
foreach ($decl->joinVariableDeclarations as $joinDecl) {
if ($joinDecl->join instanceof Join) {
if (isset($this->components[$joinDecl->join->aliasIdentificationVariable])) {

Check failure on line 238 in src/Translatable/Query/TreeWalker/TranslationWalker.php

View workflow job for this annotation

GitHub Actions / PHPStan

Ignored error pattern #^Access to an undefined property Doctrine\\ORM\\Query\\AST\\Join\:\:\$aliasIdentificationVariable\.$# in path /home/runner/work/DoctrineExtensions/DoctrineExtensions/src/Translatable/Query/TreeWalker/TranslationWalker.php is expected to occur 2 times, but occurred only 1 time.
$result .= $this->components[$joinDecl->join->aliasIdentificationVariable];
}
}
Expand All @@ -237,7 +244,7 @@
// based on new changes
foreach ($decl->joins as $join) {
if ($join instanceof Join) {
if (isset($this->components[$join->joinAssociationDeclaration->aliasIdentificationVariable])) {

Check failure on line 247 in src/Translatable/Query/TreeWalker/TranslationWalker.php

View workflow job for this annotation

GitHub Actions / PHPStan

Ignored error pattern #^Access to an undefined property Doctrine\\ORM\\Query\\AST\\Node\:\:\$aliasIdentificationVariable\.$# in path /home/runner/work/DoctrineExtensions/DoctrineExtensions/src/Translatable/Query/TreeWalker/TranslationWalker.php is expected to occur 2 times, but occurred only 1 time.
$result .= $this->components[$join->joinAssociationDeclaration->aliasIdentificationVariable];
}
}
Expand Down Expand Up @@ -272,6 +279,7 @@
$ea->setEntityManager($em);
$quoteStrategy = $em->getConfiguration()->getQuoteStrategy();
$joinStrategy = $q->getHint(TranslatableListener::HINT_INNER_JOIN) ? 'INNER' : 'LEFT';
$onlyFields = $q->getHint(self::HINT_ONLY_FIELDS);

foreach ($this->translatedComponents as $dqlAlias => $comp) {
/** @var ClassMetadata $meta */
Expand All @@ -281,6 +289,13 @@
$transMeta = $em->getClassMetadata($transClass);
$transTable = $quoteStrategy->getTableName($transMeta, $this->platform);
foreach ($config['fields'] as $field) {
if ($onlyFields) {
$checkField = $dqlAlias.'.'.$field;
if (!\in_array($checkField, $onlyFields, true)) {
continue;

Check warning on line 295 in src/Translatable/Query/TreeWalker/TranslationWalker.php

View check run for this annotation

Codecov / codecov/patch

src/Translatable/Query/TreeWalker/TranslationWalker.php#L293-L295

Added lines #L293 - L295 were not covered by tests
}
}

$compTblAlias = $this->walkIdentificationVariable($dqlAlias, $field);
$tblAlias = $this->getSQLTableAlias('trans'.$compTblAlias.$field);
$sql = " {$joinStrategy} JOIN ".$transTable.' '.$tblAlias;
Expand Down
Loading