mirror of
https://github.com/HDInnovations/UNIT3D-Community-Edition.git
synced 2026-02-06 11:38:52 -06:00
(Update) Audits Trait 🚀
- stop logging system actions
This commit is contained in:
@@ -145,21 +145,25 @@ trait Auditable
|
||||
*/
|
||||
protected static function registerCreate($model)
|
||||
{
|
||||
// Generate the JSON to store
|
||||
$data = self::generate('create', [], self::strip($model, $model->getAttributes()));
|
||||
// Get auth (if any)
|
||||
$userId = self::getUserId();
|
||||
// Store record
|
||||
$now = Carbon::now()->format('Y-m-d H:i:s');
|
||||
DB::table('audits')->insert([
|
||||
'user_id' => $userId,
|
||||
'model_name' => class_basename($model),
|
||||
'model_entry_id' => $model->{$model->getKeyName()},
|
||||
'action' => 'create',
|
||||
'record' => $data,
|
||||
'created_at' => $now,
|
||||
'updated_at' => $now,
|
||||
]);
|
||||
|
||||
if ($userId !== 1) {
|
||||
// Generate the JSON to store
|
||||
$data = self::generate('create', [], self::strip($model, $model->getAttributes()));
|
||||
|
||||
// Store record
|
||||
$now = Carbon::now()->format('Y-m-d H:i:s');
|
||||
DB::table('audits')->insert([
|
||||
'user_id' => $userId,
|
||||
'model_name' => class_basename($model),
|
||||
'model_entry_id' => $model->{$model->getKeyName()},
|
||||
'action' => 'create',
|
||||
'record' => $data,
|
||||
'created_at' => $now,
|
||||
'updated_at' => $now,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -169,22 +173,26 @@ trait Auditable
|
||||
*/
|
||||
protected static function registerUpdate($model)
|
||||
{
|
||||
// Strip data
|
||||
// Generate the JSON to store
|
||||
$data = self::generate('update', self::strip($model, $model->getOriginal()), self::strip($model, $model->getChanges()));
|
||||
// Get auth (if any)
|
||||
$userId = self::getUserId();
|
||||
// Store record
|
||||
$now = Carbon::now()->format('Y-m-d H:i:s');
|
||||
DB::table('audits')->insert([
|
||||
'user_id' => $userId,
|
||||
'model_name' => class_basename($model),
|
||||
'model_entry_id' => $model->{$model->getKeyName()},
|
||||
'action' => 'update',
|
||||
'record' => $data,
|
||||
'created_at' => $now,
|
||||
'updated_at' => $now,
|
||||
]);
|
||||
|
||||
if ($userId !== 1) {
|
||||
// Strip data
|
||||
// Generate the JSON to store
|
||||
$data = self::generate('update', self::strip($model, $model->getOriginal()), self::strip($model, $model->getChanges()));
|
||||
|
||||
// Store record
|
||||
$now = Carbon::now()->format('Y-m-d H:i:s');
|
||||
DB::table('audits')->insert([
|
||||
'user_id' => $userId,
|
||||
'model_name' => class_basename($model),
|
||||
'model_entry_id' => $model->{$model->getKeyName()},
|
||||
'action' => 'update',
|
||||
'record' => $data,
|
||||
'created_at' => $now,
|
||||
'updated_at' => $now,
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -194,20 +202,24 @@ trait Auditable
|
||||
*/
|
||||
protected static function registerDelete($model)
|
||||
{
|
||||
// Generate the JSON to store
|
||||
$data = self::generate('delete', self::strip($model, $model->getAttributes()));
|
||||
// Get auth (if any)
|
||||
$userId = self::getUserId();
|
||||
// Store record
|
||||
$now = Carbon::now()->format('Y-m-d H:i:s');
|
||||
DB::table('audits')->insert([
|
||||
'user_id' => $userId,
|
||||
'model_name' => class_basename($model),
|
||||
'model_entry_id' => $model->{$model->getKeyName()},
|
||||
'action' => 'delete',
|
||||
'record' => $data,
|
||||
'created_at' => $now,
|
||||
'updated_at' => $now,
|
||||
]);
|
||||
|
||||
if ($userId !== 1) {
|
||||
// Generate the JSON to store
|
||||
$data = self::generate('delete', self::strip($model, $model->getAttributes()));
|
||||
|
||||
// Store record
|
||||
$now = Carbon::now()->format('Y-m-d H:i:s');
|
||||
DB::table('audits')->insert([
|
||||
'user_id' => $userId,
|
||||
'model_name' => class_basename($model),
|
||||
'model_entry_id' => $model->{$model->getKeyName()},
|
||||
'action' => 'delete',
|
||||
'record' => $data,
|
||||
'created_at' => $now,
|
||||
'updated_at' => $now,
|
||||
]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user