Skip to content

Commit 6d0005d

Browse files
seto1ryuring
authored andcommitted
論理削除時にイベントの実行や関連データの削除を行わない (#4237)
1 parent 9534c29 commit 6d0005d

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

plugins/baser-core/src/Model/Table/SoftDeleteTrait.php

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
namespace BaserCore\Model\Table;
1313

14+
use ArrayObject;
1415
use Cake\ORM\RulesChecker;
1516
use Cake\Datasource\EntityInterface;
1617
use BaserCore\Error\MissingColumnException;
@@ -123,20 +124,6 @@ protected function _processDelete($entity, $options): bool
123124
return false;
124125
}
125126

126-
$event = $this->dispatchEvent('Model.beforeDelete', [
127-
'entity' => $entity,
128-
'options' => $options,
129-
]);
130-
131-
if ($event->isStopped()) {
132-
return $event->getResult();
133-
}
134-
135-
$this->_associations->cascadeDelete(
136-
$entity,
137-
['_primary' => false] + $options->getArrayCopy()
138-
);
139-
140127
$query = $this->updateQuery();
141128
$conditions = (array)$entity->extract($primaryKey);
142129
$statement = $query->update($this->getTable())
@@ -149,11 +136,6 @@ protected function _processDelete($entity, $options): bool
149136
return $success;
150137
}
151138

152-
$this->dispatchEvent('Model.afterDelete', [
153-
'entity' => $entity,
154-
'options' => $options,
155-
]);
156-
157139
return $success;
158140
}
159141

@@ -181,14 +163,27 @@ public function deleteAll($conditions): int
181163
* @param EntityInterface $entity entity
182164
* @return bool true in case of success, false otherwise.
183165
*/
184-
public function hardDelete(EntityInterface $entity)
166+
public function hardDelete(EntityInterface $entity, array $options = [])
185167
{
186168
if(!$this->enabled) {
187169
throw new \BadMethodCallException('SoftDeleteTrait is not enabled');
188170
}
189-
if (!$this->delete($entity)) {
190-
return false;
171+
172+
$options = new ArrayObject($options);
173+
174+
$event = $this->dispatchEvent('Model.beforeDelete', [
175+
'entity' => $entity,
176+
'options' => $options,
177+
]);
178+
if ($event->isStopped()) {
179+
return $event->getResult();
191180
}
181+
182+
$this->_associations->cascadeDelete(
183+
$entity,
184+
['_primary' => false] + $options->getArrayCopy()
185+
);
186+
192187
$primaryKey = (array)$this->getPrimaryKey();
193188
$query = $this->deleteQuery();
194189
$conditions = (array)$entity->extract($primaryKey);
@@ -201,6 +196,11 @@ public function hardDelete(EntityInterface $entity)
201196
return $success;
202197
}
203198

199+
$this->dispatchEvent('Model.afterDelete', [
200+
'entity' => $entity,
201+
'options' => $options,
202+
]);
203+
204204
return $success;
205205
}
206206

0 commit comments

Comments
 (0)