Commit 9c9654e2 authored by germansokolov13's avatar germansokolov13

Убирает всю привязку к событиям, чтобы полагаться на softDelete(вызывается из…

Убирает всю привязку к событиям, чтобы полагаться на softDelete(вызывается из delete из ActiveRecord). Добавляет ретёртны результатов сейвов. Слегка фиксит forceDelete
parent 72ffb07e
......@@ -36,21 +36,12 @@ class SoftDelete extends Behavior
*/
public $activeValue = 1;
/**
* @inheritdoc
*/
public function events() {
return [
ActiveRecord::EVENT_BEFORE_DELETE => 'softDelete',
];
}
/**
* Set the attribute deleted
*
* @param Event $event
* Удалить софтделитом. Возращает true/false в зависимости от того, успешно ли
* @return bool
*/
public function softDelete($event) {
public function softDelete() {
if($this->timeAttribute) {
$attributes[0] = $this->timeAttribute;
$this->owner->$attributes[0] = time();
......@@ -60,14 +51,12 @@ class SoftDelete extends Behavior
$this->owner->$attributes[1] = $this->deletedValue;
// save record
$this->owner->save(false, $attributes);
//prevent real delete
$event->isValid = false;
return $this->owner->save(false, $attributes);
}
/**
* Restore soft-deleted record
* Restore soft-deleted record. Возращает true/false в зависимости от того, успешно ли
* @return bool
*/
public function restore() {
if($this->timeAttribute) {
......@@ -79,15 +68,20 @@ class SoftDelete extends Behavior
$this->owner->$attributes[1] = $this->activeValue;
// save record
$this->owner->save(false, $attributes);
return $this->owner->save(false, $attributes);
}
/**
* Force delete from database
* Force delete from database. Возращает true/false в зависимости от того, успешно ли
* @return bool
*/
public function forceDelete() {
// store model so that we can detach the behavior and delete as normal
$model = $this->owner;
$this->detach();
$model->delete();
$result = $model->delete();
$this->attach($model);
return $result;
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment