Skip to content

Commit

Permalink
Merge pull request #11202 from mpdude/mergeup-2.18.x-3.0.x
Browse files Browse the repository at this point in the history
Merge 2.18.x up into 3.0.x
  • Loading branch information
greg0ire authored Feb 1, 2024
2 parents fd8d981 + c7a91a4 commit 2e155e9
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 250 deletions.
15 changes: 0 additions & 15 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -788,12 +788,6 @@
<InvalidArgument>
<code>$sqlParams</code>
</InvalidArgument>
<LessSpecificReturnStatement>
<code><![CDATA[$this->parse()->getSqlExecutor()->getSqlStatements()]]></code>
</LessSpecificReturnStatement>
<MoreSpecificReturnType>
<code><![CDATA[list<string>|string]]></code>
</MoreSpecificReturnType>
<PossiblyNullArgument>
<code><![CDATA[$this->getDQL()]]></code>
</PossiblyNullArgument>
Expand Down Expand Up @@ -896,15 +890,6 @@
<PossiblyInvalidIterator>
<code><![CDATA[$this->sqlStatements]]></code>
</PossiblyInvalidIterator>
<PropertyNotSetInConstructor>
<code>MultiTableUpdateExecutor</code>
</PropertyNotSetInConstructor>
<PropertyTypeCoercion>
<code><![CDATA[$this->sqlStatements]]></code>
</PropertyTypeCoercion>
<UninitializedProperty>
<code><![CDATA[$this->sqlStatements]]></code>
</UninitializedProperty>
</file>
<file src="src/Query/Exec/SingleSelectExecutor.php">
<PossiblyInvalidArgument>
Expand Down
2 changes: 1 addition & 1 deletion src/Query/Exec/AbstractSqlExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ abstract class AbstractSqlExecutor
/**
* Gets the SQL statements that are executed by the executor.
*
* @return mixed[]|string All the SQL update statements.
* @return list<string>|string All the SQL update statements.
*/
public function getSqlStatements(): array|string
{
Expand Down
17 changes: 9 additions & 8 deletions src/Query/Exec/MultiTableUpdateExecutor.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,10 +42,11 @@ class MultiTableUpdateExecutor extends AbstractSqlExecutor
*/
public function __construct(AST\Node $AST, SqlWalker $sqlWalker)
{
$em = $sqlWalker->getEntityManager();
$conn = $em->getConnection();
$platform = $conn->getDatabasePlatform();
$quoteStrategy = $em->getConfiguration()->getQuoteStrategy();
$em = $sqlWalker->getEntityManager();
$conn = $em->getConnection();
$platform = $conn->getDatabasePlatform();
$quoteStrategy = $em->getConfiguration()->getQuoteStrategy();
$this->sqlStatements = [];

if ($conn instanceof PrimaryReadReplicaConnection) {
$conn->ensureConnectedToPrimary();
Expand Down Expand Up @@ -77,13 +78,13 @@ public function __construct(AST\Node $AST, SqlWalker $sqlWalker)

// 3. Create and store UPDATE statements
$classNames = [...$primaryClass->parentClasses, ...[$primaryClass->name], ...$primaryClass->subClasses];
$i = -1;

foreach (array_reverse($classNames) as $className) {
$affected = false;
$class = $em->getClassMetadata($className);
$updateSql = 'UPDATE ' . $quoteStrategy->getTableName($class, $platform) . ' SET ';

$sqlParameters = [];
foreach ($updateItems as $updateItem) {
$field = $updateItem->pathExpression->field;

Expand All @@ -95,23 +96,23 @@ public function __construct(AST\Node $AST, SqlWalker $sqlWalker)

if (! $affected) {
$affected = true;
++$i;
} else {
$updateSql .= ', ';
}

$updateSql .= $sqlWalker->walkUpdateItem($updateItem);

if ($newValue instanceof AST\InputParameter) {
$this->sqlParameters[$i][] = $newValue->name;
$sqlParameters[] = $newValue->name;

++$this->numParametersInUpdateClause;
}
}
}

if ($affected) {
$this->sqlStatements[$i] = $updateSql . ' WHERE (' . $idColumnList . ') IN (' . $idSubselect . ')';
$this->sqlParameters[] = $sqlParameters;
$this->sqlStatements[] = $updateSql . ' WHERE (' . $idColumnList . ') IN (' . $idSubselect . ')';
}
}

Expand Down
Loading

0 comments on commit 2e155e9

Please sign in to comment.