|
18 | 18 | use Doctrine\ORM\Query\AST\SelectStatement; |
19 | 19 | use Doctrine\ORM\Query\AST\UpdateStatement; |
20 | 20 | use Doctrine\ORM\Query\Exec\AbstractSqlExecutor; |
| 21 | +use Doctrine\ORM\Query\Exec\PreparedExecutorFinalizer; |
21 | 22 | use Doctrine\ORM\Query\Exec\SingleTableDeleteUpdateExecutor; |
22 | | -use Doctrine\ORM\Query\SqlWalker; |
| 23 | +use Doctrine\ORM\Query\Exec\SqlFinalizer; |
23 | 24 | use Gedmo\Exception\RuntimeException; |
24 | 25 | use Gedmo\Exception\UnexpectedValueException; |
25 | 26 | use Gedmo\SoftDeleteable\Query\TreeWalker\Exec\MultiTableDeleteExecutor; |
26 | 27 | use Gedmo\SoftDeleteable\SoftDeleteableListener; |
| 28 | +use Gedmo\Tool\ORM\Walker\CompatSqlOutputWalker; |
27 | 29 | use Gedmo\Tool\ORM\Walker\SqlWalkerCompat; |
28 | 30 |
|
29 | 31 | /** |
|
36 | 38 | * |
37 | 39 | * @final since gedmo/doctrine-extensions 3.11 |
38 | 40 | */ |
39 | | -class SoftDeleteableWalker extends SqlWalker |
| 41 | +class SoftDeleteableWalker extends CompatSqlOutputWalker |
40 | 42 | { |
41 | 43 | use SqlWalkerCompat; |
42 | 44 |
|
@@ -99,21 +101,43 @@ public function __construct($query, $parserResult, array $queryComponents) |
99 | 101 | * @param SelectStatement|UpdateStatement|DeleteStatement $statement |
100 | 102 | * |
101 | 103 | * @throws UnexpectedValueException when an unsupported AST statement is given |
| 104 | + * |
| 105 | + * @phpstan-assert DeleteStatement $statement |
102 | 106 | */ |
103 | 107 | protected function doGetExecutorWithCompat($statement): AbstractSqlExecutor |
104 | 108 | { |
105 | | - switch (true) { |
106 | | - case $statement instanceof DeleteStatement: |
107 | | - assert(class_exists($statement->deleteClause->abstractSchemaName)); |
| 109 | + if (!$statement instanceof DeleteStatement) { |
| 110 | + throw new UnexpectedValueException('SoftDeleteable walker should be used only on delete statement'); |
| 111 | + } |
108 | 112 |
|
109 | | - $primaryClass = $this->getEntityManager()->getClassMetadata($statement->deleteClause->abstractSchemaName); |
| 113 | + return $this->createDeleteStatementExecutor($statement); |
| 114 | + } |
110 | 115 |
|
111 | | - return $primaryClass->isInheritanceTypeJoined() |
112 | | - ? new MultiTableDeleteExecutor($statement, $this, $this->meta, $this->getConnection()->getDatabasePlatform(), $this->configuration) |
113 | | - : new SingleTableDeleteUpdateExecutor($statement, $this); |
114 | | - default: |
115 | | - throw new UnexpectedValueException('SoftDeleteable walker should be used only on delete statement'); |
| 116 | + /** |
| 117 | + * @param DeleteStatement|UpdateStatement|SelectStatement $AST |
| 118 | + * |
| 119 | + * @throws UnexpectedValueException when an unsupported AST statement is given |
| 120 | + * |
| 121 | + * @phpstan-assert DeleteStatement $AST |
| 122 | + */ |
| 123 | + protected function doGetFinalizerWithCompat($AST): SqlFinalizer |
| 124 | + { |
| 125 | + if (!$AST instanceof DeleteStatement) { |
| 126 | + throw new UnexpectedValueException('SoftDeleteable walker should be used only on delete statement'); |
116 | 127 | } |
| 128 | + |
| 129 | + return new PreparedExecutorFinalizer($this->createDeleteStatementExecutor($AST)); |
| 130 | + } |
| 131 | + |
| 132 | + protected function createDeleteStatementExecutor(DeleteStatement $AST): AbstractSqlExecutor |
| 133 | + { |
| 134 | + assert(class_exists($AST->deleteClause->abstractSchemaName)); |
| 135 | + |
| 136 | + $primaryClass = $this->getEntityManager()->getClassMetadata($AST->deleteClause->abstractSchemaName); |
| 137 | + |
| 138 | + return $primaryClass->isInheritanceTypeJoined() |
| 139 | + ? new MultiTableDeleteExecutor($AST, $this, $this->meta, $this->getConnection()->getDatabasePlatform(), $this->configuration) |
| 140 | + : new SingleTableDeleteUpdateExecutor($AST, $this); |
117 | 141 | } |
118 | 142 |
|
119 | 143 | /** |
|
0 commit comments