Skip to content

Commit

Permalink
Produce summary data to feed back into --table option
Browse files Browse the repository at this point in the history
  • Loading branch information
Nathan Nguyen committed Sep 20, 2024
1 parent cad0186 commit e036720
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
3 changes: 1 addition & 2 deletions classes/helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -330,8 +330,7 @@ public static function regular_expression_search(string $search, string $table,
if (!empty($stream)) {
if ($summary) {
fputcsv($stream, [
$table,
$column->name,
"$table:$column->name",
]);

// Return empty array to skip the rest of the function.
Expand Down
17 changes: 15 additions & 2 deletions cli/find.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,6 @@
// Show header.
if (!$options['summary']) {
fputcsv($fp, ['table', 'column', 'courseid', 'shortname', 'id', 'match']);
} else {
fputcsv($fp, ['table', 'column']);
}

// Perform the search.
Expand Down Expand Up @@ -146,5 +144,20 @@
}

$progress->update_full(100, "Finished searching into $output");

fclose($fp);

if ($summary) {
// Read the content of the output file.
$filecontent = file_get_contents($output);
// Replace new line with comma.
$filecontent = str_replace("\n", ',', $filecontent);
// Remove the last comma.
$filecontent = substr($filecontent, 0, -1);
// Add a new line at the end.
$filecontent .= "\n";
// Write the content back to the file.
file_put_contents($output, $filecontent);
}

exit(0);

0 comments on commit e036720

Please sign in to comment.