Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions src/Venturecraft/Revisionable/RevisionableTrait.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php namespace Venturecraft\Revisionable;

use Illuminate\Support\Arr;
use Illuminate\Support\Str;


/*
* This file is part of the Revisionable package by Venture Craft
Expand Down Expand Up @@ -186,12 +188,13 @@ public function postSave()
$changes_to_record = $this->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(),
Expand Down Expand Up @@ -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(),
Expand All @@ -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())
Expand All @@ -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(),
Expand All @@ -293,14 +300,16 @@ 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())) {

$revisions[] = array(
'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(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down