diff --git a/update_uad.php b/update_uad.php index ee04a58..4a013ef 100644 --- a/update_uad.php +++ b/update_uad.php @@ -1,39 +1,106 @@ $value) { + if ($value != $old_item[$key]) { + // These values aren't the same + // Print diff + print_diff($key, $old_item[$key], COLOR_RED); + print_diff($key, $value, COLOR_GREEN); + } else { + // Values are the same, print as is + print_diff($key, $value, null); + } + } + print(" }\n"); } } -# Save to dir -foreach ($new_list as $list_type => $list) { - usort($list, function ($o1, $o2) { - return $o1['id'] <=> $o2['id']; - }); - file_put_contents(__DIR__ . '/' . $list_type . '.json', json_encode($list, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT)); +// The remaining items in the old list are removed +foreach ($old_list as $item) { + if ($item['removal'] == 'Unsafe') { + // Exclude Unsafe items + continue; + } + // List this item as removed item. + print("\e[31m-{\e[0m\n"); + foreach ($item as $key => $value) { + print_diff($key, $value, null); + } + print("\e[31m-}\e[0m\n"); +} + +exit(0); + +function print_diff(string $key, string|array|null $value, ?int $color): void { + if ($color == COLOR_RED) { + $symbol = '-'; + $color_begin = "\e[31m"; + $color_end = "\e[0m"; + } else if ($color == COLOR_GREEN) { + $symbol = '+'; + $color_begin = "\e[32m"; + $color_end = "\e[0m"; + } else { + $symbol = ' '; + $color_begin = ''; + $color_end = ''; + } + if ($value == null) { + printf("$symbol$color_begin $key: null,$color_end"); + } else if (is_string($value)) { + printf("$symbol$color_begin $key: $value,$color_end"); + } else if (is_array($value)) { + printf("$symbol$color_begin $key: [$color_end"); + foreach ($value as $item) { + printf("$symbol$color_begin $item,$color_end"); + } + printf("$symbol$color_begin ],$color_end"); + } +} + +function find_in_old_list(string $id): ?array { + global $old_list; + $c = count($old_list); + for ($i = 0; $i < $c; ++$i) { + $item = $old_list[$i]; + if ($item['id'] == $id) { + array_splice($old_list, $i, 1); + return $item; + } + } + return null; } function get_removal(string $uad_removal): string { @@ -48,4 +115,4 @@ function get_removal(string $uad_removal): string { case "Unsafe": return "unsafe"; } -} \ No newline at end of file +}