force delete when updating documents #11m1x9w
This commit is contained in:
parent
fc38f259b6
commit
b42c81c05b
@ -38,7 +38,7 @@ class UpdateDocument extends Job implements ShouldUpdate
|
||||
$this->deleteMediaModel($this->model, 'attachment', $this->request);
|
||||
}
|
||||
|
||||
$this->deleteRelationships($this->model, ['items', 'item_taxes', 'totals']);
|
||||
$this->deleteRelationships($this->model, ['items', 'item_taxes', 'totals'], true);
|
||||
|
||||
$this->dispatch(new CreateDocumentItemsAndTotals($this->model, $this->request));
|
||||
|
||||
|
@ -9,7 +9,7 @@ use Illuminate\Support\Str;
|
||||
|
||||
trait Relationships
|
||||
{
|
||||
public function countRelationships($model, $relationships)
|
||||
public function countRelationships($model, $relationships): array
|
||||
{
|
||||
$record = new \stdClass();
|
||||
$record->model = $model;
|
||||
@ -36,10 +36,9 @@ trait Relationships
|
||||
*
|
||||
* @param $model
|
||||
* @param $relationships
|
||||
*
|
||||
* @return void
|
||||
* @param $permanently
|
||||
*/
|
||||
public function deleteRelationships($model, $relationships)
|
||||
public function deleteRelationships($model, $relationships, $permanently = false): void
|
||||
{
|
||||
$record = new \stdClass();
|
||||
$record->model = $model;
|
||||
@ -61,8 +60,10 @@ trait Relationships
|
||||
$items[] = $relation;
|
||||
}
|
||||
|
||||
$function = $permanently ? 'forceDelete' : 'delete';
|
||||
|
||||
foreach ((array) $items as $item) {
|
||||
$item->delete();
|
||||
$item->$function();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user