diff --git a/src/Venturecraft/Revisionable/RevisionableTrait.php b/src/Venturecraft/Revisionable/RevisionableTrait.php index 0def63f2..bcdf487c 100644 --- a/src/Venturecraft/Revisionable/RevisionableTrait.php +++ b/src/Venturecraft/Revisionable/RevisionableTrait.php @@ -1,6 +1,8 @@ changedRevisionableFields(); $revisions = array(); - + $group_id = (string) Str::uuid(); foreach ($changes_to_record as $key => $change) { $original = array( 'revisionable_type' => $this->getMorphClass(), 'revisionable_id' => $this->getKey(), 'key' => $key, + 'group_id' => $group_id, 'old_value' => Arr::get($this->originalData, $key), 'new_value' => $this->updatedData[$key], 'user_id' => $this->getSystemUserId(), @@ -230,12 +233,14 @@ public function postCreate() return false; } + $group_id = (string) Str::uuid(); if ((!isset($this->revisionEnabled) || $this->revisionEnabled)) { $revisions[] = array( 'revisionable_type' => $this->getMorphClass(), 'revisionable_id' => $this->getKey(), 'key' => self::CREATED_AT, + 'group_id' => $group_id, 'old_value' => null, 'new_value' => $this->{self::CREATED_AT}, 'user_id' => $this->getSystemUserId(), @@ -259,6 +264,7 @@ public function postCreate() */ public function postDelete() { + $group_id = (string) Str::uuid(); if ((!isset($this->revisionEnabled) || $this->revisionEnabled) && $this->isSoftDelete() && $this->isRevisionable($this->getDeletedAtColumn()) @@ -267,6 +273,7 @@ public function postDelete() 'revisionable_type' => $this->getMorphClass(), 'revisionable_id' => $this->getKey(), 'key' => $this->getDeletedAtColumn(), + 'group_id' => $group_id, 'old_value' => null, 'new_value' => $this->{$this->getDeletedAtColumn()}, 'user_id' => $this->getSystemUserId(), @@ -293,7 +300,8 @@ public function postForceDelete() if (empty($this->revisionForceDeleteEnabled)) { return false; } - + + $group_id = (string) Str::uuid(); if ((!isset($this->revisionEnabled) || $this->revisionEnabled) && (($this->isSoftDelete() && $this->isForceDeleting()) || !$this->isSoftDelete())) { @@ -301,6 +309,7 @@ public function postForceDelete() 'revisionable_type' => $this->getMorphClass(), 'revisionable_id' => $this->getKey(), 'key' => self::CREATED_AT, + 'group_id' => $group_id, 'old_value' => $this->{self::CREATED_AT}, 'new_value' => null, 'user_id' => $this->getSystemUserId(), diff --git a/src/migrations/2013_04_09_062329_create_revisions_table.php b/src/migrations/2013_04_09_062329_create_revisions_table.php index 8d3d2d2a..65683b39 100644 --- a/src/migrations/2013_04_09_062329_create_revisions_table.php +++ b/src/migrations/2013_04_09_062329_create_revisions_table.php @@ -17,6 +17,7 @@ public function up() $table->unsignedBigInteger('revisionable_id'); $table->unsignedBigInteger('user_id')->nullable(); $table->string('key'); + $table->uuid('group_id')->nullable(); $table->text('old_value')->nullable(); $table->text('new_value')->nullable(); $table->timestamps();