Skip to content

Commit

Permalink
Propagate deletations and restoriations when using ModelTrait
Browse files Browse the repository at this point in the history
  • Loading branch information
pellaras committed Sep 25, 2018
1 parent 8b0c18e commit 2269286
Showing 1 changed file with 35 additions and 1 deletion.
36 changes: 35 additions & 1 deletion src/ModelObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function __construct(DynamoDbClientInterface $dynamoDb)
$this->attributeFilter = $dynamoDb->getAttributeFilter();
}

public function saved($model)
protected function _save($model)
{
$attrs = $model->attributesToArray();
// $this->attributeFilter->filter($attrs);
Expand All @@ -45,4 +45,38 @@ public function saved($model)
Log::info($e);
}
}

protected function _delete($model)
{
$key = [$model->getKeyName() => $model->getKey()];

try {
$this->dynamoDbClient->deleteItem([
'TableName' => $model->getDynamoDbTableName(),
'Key' => $this->marshaler->marshalItem($key),
]);
} catch (Exception $e) {
Log::info($e);
}
}

public function created($model)
{
$this->_save($model);
}

public function updated($model)
{
$this->_save($model);
}

public function deleted($model)
{
$this->_delete($model);
}

public function restored($model)
{
$this->_save($model);
}
}

0 comments on commit 2269286

Please sign in to comment.