Skip to content

Commit

Permalink
Incorporate bug fixes
Browse files Browse the repository at this point in the history
A bunch of changes based on testing. Toward #39.
  • Loading branch information
waldoj committed Jan 7, 2018
1 parent 71f4590 commit c85248e
Showing 1 changed file with 27 additions and 12 deletions.
39 changes: 27 additions & 12 deletions cron/summaries_new.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,7 @@
$bills = array();
while ($bill = mysql_fetch_array($result))
{
$tmp = array($bill['number'] => $bill['id']);
$bills[] = $tmp;
$bills[$bill{number}] = $bill['id'];
}
}

Expand All @@ -111,12 +110,12 @@
* Rename each field to something reasonable.
*/
$new_headers = array(
'number' => 'SUM_BILNO',
'doc_id' => 'SUMMARY_DOCID',
'type' => 'SUMMARY_TYPE',
'text' => 'SUMMARY_TEXT'
'number',
'doc_id',
'type',
'text'
);
foreach ($new_headers as $new => $old)
foreach ($new_headers as $old => $new)
{
$summary[$new] = $summary[$old];
unset($summary[$old]);
Expand All @@ -126,16 +125,16 @@
* Change the format of the bill number. In this file, the numeric portions are left-padded
* with zeros, so that e.g. HB1 is rendered as HB0001. Here we change them to e.g. HB1.
*/
$suffix = substr($bill['number'], 2, -1) + 0;
$bill['number'] = substr($bill['number'], 0, 2) . $suffix;
$suffix = substr($summary['number'], 2) + 0;
$summary['number'] = substr($summary['number'], 0, 2) . $suffix;


/*
* Before we proceed any farther, see if this record is either new or different than last
* time that we examined it.
*/
$hash = md5(serialize($summary));
$number = strtolower(trim($summary[0]));
$number = strtolower($bill['number']);

if ( isset($hashes[$number]) && ($hash == $hashes[$number]) )
{
Expand Down Expand Up @@ -187,13 +186,29 @@
$summary['text'] = substr($summary['text'], 0, -8);
}

# Put the data back into the database.
/*
* If we have any summary text, store it in the database.
*/
if (!empty($summary['text']))
{

/*
* Look up the bill ID for this bill number.
*/
$bill_id = $bills[strtolower($summary{number})];
if (is_empty($bill_id))
{
$log->put('Summary found for '. $summary['number']
. ', but we have no record of that bill.', 4);
continue;
}

/*
* Commit this to the database.
*/
$sql = 'UPDATE bills
SET summary="' . mysql_real_escape_string($summary['text']) . '"
WHERE id="' . $bills[$bill{number}] . '"
WHERE id="' . $bill_id . '"
AND session_id = ' . $session_id;
$result = mysql_query($sql);
if (!$result)
Expand Down

0 comments on commit c85248e

Please sign in to comment.