Skip to content

Commit

Permalink
add SoftDeleteBehavior::$invokeDeleteEvents
Browse files Browse the repository at this point in the history
  • Loading branch information
klimov-paul committed Jul 6, 2023
1 parent a6cd0b9 commit e9b6e37
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/SoftDeleteBehavior.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,11 @@ class SoftDeleteBehavior extends CBehavior
* in format: `[attributeName => attributeValue]`. If not set value will be automatically detected from {@see softDeleteAttributeValues}.
*/
public $restoreAttributeValues;
/**
* @var bool whether to invoke owner {@see \CActiveRecord::beforeDelete()} and {@see \CActiveRecord::afterDelete()}
* while performing soft delete. This option affects only {@see softDelete()} method.
*/
public $invokeDeleteEvents = true;
/**
* @var callable|null callback, which execution determines if record should be "hard" deleted instead of being marked
* as deleted. Callback should match following signature: `bool function(\CActiveRecord $model)`
Expand Down Expand Up @@ -180,7 +185,17 @@ public function softDelete(): bool
return $this->owner->delete();
}

return $this->softDeleteInternal();
if ($this->invokeDeleteEvents && !$this->owner->evaluateExpression('$this->beforeDelete()')) {
return false;
}

$result = $this->softDeleteInternal();

if ($this->invokeDeleteEvents) {
$this->owner->evaluateExpression('$this->afterDelete()');
}

return $result;
}

/**
Expand Down

0 comments on commit e9b6e37

Please sign in to comment.