Skip to content

Commit

Permalink
Fixes problem with deleteOneChild and saveMany events
Browse files Browse the repository at this point in the history
  • Loading branch information
artstorm committed Aug 31, 2015
1 parent 9be4349 commit 4d38250
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 10 deletions.
15 changes: 7 additions & 8 deletions api/app/Extensions/Revisionable/ChangeloggableTrait.php
Expand Up @@ -162,7 +162,7 @@ public function postSaveMany($key, Collection $childModels)
}

if ((!isset($this->revisionEnabled) || $this->revisionEnabled)
&& (!$limitReached || $RevisionCleanup)
&& (!$limitReached || $revisionCleanup)
) {
$revisions = [];

Expand All @@ -171,30 +171,30 @@ public function postSaveMany($key, Collection $childModels)
// $changes_to_record = $this->changedRevisionableFields();
// foreach ($changes_to_record as $key => $change) {
foreach ($childModels as $model) {
$revisions[] = array(
$revisions[] = [
'revisionable_type' => get_class($this),
'revisionable_id' => $this->getKey(),
'key' => $key,
'old_value' => null,
'new_value' => $model->toArray(),
'new_value' => $model->toJson(),
'user_id' => $this->getUserId(),
'created_at' => new \DateTime(),
'updated_at' => new \DateTime(),
);
];
}

if (count($revisions) > 0) {
if ($limitReached && $RevisionCleanup) {
if ($limitReached && $revisionCleanup) {
$toDelete = $this->revisionHistory()->orderBy('id', 'asc')->limit(count($revisions))->get();
foreach ($toDelete as $delete) {
$delete->delete();
}
}

$revision = new Revision;
\DB::table($revision->getTable())->insert($revisions);
}
}

}

/**
Expand Down Expand Up @@ -287,7 +287,7 @@ public function postDeleteOneChild($key, $id)
];

$revision = new Revision;
\DB::table($revision->getTable())->insert($revisions);
\DB::table($revision->getTable())->insert($data);
}
}

Expand All @@ -306,7 +306,6 @@ protected function isRelationRevisionable($relation)

if (isset($this->dontKeepRevisionOf)) {
return !in_array($relation, $this->dontKeepRevisionOf);

}

return true;
Expand Down
4 changes: 2 additions & 2 deletions api/app/Http/Controllers/ChildEntityController.php
Expand Up @@ -224,7 +224,7 @@ public function deleteOne($id, $childId)
$model = $this->findParentEntity($id);
$childModel = $this->findOrFailChildEntity($childId, $model);

$this->delete($parent, $childModel);
$this->delete($model, $childModel);

return $this->getResponse()->noContent();
}
Expand Down Expand Up @@ -430,7 +430,7 @@ protected function delete(BaseModel $parent, BaseModel $childModel)

$childModel->delete();

$this->fireModelEvent('deletedOneChild', $parent, [$parent, $this->relationName, $childModels], false);
$this->fireModelEvent('deletedOneChild', $parent, [$parent, $this->relationName, $childModel], false);
}

/**
Expand Down

0 comments on commit 4d38250

Please sign in to comment.