Fixed creating,deleting... not work expected.

This commit is contained in:
李铭昕 2019-06-24 15:13:30 +08:00
parent f8ffaedb1b
commit fce1695b91
2 changed files with 21 additions and 11 deletions

View File

@ -608,8 +608,10 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
return;
}
if ($this->fireModelEvent('deleting') === false) {
return false;
if ($event = $this->fireModelEvent('deleting')) {
if ($event instanceof StoppableEventInterface && $event->isPropagationStopped()) {
return false;
}
}
// Here, we'll touch the owning models, verifying these timestamps get updated
@ -622,7 +624,7 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
// Once the model has been deleted, we will fire off the deleted event so that
// the developers may hook into post-delete operations. We will then return
// a boolean true as the delete is presumably successful on the database.
$this->fireModelEvent('deleted', false);
$this->fireModelEvent('deleted');
return true;
}
@ -1326,8 +1328,10 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
// If the updating event returns false, we will cancel the update operation so
// developers can hook Validation systems into their models and cancel this
// operation if the model does not pass validation. Otherwise, we update.
if ($this->fireModelEvent('updating') === false) {
return false;
if ($event = $this->fireModelEvent('updating')) {
if ($event instanceof StoppableEventInterface && $event->isPropagationStopped()) {
return false;
}
}
// First we need to create a fresh query instance and touch the creation and
@ -1382,8 +1386,10 @@ abstract class Model implements ArrayAccess, Arrayable, Jsonable, JsonSerializab
*/
protected function performInsert(Builder $query)
{
if ($this->fireModelEvent('creating') === false) {
return false;
if ($event = $this->fireModelEvent('creating')) {
if ($event instanceof StoppableEventInterface && $event->isPropagationStopped()) {
return false;
}
}
// First we'll need to create a fresh query instance and touch the creation and

View File

@ -12,6 +12,8 @@ declare(strict_types=1);
namespace Hyperf\Database\Model;
use Psr\EventDispatcher\StoppableEventInterface;
trait SoftDeletes
{
/**
@ -42,7 +44,7 @@ trait SoftDeletes
$this->forceDeleting = false;
if ($deleted) {
$this->fireModelEvent('forceDeleted', false);
$this->fireModelEvent('forceDeleted');
}
});
}
@ -57,8 +59,10 @@ trait SoftDeletes
// If the restoring event does not return false, we will proceed with this
// restore operation. Otherwise, we bail out so the developer will stop
// the restore totally. We will clear the deleted timestamp and save.
if ($this->fireModelEvent('restoring') === false) {
return false;
if ($event = $this->fireModelEvent('restoring')) {
if ($event instanceof StoppableEventInterface && $event->isPropagationStopped()) {
return false;
}
}
$this->{$this->getDeletedAtColumn()} = null;
@ -70,7 +74,7 @@ trait SoftDeletes
$result = $this->save();
$this->fireModelEvent('restored', false);
$this->fireModelEvent('restored');
return $result;
}