Allow generating page when a candidates.csv file doesn't exist

This commit is contained in:
2024-08-18 23:41:50 +10:00
parent 95b7228778
commit 1d012f5ff1

View File

@@ -27,23 +27,23 @@ if (isset($options['candidates-file'])) {
// Convert CSV into an array of dictionaries. Use the header as the key in the dictionary. // Convert CSV into an array of dictionaries. Use the header as the key in the dictionary.
$candidateData = []; $candidateData = [];
if (($handle = fopen($candidatesFile, "r")) !== FALSE) { if (file_exists($candidatesFile)) {
$headers = fgetcsv($handle); if (($handle = fopen($candidatesFile, "r")) !== FALSE) {
while (($data = fgetcsv($handle)) !== FALSE) { $headers = fgetcsv($handle);
$candidate = []; while (($data = fgetcsv($handle)) !== FALSE) {
foreach ($headers as $key => $value) { $candidate = [];
$candidate[$value] = $data[$key]; foreach ($headers as $key => $value) {
$candidate[$value] = $data[$key];
}
$candidateData[] = $candidate;
} }
$candidateData[] = $candidate; fclose($handle);
} else {
error_log('Error opening candidates file');
exit(1);
} }
fclose($handle);
} else { } else {
error_log('Error opening candidates file'); error_log("The specified candidates.csv file does not exist, will not show any candidates for " . $councilData["shortName"] . ".");
exit(1);
}
if (empty($candidateData)) {
error_log("Failed to load any candidates for " . $councilData['shortName']);
} }
if (isset($options['media-file'])) { if (isset($options['media-file'])) {