diff --git a/utilities/update_legislators.php b/cron/legislators.php similarity index 71% rename from utilities/update_legislators.php rename to cron/legislators.php index cefec10..544b8ae 100644 --- a/utilities/update_legislators.php +++ b/cron/legislators.php @@ -1,17 +1,5 @@ now() ORDER BY chamber ASC'; -$stmt = $db->prepare($sql); +$stmt = $dbh->prepare($sql); $stmt->execute(); $known_legislators = $stmt->fetchAll(PDO::FETCH_OBJ); foreach ($known_legislators as &$known_legislator) @@ -37,7 +25,11 @@ } } -echo '

Loaded ' . count($known_legislators) . ' from local database.

'; +$log->put('Loaded ' . count($known_legislators) . ' from local database.', 1); +if (count($known_legislators) > 140) +{ + $log->put('There are ' . count($known_legislators) . ' legislators in the database—too many.', 5); +} /* * Get senators. Their Senate ID (e.g., "S100") is the key, their name is the value. @@ -54,7 +46,7 @@ $senators = $tmp; unset($tmp); -echo '

Retrieved ' . count($senators) . ' senators from senate.virginia.gov.

'; +$log->put('Retrieved ' . count($senators) . ' senators from senate.virginia.gov.', 1); /* * Get delegates. Their House ID (e.g., "H0200") is the key, their name is the value. @@ -71,7 +63,7 @@ $delegates = $tmp; unset($tmp); -echo '

Retrieved ' . count($delegates) . ' delegates from virginiageneralassembly.gov.

'; +$log->put('Retrieved ' . count($delegates) . ' delegates from virginiageneralassembly.gov.', 1); /* * First see if we have records of any representatives that are not currently in office. @@ -88,7 +80,7 @@ { if (!isset($senators[$id])) { - echo '
  • Remove Sen. ' . $known_legislator->name . '
  • '; + $log->put('Error: Sen. ' . $known_legislator->name . ' is no longer in office, but is still listed in the database.', 5); } } @@ -99,7 +91,7 @@ { if (!isset($delegates[$id])) { - echo '
  • Remove Del. ' . $known_legislator->name . '
  • '; + $log->put('Error: Del. ' . $known_legislator->name . ' is no longer in office, but is still listed in the database.', 5); } } @@ -126,8 +118,7 @@ if ($match == FALSE) { - echo '
  • Add ' . $name . '
  • '; + $log->put('Senator missing from the database: ' . $name . ' (http://apps.senate.virginia.gov/Senator/memberpage.php?id=' . $lis_id . ')', 6); } } @@ -150,8 +141,7 @@ if ($match == FALSE) { - echo '
  • Add ' . $name . '
  • '; + $log->put('Delegate missing from the database: ' . $name . ' (http://virginiageneralassembly.gov/house/members/members.php?id='. $lis_id . ')', 6); } } diff --git a/cron/update.php b/cron/update.php index e9c9f4d..3686481 100644 --- a/cron/update.php +++ b/cron/update.php @@ -156,6 +156,12 @@ require 'cleanup.php'; } +# Check for missing / excess legislators. +if ($type == 'legislators') +{ + require 'legislators.php'; +} + # Run cache.php, which has a bunch of functions that preemptively load data into the in-memory # cache. if (($type == 'all') || ($type == 'cache'))