Skip to content

Commit

Permalink
fix: conditional checks were refined to work with the data structures…
Browse files Browse the repository at this point in the history
… of audits.
  • Loading branch information
sriramkanakam87 committed Oct 2, 2024
1 parent 2b3f5f5 commit 87363b3
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions app/Livewire/MoleculeHistoryTimeline.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,19 @@ public function getHistory()
$audit_data[$index]['event'] = $audit->getMetadata()['audit_event'];
$audit_data[$index]['created_at'] = date('Y/m/d', strtotime($audit->getMetadata()['audit_created_at']));

if (str_contains('.', array_keys($audit->old_values)[0])) {
$old_key = $audit->old_values ? explode('.', array_keys($audit->old_values)[0])[0] : null;
$new_key = $audit->new_values ? explode('.', array_keys($audit->new_values)[0])[0] : null;

$old_key = $old_key ?: $new_key;
$new_key = $new_key ?: $old_key;
$values = !empty($audit->old_values) ? $audit->old_values : $audit->new_values;
$first_affected_column = !empty($values) ? array_keys($values)[0] : null;

if (str_contains($first_affected_column, '.')) {
$affected_column = explode('.', $first_affected_column)[0];

$audit_data[$index]['affected_columns'][$affected_column]['old_value'] = $audit->old_values ? array_values($audit->old_values)[0] : null;
$audit_data[$index]['affected_columns'][$affected_column]['new_value'] = $audit->new_values ? array_values($audit->new_values)[0] : null;
} else {
foreach ($audit->getModified() as $key => $value) {
$audit_data[$index]['affected_columns'][$key]['old_value'] = $value['old'] ?: null;
$audit_data[$index]['affected_columns'][$key]['new_value'] = $value['new'] ?: null;
foreach ($audit->getModified() as $affected_column => $value) {

$audit_data[$index]['affected_columns'][$affected_column]['old_value'] = array_key_exists('old', $value) ? $value['old'] : null;
$audit_data[$index]['affected_columns'][$affected_column]['new_value'] = array_key_exists('new', $value) ? $value['new'] : null;
}
}
}
Expand All @@ -42,7 +45,6 @@ public function getHistory()

array_push($audit_data, $initial_audit);
$this->audit_data = $audit_data;
// dd($audit_data);
}

public function render()
Expand Down

0 comments on commit 87363b3

Please sign in to comment.