protected function saveAuditTrail($action, $newAttributes, $oldAttributes, $entry_id, $user_id, $model, $model_id, $created)
{
// Build a list of fields to log
$rows = array();
foreach ($newAttributes as $field => $new) {
$old = isset($oldAttributes[$field]) ? $oldAttributes[$field] : '';
// If they are not the same lets write an audit log
if ($new != $old) {
$rows[] = [$entry_id, $user_id, $old, $new, $action, $model, $model_id, $field, $created];
}
}
// Record the field changes with a batch insert
if (!empty($rows)) {
$columns = ['entry_id', 'user_id', 'old_value', 'new_value', 'action', 'model', 'model_id', 'field', 'created'];
$audit = Audit::getInstance();
$audit->getDb()->createCommand()->batchInsert(AuditTrail::tableName(), $columns, $rows)->execute();
}
}