@@ -10,18 +10,18 @@ |
||
10 | 10 | order by hdate, hpos'); |
11 | 11 | $last = array('hdate'=>''); |
12 | 12 | for ($i=0; $i<$q->rows(); $i++) { |
13 | - $row = array( |
|
14 | - 'atime' => $q->field($i, 'atime'), |
|
15 | - 'hdate' => $q->field($i, 'hdate'), |
|
16 | - 'gid' => $q->field($i, 'gid'), |
|
17 | - 'hpos' => $q->field($i, 'hpos') |
|
18 | - ); |
|
19 | - if ($row['hdate'] != $last['hdate']) |
|
20 | - $last = array(); |
|
21 | - if ($last && $row['atime'] < $last['atime']-5) { |
|
22 | - print "PROBLEM; current row is $row[gid] $row[hdate] $row[atime]\n"; |
|
23 | - print " Last was $last[gid] $last[hdate] $last[atime]\n"; |
|
24 | - } |
|
25 | - $last = $row; |
|
13 | + $row = array( |
|
14 | + 'atime' => $q->field($i, 'atime'), |
|
15 | + 'hdate' => $q->field($i, 'hdate'), |
|
16 | + 'gid' => $q->field($i, 'gid'), |
|
17 | + 'hpos' => $q->field($i, 'hpos') |
|
18 | + ); |
|
19 | + if ($row['hdate'] != $last['hdate']) |
|
20 | + $last = array(); |
|
21 | + if ($last && $row['atime'] < $last['atime']-5) { |
|
22 | + print "PROBLEM; current row is $row[gid] $row[hdate] $row[atime]\n"; |
|
23 | + print " Last was $last[gid] $last[hdate] $last[atime]\n"; |
|
24 | + } |
|
25 | + $last = $row; |
|
26 | 26 | } |
27 | 27 |
@@ -9,7 +9,7 @@ discard block |
||
9 | 9 | and (user_id is null or user_id != -1) and deleted=0 |
10 | 10 | order by hdate, hpos'); |
11 | 11 | $last = array('hdate'=>''); |
12 | -for ($i=0; $i<$q->rows(); $i++) { |
|
12 | +for ($i = 0; $i < $q->rows(); $i++) { |
|
13 | 13 | $row = array( |
14 | 14 | 'atime' => $q->field($i, 'atime'), |
15 | 15 | 'hdate' => $q->field($i, 'hdate'), |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | ); |
19 | 19 | if ($row['hdate'] != $last['hdate']) |
20 | 20 | $last = array(); |
21 | - if ($last && $row['atime'] < $last['atime']-5) { |
|
21 | + if ($last && $row['atime'] < $last['atime'] - 5) { |
|
22 | 22 | print "PROBLEM; current row is $row[gid] $row[hdate] $row[atime]\n"; |
23 | 23 | print " Last was $last[gid] $last[hdate] $last[atime]\n"; |
24 | 24 | } |
@@ -16,8 +16,9 @@ |
||
16 | 16 | 'gid' => $q->field($i, 'gid'), |
17 | 17 | 'hpos' => $q->field($i, 'hpos') |
18 | 18 | ); |
19 | - if ($row['hdate'] != $last['hdate']) |
|
20 | - $last = array(); |
|
19 | + if ($row['hdate'] != $last['hdate']) { |
|
20 | + $last = array(); |
|
21 | + } |
|
21 | 22 | if ($last && $row['atime'] < $last['atime']-5) { |
22 | 23 | print "PROBLEM; current row is $row[gid] $row[hdate] $row[atime]\n"; |
23 | 24 | print " Last was $last[gid] $last[hdate] $last[atime]\n"; |
@@ -52,7 +52,9 @@ |
||
52 | 52 | <br><small style='color:#666'>$reason</small> |
53 | 53 | "; |
54 | 54 | } |
55 | -if (!$out) exit; |
|
55 | +if (!$out) { |
|
56 | + exit; |
|
57 | +} |
|
56 | 58 | |
57 | 59 | $headers = |
58 | 60 | "From: TheyWorkForYou <" . CONTACTEMAIL . ">\r\n" . |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | '); |
23 | 23 | |
24 | 24 | $keys = array(); |
25 | -for ($i=0; $i<$q->rows(); $i++) { |
|
25 | +for ($i = 0; $i < $q->rows(); $i++) { |
|
26 | 26 | $keys[] = $q->field($i, 'api_key'); |
27 | 27 | } |
28 | 28 | $keys = join("','", $keys); |
@@ -34,18 +34,18 @@ discard block |
||
34 | 34 | GROUP BY api_key |
35 | 35 | "); |
36 | 36 | $summary = array(); |
37 | -for ($i=0; $i<$q2->rows(); $i++) { |
|
37 | +for ($i = 0; $i < $q2->rows(); $i++) { |
|
38 | 38 | $row = $q2->row($i); |
39 | 39 | $summary[$row['api_key']] = array($row['first_use'], $row['count']); |
40 | 40 | } |
41 | 41 | |
42 | 42 | $out = ''; |
43 | -for ($i=0; $i<$q->rows(); $i++) { |
|
43 | +for ($i = 0; $i < $q->rows(); $i++) { |
|
44 | 44 | $row = $q->row($i); |
45 | 45 | $reason = preg_replace("/\r?\n/", ' ', $row['reason']); |
46 | - $comm = $row['commercial']==1 ? ', commercial' : ''; |
|
47 | - $ipa = $row['ip_addresses']!=1 ? 'es' : ''; |
|
48 | - $hp = $row['count']!=1 ? 's' : ''; |
|
46 | + $comm = $row['commercial'] == 1 ? ', commercial' : ''; |
|
47 | + $ipa = $row['ip_addresses'] != 1 ? 'es' : ''; |
|
48 | + $hp = $row['count'] != 1 ? 's' : ''; |
|
49 | 49 | list($first, $total) = $summary[$row['api_key']]; |
50 | 50 | $out .= "<p><b>$row[count] hit$hp, from $row[ip_addresses] IP address$ipa.</b> $row[firstname] $row[lastname] <$row[email]> |
51 | 51 | <br>$row[api_key], created $row[created], first use $first$comm, total calls $total |
@@ -61,5 +61,5 @@ discard block |
||
61 | 61 | "Content-Transfer-Encoding: 8bit\r\n"; |
62 | 62 | $subject = 'Daily TheyWorkForYou API usage'; |
63 | 63 | $to = join(chr(64), array('commercial', 'mysociety.org')); |
64 | -mail ($to, $subject, $out, $headers); |
|
64 | +mail($to, $subject, $out, $headers); |
|
65 | 65 |
@@ -10,7 +10,7 @@ discard block |
||
10 | 10 | |
11 | 11 | # Done directly as storing everything in an array as $db->query() does runs out of memory, unsurprisingly |
12 | 12 | $q = mysql_query( |
13 | - 'select section.body, gid, yes_votes, no_votes |
|
13 | + 'select section.body, gid, yes_votes, no_votes |
|
14 | 14 | from hansard |
15 | 15 | inner join epobject as section on hansard.section_id = section.epobject_id |
16 | 16 | left join anonvotes on hansard.epobject_id = anonvotes.epobject_id |
@@ -24,34 +24,34 @@ discard block |
||
24 | 24 | |
25 | 25 | $votes = array(); |
26 | 26 | while ($row = mysql_fetch_assoc($q)) { |
27 | - $dept = $row['body']; |
|
28 | - if (!isset($votes[$dept])) $votes[$dept] = array( |
|
29 | - 'verymoreyes'=>0, 'moreyes'=>0, 'verymoreno'=>0, 'moreno'=>0, 'same'=>0, 'none'=>0 |
|
30 | - ); |
|
31 | - $yes = $row['yes_votes']; |
|
32 | - $no = $row['no_votes']; |
|
33 | - $gid = $row['gid']; |
|
34 | - if (is_null($yes)) { |
|
35 | - $votes[$dept]['none']++; |
|
36 | - } else { |
|
37 | - if ($no > $yes+10) { |
|
38 | - $votes[$dept]['verymoreno']++; |
|
39 | - } elseif ($no > $yes) { |
|
40 | - $votes[$dept]['moreno']++; |
|
41 | - } elseif ($no + 10 < $yes) { |
|
42 | - $votes[$dept]['verymoreyes']++; |
|
43 | - } elseif ($no < $yes) { |
|
44 | - $votes[$dept]['moreyes']++; |
|
45 | - } else { |
|
46 | - $votes[$dept]['same']++; |
|
47 | - } |
|
48 | - } |
|
27 | + $dept = $row['body']; |
|
28 | + if (!isset($votes[$dept])) $votes[$dept] = array( |
|
29 | + 'verymoreyes'=>0, 'moreyes'=>0, 'verymoreno'=>0, 'moreno'=>0, 'same'=>0, 'none'=>0 |
|
30 | + ); |
|
31 | + $yes = $row['yes_votes']; |
|
32 | + $no = $row['no_votes']; |
|
33 | + $gid = $row['gid']; |
|
34 | + if (is_null($yes)) { |
|
35 | + $votes[$dept]['none']++; |
|
36 | + } else { |
|
37 | + if ($no > $yes+10) { |
|
38 | + $votes[$dept]['verymoreno']++; |
|
39 | + } elseif ($no > $yes) { |
|
40 | + $votes[$dept]['moreno']++; |
|
41 | + } elseif ($no + 10 < $yes) { |
|
42 | + $votes[$dept]['verymoreyes']++; |
|
43 | + } elseif ($no < $yes) { |
|
44 | + $votes[$dept]['moreyes']++; |
|
45 | + } else { |
|
46 | + $votes[$dept]['same']++; |
|
47 | + } |
|
48 | + } |
|
49 | 49 | } |
50 | 50 | |
51 | 51 | print "Department,11+ more yes votes than no,1-10 more yes votes than no,11+ more no votes than yes,1-10 more no votes than yes,Same votes yes/no,No votes\n"; |
52 | 52 | foreach ($votes as $dept => $v) { |
53 | - #if (!$v['moreyes'] && !$v['moreno'] && !$v['same']) continue; |
|
54 | - if (strstr($dept, ',')) |
|
55 | - $dept = "\"$dept\""; |
|
56 | - print "$dept,$v[verymoreyes],$v[moreyes],$v[verymoreno],$v[moreno],$v[same],$v[none]\n"; |
|
53 | + #if (!$v['moreyes'] && !$v['moreno'] && !$v['same']) continue; |
|
54 | + if (strstr($dept, ',')) |
|
55 | + $dept = "\"$dept\""; |
|
56 | + print "$dept,$v[verymoreyes],$v[moreyes],$v[verymoreno],$v[moreno],$v[same],$v[none]\n"; |
|
57 | 57 | } |
@@ -34,7 +34,7 @@ |
||
34 | 34 | if (is_null($yes)) { |
35 | 35 | $votes[$dept]['none']++; |
36 | 36 | } else { |
37 | - if ($no > $yes+10) { |
|
37 | + if ($no > $yes + 10) { |
|
38 | 38 | $votes[$dept]['verymoreno']++; |
39 | 39 | } elseif ($no > $yes) { |
40 | 40 | $votes[$dept]['moreno']++; |
@@ -25,9 +25,11 @@ discard block |
||
25 | 25 | $votes = array(); |
26 | 26 | while ($row = mysql_fetch_assoc($q)) { |
27 | 27 | $dept = $row['body']; |
28 | - if (!isset($votes[$dept])) $votes[$dept] = array( |
|
28 | + if (!isset($votes[$dept])) { |
|
29 | + $votes[$dept] = array( |
|
29 | 30 | 'verymoreyes'=>0, 'moreyes'=>0, 'verymoreno'=>0, 'moreno'=>0, 'same'=>0, 'none'=>0 |
30 | 31 | ); |
32 | + } |
|
31 | 33 | $yes = $row['yes_votes']; |
32 | 34 | $no = $row['no_votes']; |
33 | 35 | $gid = $row['gid']; |
@@ -51,7 +53,8 @@ discard block |
||
51 | 53 | print "Department,11+ more yes votes than no,1-10 more yes votes than no,11+ more no votes than yes,1-10 more no votes than yes,Same votes yes/no,No votes\n"; |
52 | 54 | foreach ($votes as $dept => $v) { |
53 | 55 | #if (!$v['moreyes'] && !$v['moreno'] && !$v['same']) continue; |
54 | - if (strstr($dept, ',')) |
|
55 | - $dept = "\"$dept\""; |
|
56 | + if (strstr($dept, ',')) { |
|
57 | + $dept = "\"$dept\""; |
|
58 | + } |
|
56 | 59 | print "$dept,$v[verymoreyes],$v[moreyes],$v[verymoreno],$v[moreno],$v[same],$v[none]\n"; |
57 | 60 | } |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | */ |
7 | 7 | |
8 | 8 | function mlog($message) { |
9 | - print $message; |
|
9 | + print $message; |
|
10 | 10 | } |
11 | 11 | |
12 | 12 | include_once '../www/includes/easyparliament/init.php'; |
@@ -24,9 +24,9 @@ discard block |
||
24 | 24 | # Last sent is timestamp of last alerts gone out. |
25 | 25 | # Last batch is the search index batch number last alert went out to. |
26 | 26 | if (is_file('alerts-lastsent')) |
27 | - $lastsent = file('alerts-lastsent'); |
|
27 | + $lastsent = file('alerts-lastsent'); |
|
28 | 28 | else |
29 | - $lastsent = array('', 0); |
|
29 | + $lastsent = array('', 0); |
|
30 | 30 | |
31 | 31 | $lastupdated = trim($lastsent[0]); |
32 | 32 | if (!$lastupdated) $lastupdated = strtotime('00:00 today'); |
@@ -38,13 +38,13 @@ discard block |
||
38 | 38 | # have been made since last time we ran |
39 | 39 | $batch_query_fragment = ""; |
40 | 40 | for ($i=$lastbatch + 1; $i <= $max_batch_id; $i++) { |
41 | - $batch_query_fragment .= "batch:$i "; |
|
41 | + $batch_query_fragment .= "batch:$i "; |
|
42 | 42 | } |
43 | 43 | $batch_query_fragment = trim($batch_query_fragment); |
44 | 44 | mlog("batch_query_fragment: " . $batch_query_fragment . "\n"); |
45 | 45 | |
46 | 46 | if (!$batch_query_fragment) { |
47 | - mlog("No new batches since last run - nothing to run over!"); |
|
47 | + mlog("No new batches since last run - nothing to run over!"); |
|
48 | 48 | exit; |
49 | 49 | } |
50 | 50 | |
@@ -56,28 +56,28 @@ discard block |
||
56 | 56 | $toemail = ''; |
57 | 57 | $template = 'alert_mailout'; |
58 | 58 | for ($k=1; $k<$argc; $k++) { |
59 | - if ($argv[$k] == '--nomail') |
|
60 | - $nomail = true; |
|
61 | - if (preg_match('#^--only=(.*)$#', $argv[$k], $m)) |
|
62 | - $onlyemail = $m[1]; |
|
63 | - if (preg_match('#^--from=(.*)$#', $argv[$k], $m)) |
|
64 | - $fromemail = $m[1]; |
|
65 | - if (preg_match('#^--to=(.*)$#', $argv[$k], $m)) |
|
66 | - $toemail = $m[1]; |
|
67 | - if (preg_match('#^--template=(.*)$#', $argv[$k], $m)) { |
|
68 | - $template = $m[1]; |
|
69 | - # Tee hee |
|
70 | - $template = "../../../../../../../../../../home/twfy-live/email-alert-templates/alert_mailout_$template"; |
|
71 | - } |
|
59 | + if ($argv[$k] == '--nomail') |
|
60 | + $nomail = true; |
|
61 | + if (preg_match('#^--only=(.*)$#', $argv[$k], $m)) |
|
62 | + $onlyemail = $m[1]; |
|
63 | + if (preg_match('#^--from=(.*)$#', $argv[$k], $m)) |
|
64 | + $fromemail = $m[1]; |
|
65 | + if (preg_match('#^--to=(.*)$#', $argv[$k], $m)) |
|
66 | + $toemail = $m[1]; |
|
67 | + if (preg_match('#^--template=(.*)$#', $argv[$k], $m)) { |
|
68 | + $template = $m[1]; |
|
69 | + # Tee hee |
|
70 | + $template = "../../../../../../../../../../home/twfy-live/email-alert-templates/alert_mailout_$template"; |
|
71 | + } |
|
72 | 72 | } |
73 | 73 | |
74 | 74 | if (DEVSITE) |
75 | - $nomail = true; |
|
75 | + $nomail = true; |
|
76 | 76 | |
77 | 77 | if ($nomail) mlog("NOT SENDING EMAIL\n"); |
78 | 78 | if (($fromemail && $onlyemail) || ($toemail && $onlyemail)) { |
79 | - mlog("Can't have both from/to and only!\n"); |
|
80 | - exit; |
|
79 | + mlog("Can't have both from/to and only!\n"); |
|
80 | + exit; |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | $active = 0; |
@@ -140,142 +140,142 @@ discard block |
||
140 | 140 | $outof = count($alertdata); |
141 | 141 | $start_time = time(); |
142 | 142 | foreach ($alertdata as $alertitem) { |
143 | - $active++; |
|
144 | - $email = $alertitem['email']; |
|
145 | - if ($onlyemail && $email != $onlyemail) continue; |
|
146 | - if ($fromemail && strtolower($email) == $fromemail) $fromflag = true; |
|
147 | - if ($fromemail && !$fromflag) continue; |
|
148 | - if ($toemail && strtolower($email) >= $toemail) continue; |
|
149 | - $criteria_raw = $alertitem['criteria']; |
|
150 | - if (preg_match('#\bOR\b#', $criteria_raw)) { |
|
151 | - $criteria_raw = "($criteria_raw)"; |
|
152 | - } |
|
153 | - $criteria_batch = $criteria_raw . " " . $batch_query_fragment; |
|
154 | - |
|
155 | - if ($email != $current['email']) { |
|
156 | - if ($email_text) |
|
157 | - write_and_send_email($current, $email_text, $template); |
|
158 | - $current['email'] = $email; |
|
159 | - $current['token'] = $alertitem['alert_id'] . '-' . $alertitem['registrationtoken']; |
|
160 | - $email_text = ''; |
|
161 | - $q = $db->query('SELECT user_id FROM users WHERE email = :email', array( |
|
143 | + $active++; |
|
144 | + $email = $alertitem['email']; |
|
145 | + if ($onlyemail && $email != $onlyemail) continue; |
|
146 | + if ($fromemail && strtolower($email) == $fromemail) $fromflag = true; |
|
147 | + if ($fromemail && !$fromflag) continue; |
|
148 | + if ($toemail && strtolower($email) >= $toemail) continue; |
|
149 | + $criteria_raw = $alertitem['criteria']; |
|
150 | + if (preg_match('#\bOR\b#', $criteria_raw)) { |
|
151 | + $criteria_raw = "($criteria_raw)"; |
|
152 | + } |
|
153 | + $criteria_batch = $criteria_raw . " " . $batch_query_fragment; |
|
154 | + |
|
155 | + if ($email != $current['email']) { |
|
156 | + if ($email_text) |
|
157 | + write_and_send_email($current, $email_text, $template); |
|
158 | + $current['email'] = $email; |
|
159 | + $current['token'] = $alertitem['alert_id'] . '-' . $alertitem['registrationtoken']; |
|
160 | + $email_text = ''; |
|
161 | + $q = $db->query('SELECT user_id FROM users WHERE email = :email', array( |
|
162 | 162 | ':email' => $email |
163 | 163 | )); |
164 | - if ($q->rows() > 0) { |
|
165 | - $user_id = $q->field(0, 'user_id'); |
|
166 | - $registered++; |
|
167 | - } else { |
|
168 | - $user_id = 0; |
|
169 | - $unregistered++; |
|
170 | - } |
|
171 | - mlog("\nEMAIL: $email, uid $user_id; memory usage : ".memory_get_usage()."\n"); |
|
172 | - } |
|
173 | - |
|
174 | - $data = null; |
|
175 | - if (!isset($results[$criteria_batch])) { |
|
176 | - mlog(" ALERT $active/$outof QUERY $queries : Xapian query '$criteria_batch'"); |
|
177 | - $start = getmicrotime(); |
|
178 | - $SEARCHENGINE = new SEARCHENGINE($criteria_batch); |
|
179 | - #mlog("query_remade: " . $SEARCHENGINE->query_remade() . "\n"); |
|
180 | - $args = array( |
|
181 | - 's' => $criteria_raw, # Note: use raw here for URLs, whereas search engine has batch |
|
182 | - 'threshold' => $lastupdated, # Return everything added since last time this script was run |
|
183 | - 'o' => 'c', |
|
184 | - 'num' => 1000, // this is limited to 1000 in hansardlist.php anyway |
|
185 | - 'pop' => 1, |
|
186 | - 'e' => 1 # Don't escape ampersands |
|
187 | - ); |
|
188 | - $data = $DEBATELIST->_get_data_by_search($args); |
|
189 | - # add to cache (but only for speaker queries, which are commonly repeated) |
|
190 | - # Don't cache, it's very quick, and we'd prefer low memory usage |
|
191 | - #if (preg_match('#^speaker:\d+$#', $criteria_raw, $m)) { |
|
192 | - # mlog(", caching"); |
|
193 | - # $results[$criteria_batch] = $data; |
|
194 | - #} |
|
195 | - # unset($SEARCHENGINE); |
|
196 | - $total_results = $data['info']['total_results']; |
|
197 | - $queries++; |
|
198 | - mlog(", hits ".$total_results.", time ".(getmicrotime()-$start)."\n"); |
|
199 | - } else { |
|
200 | - mlog(" ACTION $active/$outof CACHE HIT : Using cached result for '$criteria_batch'\n"); |
|
201 | - $data = $results[$criteria_batch]; |
|
202 | - } |
|
203 | - |
|
204 | - if (isset($data['rows']) && count($data['rows']) > 0) { |
|
205 | - usort($data['rows'], 'sort_by_stuff'); # Sort results into order, by major, then date, then hpos |
|
206 | - $o = array(); $major = 0; $count = array(); $total = 0; |
|
207 | - $any_content = false; |
|
208 | - foreach ($data['rows'] as $row) { |
|
209 | - if ($major !== $row['major']) { |
|
210 | - $count[$major] = $total; $total = 0; |
|
211 | - $major = $row['major']; |
|
212 | - $o[$major] = ''; |
|
213 | - $k = 3; |
|
214 | - } |
|
215 | - #mlog($row['major'] . " " . $row['gid'] ."\n"); |
|
216 | - |
|
217 | - # Due to database server failure and restoring from day |
|
218 | - # old backup, 17th January 2012 is being newly |
|
219 | - # inserted, but has already been alerted upon. So |
|
220 | - # manually now stop anything from before 18th January |
|
221 | - # 2012 from sending an email alert again. |
|
222 | - if ($row['hdate'] < '2012-01-18') continue; |
|
223 | - |
|
224 | - $q = $db->query('SELECT gid_from FROM gidredirect WHERE gid_to = :gid_to', array( |
|
164 | + if ($q->rows() > 0) { |
|
165 | + $user_id = $q->field(0, 'user_id'); |
|
166 | + $registered++; |
|
167 | + } else { |
|
168 | + $user_id = 0; |
|
169 | + $unregistered++; |
|
170 | + } |
|
171 | + mlog("\nEMAIL: $email, uid $user_id; memory usage : ".memory_get_usage()."\n"); |
|
172 | + } |
|
173 | + |
|
174 | + $data = null; |
|
175 | + if (!isset($results[$criteria_batch])) { |
|
176 | + mlog(" ALERT $active/$outof QUERY $queries : Xapian query '$criteria_batch'"); |
|
177 | + $start = getmicrotime(); |
|
178 | + $SEARCHENGINE = new SEARCHENGINE($criteria_batch); |
|
179 | + #mlog("query_remade: " . $SEARCHENGINE->query_remade() . "\n"); |
|
180 | + $args = array( |
|
181 | + 's' => $criteria_raw, # Note: use raw here for URLs, whereas search engine has batch |
|
182 | + 'threshold' => $lastupdated, # Return everything added since last time this script was run |
|
183 | + 'o' => 'c', |
|
184 | + 'num' => 1000, // this is limited to 1000 in hansardlist.php anyway |
|
185 | + 'pop' => 1, |
|
186 | + 'e' => 1 # Don't escape ampersands |
|
187 | + ); |
|
188 | + $data = $DEBATELIST->_get_data_by_search($args); |
|
189 | + # add to cache (but only for speaker queries, which are commonly repeated) |
|
190 | + # Don't cache, it's very quick, and we'd prefer low memory usage |
|
191 | + #if (preg_match('#^speaker:\d+$#', $criteria_raw, $m)) { |
|
192 | + # mlog(", caching"); |
|
193 | + # $results[$criteria_batch] = $data; |
|
194 | + #} |
|
195 | + # unset($SEARCHENGINE); |
|
196 | + $total_results = $data['info']['total_results']; |
|
197 | + $queries++; |
|
198 | + mlog(", hits ".$total_results.", time ".(getmicrotime()-$start)."\n"); |
|
199 | + } else { |
|
200 | + mlog(" ACTION $active/$outof CACHE HIT : Using cached result for '$criteria_batch'\n"); |
|
201 | + $data = $results[$criteria_batch]; |
|
202 | + } |
|
203 | + |
|
204 | + if (isset($data['rows']) && count($data['rows']) > 0) { |
|
205 | + usort($data['rows'], 'sort_by_stuff'); # Sort results into order, by major, then date, then hpos |
|
206 | + $o = array(); $major = 0; $count = array(); $total = 0; |
|
207 | + $any_content = false; |
|
208 | + foreach ($data['rows'] as $row) { |
|
209 | + if ($major !== $row['major']) { |
|
210 | + $count[$major] = $total; $total = 0; |
|
211 | + $major = $row['major']; |
|
212 | + $o[$major] = ''; |
|
213 | + $k = 3; |
|
214 | + } |
|
215 | + #mlog($row['major'] . " " . $row['gid'] ."\n"); |
|
216 | + |
|
217 | + # Due to database server failure and restoring from day |
|
218 | + # old backup, 17th January 2012 is being newly |
|
219 | + # inserted, but has already been alerted upon. So |
|
220 | + # manually now stop anything from before 18th January |
|
221 | + # 2012 from sending an email alert again. |
|
222 | + if ($row['hdate'] < '2012-01-18') continue; |
|
223 | + |
|
224 | + $q = $db->query('SELECT gid_from FROM gidredirect WHERE gid_to = :gid_to', array( |
|
225 | 225 | ':gid_to' => 'uk.org.publicwhip/' . $sects_gid[$major] . '/' . $row['gid'] |
226 | 226 | )); |
227 | - if ($q->rows() > 0) continue; |
|
228 | - --$k; |
|
229 | - if ($k>=0) { |
|
230 | - $any_content = true; |
|
231 | - $parentbody = text_html_to_email($row['parent']['body']); |
|
232 | - $body = text_html_to_email($row['extract']); |
|
233 | - if (isset($row['speaker']) && count($row['speaker'])) $body = $row['speaker']['name'] . ': ' . $body; |
|
234 | - |
|
235 | - $body = wordwrap($body, 72); |
|
236 | - $o[$major] .= $parentbody . ' (' . format_date($row['hdate'], SHORTDATEFORMAT) . ")\nhttps://www.theyworkforyou.com" . $row['listurl'] . "\n"; |
|
237 | - $o[$major] .= $body . "\n\n"; |
|
238 | - } |
|
239 | - $total++; |
|
240 | - } |
|
241 | - $count[$major] = $total; |
|
242 | - |
|
243 | - if ($any_content) { |
|
244 | - # Add data to email_text |
|
245 | - $desc = trim(html_entity_decode($data['searchdescription'])); |
|
246 | - $desc = trim(preg_replace('#\(?B\d+( OR B\d+)*\)?\s*#', '', $desc)); |
|
247 | - foreach ($o as $major => $body) { |
|
248 | - if ($body) { |
|
249 | - $heading = $desc . ' : ' . $count[$major] . ' ' . $sects[$major] . ($count[$major]!=1?'s':''); |
|
250 | - $email_text .= "$heading\n".str_repeat('=',strlen($heading))."\n\n"; |
|
251 | - if ($count[$major] > 3) { |
|
252 | - $email_text .= "There are more results than we have shown here. See more:\nhttps://www.theyworkforyou.com/search/?s=".urlencode($criteria_raw)."+section:".$sects_search[$major]."&o=d\n\n"; |
|
253 | - } |
|
254 | - $email_text .= $body; |
|
255 | - } |
|
256 | - } |
|
257 | - } |
|
258 | - } |
|
227 | + if ($q->rows() > 0) continue; |
|
228 | + --$k; |
|
229 | + if ($k>=0) { |
|
230 | + $any_content = true; |
|
231 | + $parentbody = text_html_to_email($row['parent']['body']); |
|
232 | + $body = text_html_to_email($row['extract']); |
|
233 | + if (isset($row['speaker']) && count($row['speaker'])) $body = $row['speaker']['name'] . ': ' . $body; |
|
234 | + |
|
235 | + $body = wordwrap($body, 72); |
|
236 | + $o[$major] .= $parentbody . ' (' . format_date($row['hdate'], SHORTDATEFORMAT) . ")\nhttps://www.theyworkforyou.com" . $row['listurl'] . "\n"; |
|
237 | + $o[$major] .= $body . "\n\n"; |
|
238 | + } |
|
239 | + $total++; |
|
240 | + } |
|
241 | + $count[$major] = $total; |
|
242 | + |
|
243 | + if ($any_content) { |
|
244 | + # Add data to email_text |
|
245 | + $desc = trim(html_entity_decode($data['searchdescription'])); |
|
246 | + $desc = trim(preg_replace('#\(?B\d+( OR B\d+)*\)?\s*#', '', $desc)); |
|
247 | + foreach ($o as $major => $body) { |
|
248 | + if ($body) { |
|
249 | + $heading = $desc . ' : ' . $count[$major] . ' ' . $sects[$major] . ($count[$major]!=1?'s':''); |
|
250 | + $email_text .= "$heading\n".str_repeat('=',strlen($heading))."\n\n"; |
|
251 | + if ($count[$major] > 3) { |
|
252 | + $email_text .= "There are more results than we have shown here. See more:\nhttps://www.theyworkforyou.com/search/?s=".urlencode($criteria_raw)."+section:".$sects_search[$major]."&o=d\n\n"; |
|
253 | + } |
|
254 | + $email_text .= $body; |
|
255 | + } |
|
256 | + } |
|
257 | + } |
|
258 | + } |
|
259 | 259 | } |
260 | 260 | if ($email_text) |
261 | - write_and_send_email($current, $email_text, $template); |
|
261 | + write_and_send_email($current, $email_text, $template); |
|
262 | 262 | |
263 | 263 | mlog("\n"); |
264 | 264 | |
265 | 265 | $sss = "Active alerts: $active\nEmail lookups: $registered registered, $unregistered unregistered\nQuery lookups: $queries\nSent emails: $sentemails\n"; |
266 | 266 | if ($globalsuccess) { |
267 | - $sss .= 'Everything went swimmingly, in '; |
|
267 | + $sss .= 'Everything went swimmingly, in '; |
|
268 | 268 | } else { |
269 | - $sss .= 'Something went wrong! Total time: '; |
|
269 | + $sss .= 'Something went wrong! Total time: '; |
|
270 | 270 | } |
271 | 271 | $sss .= (getmicrotime()-$global_start)."\n\n"; |
272 | 272 | mlog($sss); |
273 | 273 | if (!$nomail && !$onlyemail) { |
274 | - $fp = fopen('alerts-lastsent', 'w'); |
|
275 | - fwrite($fp, time() . "\n"); |
|
276 | - fwrite($fp, $max_batch_id); |
|
277 | - fclose($fp); |
|
278 | - mail(ALERT_STATS_EMAILS, 'Email alert statistics', $sss, 'From: Email Alerts <[email protected]>'); |
|
274 | + $fp = fopen('alerts-lastsent', 'w'); |
|
275 | + fwrite($fp, time() . "\n"); |
|
276 | + fwrite($fp, $max_batch_id); |
|
277 | + fclose($fp); |
|
278 | + mail(ALERT_STATS_EMAILS, 'Email alert statistics', $sss, 'From: Email Alerts <[email protected]>'); |
|
279 | 279 | } |
280 | 280 | mlog(date('r') . "\n"); |
281 | 281 | |
@@ -303,30 +303,30 @@ discard block |
||
303 | 303 | } |
304 | 304 | |
305 | 305 | function write_and_send_email($current, $data, $template) { |
306 | - global $globalsuccess, $sentemails, $nomail, $start_time; |
|
307 | - |
|
308 | - $data .= '===================='; |
|
309 | - $sentemails++; |
|
310 | - mlog("SEND $sentemails : Sending email to $current[email] ... "); |
|
311 | - $d = array('to' => $current['email'], 'template' => $template); |
|
312 | - $m = array( |
|
313 | - 'DATA' => $data, |
|
314 | - 'MANAGE' => 'https://www.theyworkforyou.com/D/' . $current['token'], |
|
315 | - ); |
|
316 | - if (!$nomail) { |
|
317 | - $success = send_template_email($d, $m, true, true); # true = "Precedence: bulk", want bounces |
|
318 | - mlog("sent ... "); |
|
319 | - # sleep if time between sending mails is less than a certain number of seconds on average |
|
320 | - if (((time() - $start_time) / $sentemails) < 0.5 ) { # number of seconds per mail not to be quicker than |
|
321 | - mlog("pausing ... "); |
|
322 | - sleep(1); |
|
323 | - } |
|
324 | - } else { |
|
325 | - mlog($data); |
|
326 | - $success = 1; |
|
327 | - } |
|
328 | - mlog("done\n"); |
|
329 | - if (!$success) $globalsuccess = 0; |
|
306 | + global $globalsuccess, $sentemails, $nomail, $start_time; |
|
307 | + |
|
308 | + $data .= '===================='; |
|
309 | + $sentemails++; |
|
310 | + mlog("SEND $sentemails : Sending email to $current[email] ... "); |
|
311 | + $d = array('to' => $current['email'], 'template' => $template); |
|
312 | + $m = array( |
|
313 | + 'DATA' => $data, |
|
314 | + 'MANAGE' => 'https://www.theyworkforyou.com/D/' . $current['token'], |
|
315 | + ); |
|
316 | + if (!$nomail) { |
|
317 | + $success = send_template_email($d, $m, true, true); # true = "Precedence: bulk", want bounces |
|
318 | + mlog("sent ... "); |
|
319 | + # sleep if time between sending mails is less than a certain number of seconds on average |
|
320 | + if (((time() - $start_time) / $sentemails) < 0.5 ) { # number of seconds per mail not to be quicker than |
|
321 | + mlog("pausing ... "); |
|
322 | + sleep(1); |
|
323 | + } |
|
324 | + } else { |
|
325 | + mlog($data); |
|
326 | + $success = 1; |
|
327 | + } |
|
328 | + mlog("done\n"); |
|
329 | + if (!$success) $globalsuccess = 0; |
|
330 | 330 | } |
331 | 331 | |
332 | 332 | function text_html_to_email($s) { |
@@ -307,7 +307,7 @@ |
||
307 | 307 | |
308 | 308 | $data .= '===================='; |
309 | 309 | $sentemails++; |
310 | - mlog("SEND $sentemails : Sending email to $current[email] ... "); |
|
310 | + mlog("send $sentemails : Sending email to $current[email] ... "); |
|
311 | 311 | $d = array('to' => $current['email'], 'template' => $template); |
312 | 312 | $m = array( |
313 | 313 | 'DATA' => $data, |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | # Construct query fragment to select search index batches which |
38 | 38 | # have been made since last time we ran |
39 | 39 | $batch_query_fragment = ""; |
40 | -for ($i=$lastbatch + 1; $i <= $max_batch_id; $i++) { |
|
40 | +for ($i = $lastbatch + 1; $i <= $max_batch_id; $i++) { |
|
41 | 41 | $batch_query_fragment .= "batch:$i "; |
42 | 42 | } |
43 | 43 | $batch_query_fragment = trim($batch_query_fragment); |
@@ -55,7 +55,7 @@ discard block |
||
55 | 55 | $fromflag = false; |
56 | 56 | $toemail = ''; |
57 | 57 | $template = 'alert_mailout'; |
58 | -for ($k=1; $k<$argc; $k++) { |
|
58 | +for ($k = 1; $k < $argc; $k++) { |
|
59 | 59 | if ($argv[$k] == '--nomail') |
60 | 60 | $nomail = true; |
61 | 61 | if (preg_match('#^--only=(.*)$#', $argv[$k], $m)) |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | $user_id = 0; |
169 | 169 | $unregistered++; |
170 | 170 | } |
171 | - mlog("\nEMAIL: $email, uid $user_id; memory usage : ".memory_get_usage()."\n"); |
|
171 | + mlog("\nEMAIL: $email, uid $user_id; memory usage : " . memory_get_usage() . "\n"); |
|
172 | 172 | } |
173 | 173 | |
174 | 174 | $data = null; |
@@ -195,7 +195,7 @@ discard block |
||
195 | 195 | # unset($SEARCHENGINE); |
196 | 196 | $total_results = $data['info']['total_results']; |
197 | 197 | $queries++; |
198 | - mlog(", hits ".$total_results.", time ".(getmicrotime()-$start)."\n"); |
|
198 | + mlog(", hits " . $total_results . ", time " . (getmicrotime() - $start) . "\n"); |
|
199 | 199 | } else { |
200 | 200 | mlog(" ACTION $active/$outof CACHE HIT : Using cached result for '$criteria_batch'\n"); |
201 | 201 | $data = $results[$criteria_batch]; |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | )); |
227 | 227 | if ($q->rows() > 0) continue; |
228 | 228 | --$k; |
229 | - if ($k>=0) { |
|
229 | + if ($k >= 0) { |
|
230 | 230 | $any_content = true; |
231 | 231 | $parentbody = text_html_to_email($row['parent']['body']); |
232 | 232 | $body = text_html_to_email($row['extract']); |
@@ -246,10 +246,10 @@ discard block |
||
246 | 246 | $desc = trim(preg_replace('#\(?B\d+( OR B\d+)*\)?\s*#', '', $desc)); |
247 | 247 | foreach ($o as $major => $body) { |
248 | 248 | if ($body) { |
249 | - $heading = $desc . ' : ' . $count[$major] . ' ' . $sects[$major] . ($count[$major]!=1?'s':''); |
|
250 | - $email_text .= "$heading\n".str_repeat('=',strlen($heading))."\n\n"; |
|
249 | + $heading = $desc . ' : ' . $count[$major] . ' ' . $sects[$major] . ($count[$major] != 1 ? 's' : ''); |
|
250 | + $email_text .= "$heading\n" . str_repeat('=', strlen($heading)) . "\n\n"; |
|
251 | 251 | if ($count[$major] > 3) { |
252 | - $email_text .= "There are more results than we have shown here. See more:\nhttps://www.theyworkforyou.com/search/?s=".urlencode($criteria_raw)."+section:".$sects_search[$major]."&o=d\n\n"; |
|
252 | + $email_text .= "There are more results than we have shown here. See more:\nhttps://www.theyworkforyou.com/search/?s=" . urlencode($criteria_raw) . "+section:" . $sects_search[$major] . "&o=d\n\n"; |
|
253 | 253 | } |
254 | 254 | $email_text .= $body; |
255 | 255 | } |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | } else { |
269 | 269 | $sss .= 'Something went wrong! Total time: '; |
270 | 270 | } |
271 | -$sss .= (getmicrotime()-$global_start)."\n\n"; |
|
271 | +$sss .= (getmicrotime() - $global_start) . "\n\n"; |
|
272 | 272 | mlog($sss); |
273 | 273 | if (!$nomail && !$onlyemail) { |
274 | 274 | $fp = fopen('alerts-lastsent', 'w'); |
@@ -317,7 +317,7 @@ discard block |
||
317 | 317 | $success = send_template_email($d, $m, true, true); # true = "Precedence: bulk", want bounces |
318 | 318 | mlog("sent ... "); |
319 | 319 | # sleep if time between sending mails is less than a certain number of seconds on average |
320 | - if (((time() - $start_time) / $sentemails) < 0.5 ) { # number of seconds per mail not to be quicker than |
|
320 | + if (((time() - $start_time) / $sentemails) < 0.5) { # number of seconds per mail not to be quicker than |
|
321 | 321 | mlog("pausing ... "); |
322 | 322 | sleep(1); |
323 | 323 | } |
@@ -334,7 +334,7 @@ discard block |
||
334 | 334 | $s = preg_replace('#</?span[^>]*>#', '*', $s); |
335 | 335 | $s = str_replace( |
336 | 336 | array('£', '–', '—', '’', '<br>'), |
337 | - array("\xa3", '-', '-', "'", "\n" ), |
|
337 | + array("\xa3", '-', '-', "'", "\n"), |
|
338 | 338 | $s |
339 | 339 | ); |
340 | 340 | return $s; |
@@ -23,15 +23,20 @@ discard block |
||
23 | 23 | |
24 | 24 | # Last sent is timestamp of last alerts gone out. |
25 | 25 | # Last batch is the search index batch number last alert went out to. |
26 | -if (is_file('alerts-lastsent')) |
|
26 | +if (is_file('alerts-lastsent')) { |
|
27 | 27 | $lastsent = file('alerts-lastsent'); |
28 | -else |
|
28 | +} else { |
|
29 | 29 | $lastsent = array('', 0); |
30 | +} |
|
30 | 31 | |
31 | 32 | $lastupdated = trim($lastsent[0]); |
32 | -if (!$lastupdated) $lastupdated = strtotime('00:00 today'); |
|
33 | +if (!$lastupdated) { |
|
34 | + $lastupdated = strtotime('00:00 today'); |
|
35 | +} |
|
33 | 36 | $lastbatch = trim($lastsent[1]); |
34 | -if (!$lastbatch) $lastbatch = 0; |
|
37 | +if (!$lastbatch) { |
|
38 | + $lastbatch = 0; |
|
39 | +} |
|
35 | 40 | mlog("lastupdated: $lastupdated lastbatch: $lastbatch\n"); |
36 | 41 | |
37 | 42 | # Construct query fragment to select search index batches which |
@@ -56,14 +61,18 @@ discard block |
||
56 | 61 | $toemail = ''; |
57 | 62 | $template = 'alert_mailout'; |
58 | 63 | for ($k=1; $k<$argc; $k++) { |
59 | - if ($argv[$k] == '--nomail') |
|
60 | - $nomail = true; |
|
61 | - if (preg_match('#^--only=(.*)$#', $argv[$k], $m)) |
|
62 | - $onlyemail = $m[1]; |
|
63 | - if (preg_match('#^--from=(.*)$#', $argv[$k], $m)) |
|
64 | - $fromemail = $m[1]; |
|
65 | - if (preg_match('#^--to=(.*)$#', $argv[$k], $m)) |
|
66 | - $toemail = $m[1]; |
|
64 | + if ($argv[$k] == '--nomail') { |
|
65 | + $nomail = true; |
|
66 | + } |
|
67 | + if (preg_match('#^--only=(.*)$#', $argv[$k], $m)) { |
|
68 | + $onlyemail = $m[1]; |
|
69 | + } |
|
70 | + if (preg_match('#^--from=(.*)$#', $argv[$k], $m)) { |
|
71 | + $fromemail = $m[1]; |
|
72 | + } |
|
73 | + if (preg_match('#^--to=(.*)$#', $argv[$k], $m)) { |
|
74 | + $toemail = $m[1]; |
|
75 | + } |
|
67 | 76 | if (preg_match('#^--template=(.*)$#', $argv[$k], $m)) { |
68 | 77 | $template = $m[1]; |
69 | 78 | # Tee hee |
@@ -71,10 +80,13 @@ discard block |
||
71 | 80 | } |
72 | 81 | } |
73 | 82 | |
74 | -if (DEVSITE) |
|
83 | +if (DEVSITE) { |
|
75 | 84 | $nomail = true; |
85 | +} |
|
76 | 86 | |
77 | -if ($nomail) mlog("NOT SENDING EMAIL\n"); |
|
87 | +if ($nomail) { |
|
88 | + mlog("NOT SENDING EMAIL\n"); |
|
89 | +} |
|
78 | 90 | if (($fromemail && $onlyemail) || ($toemail && $onlyemail)) { |
79 | 91 | mlog("Can't have both from/to and only!\n"); |
80 | 92 | exit; |
@@ -142,10 +154,18 @@ discard block |
||
142 | 154 | foreach ($alertdata as $alertitem) { |
143 | 155 | $active++; |
144 | 156 | $email = $alertitem['email']; |
145 | - if ($onlyemail && $email != $onlyemail) continue; |
|
146 | - if ($fromemail && strtolower($email) == $fromemail) $fromflag = true; |
|
147 | - if ($fromemail && !$fromflag) continue; |
|
148 | - if ($toemail && strtolower($email) >= $toemail) continue; |
|
157 | + if ($onlyemail && $email != $onlyemail) { |
|
158 | + continue; |
|
159 | + } |
|
160 | + if ($fromemail && strtolower($email) == $fromemail) { |
|
161 | + $fromflag = true; |
|
162 | + } |
|
163 | + if ($fromemail && !$fromflag) { |
|
164 | + continue; |
|
165 | + } |
|
166 | + if ($toemail && strtolower($email) >= $toemail) { |
|
167 | + continue; |
|
168 | + } |
|
149 | 169 | $criteria_raw = $alertitem['criteria']; |
150 | 170 | if (preg_match('#\bOR\b#', $criteria_raw)) { |
151 | 171 | $criteria_raw = "($criteria_raw)"; |
@@ -153,8 +173,9 @@ discard block |
||
153 | 173 | $criteria_batch = $criteria_raw . " " . $batch_query_fragment; |
154 | 174 | |
155 | 175 | if ($email != $current['email']) { |
156 | - if ($email_text) |
|
157 | - write_and_send_email($current, $email_text, $template); |
|
176 | + if ($email_text) { |
|
177 | + write_and_send_email($current, $email_text, $template); |
|
178 | + } |
|
158 | 179 | $current['email'] = $email; |
159 | 180 | $current['token'] = $alertitem['alert_id'] . '-' . $alertitem['registrationtoken']; |
160 | 181 | $email_text = ''; |
@@ -219,18 +240,24 @@ discard block |
||
219 | 240 | # inserted, but has already been alerted upon. So |
220 | 241 | # manually now stop anything from before 18th January |
221 | 242 | # 2012 from sending an email alert again. |
222 | - if ($row['hdate'] < '2012-01-18') continue; |
|
243 | + if ($row['hdate'] < '2012-01-18') { |
|
244 | + continue; |
|
245 | + } |
|
223 | 246 | |
224 | 247 | $q = $db->query('SELECT gid_from FROM gidredirect WHERE gid_to = :gid_to', array( |
225 | 248 | ':gid_to' => 'uk.org.publicwhip/' . $sects_gid[$major] . '/' . $row['gid'] |
226 | 249 | )); |
227 | - if ($q->rows() > 0) continue; |
|
250 | + if ($q->rows() > 0) { |
|
251 | + continue; |
|
252 | + } |
|
228 | 253 | --$k; |
229 | 254 | if ($k>=0) { |
230 | 255 | $any_content = true; |
231 | 256 | $parentbody = text_html_to_email($row['parent']['body']); |
232 | 257 | $body = text_html_to_email($row['extract']); |
233 | - if (isset($row['speaker']) && count($row['speaker'])) $body = $row['speaker']['name'] . ': ' . $body; |
|
258 | + if (isset($row['speaker']) && count($row['speaker'])) { |
|
259 | + $body = $row['speaker']['name'] . ': ' . $body; |
|
260 | + } |
|
234 | 261 | |
235 | 262 | $body = wordwrap($body, 72); |
236 | 263 | $o[$major] .= $parentbody . ' (' . format_date($row['hdate'], SHORTDATEFORMAT) . ")\nhttps://www.theyworkforyou.com" . $row['listurl'] . "\n"; |
@@ -257,8 +284,9 @@ discard block |
||
257 | 284 | } |
258 | 285 | } |
259 | 286 | } |
260 | -if ($email_text) |
|
287 | +if ($email_text) { |
|
261 | 288 | write_and_send_email($current, $email_text, $template); |
289 | +} |
|
262 | 290 | |
263 | 291 | mlog("\n"); |
264 | 292 | |
@@ -281,24 +309,42 @@ discard block |
||
281 | 309 | |
282 | 310 | function sort_by_stuff($a, $b) { |
283 | 311 | # Always have future business first. |
284 | - if ($a['major'] == 'F' && $b['major'] != 'F') return -1; |
|
285 | - if ($b['major'] == 'F' && $a['major'] != 'F') return 1; |
|
312 | + if ($a['major'] == 'F' && $b['major'] != 'F') { |
|
313 | + return -1; |
|
314 | + } |
|
315 | + if ($b['major'] == 'F' && $a['major'] != 'F') { |
|
316 | + return 1; |
|
317 | + } |
|
286 | 318 | |
287 | 319 | # Otherwise sort firstly by major number (so Commons before NI before SP before Lords) |
288 | - if ($a['major'] > $b['major']) return 1; |
|
289 | - if ($a['major'] < $b['major']) return -1; |
|
320 | + if ($a['major'] > $b['major']) { |
|
321 | + return 1; |
|
322 | + } |
|
323 | + if ($a['major'] < $b['major']) { |
|
324 | + return -1; |
|
325 | + } |
|
290 | 326 | |
291 | 327 | # Then by date (most recent first for everything except future, which is the opposite) |
292 | 328 | if ($a['major'] == 'F') { |
293 | - if ($a['hdate'] > $b['hdate']) return 1; |
|
294 | - if ($a['hdate'] < $b['hdate']) return -1; |
|
329 | + if ($a['hdate'] > $b['hdate']) { |
|
330 | + return 1; |
|
331 | + } |
|
332 | + if ($a['hdate'] < $b['hdate']) { |
|
333 | + return -1; |
|
334 | + } |
|
295 | 335 | } else { |
296 | - if ($a['hdate'] < $b['hdate']) return 1; |
|
297 | - if ($a['hdate'] > $b['hdate']) return -1; |
|
336 | + if ($a['hdate'] < $b['hdate']) { |
|
337 | + return 1; |
|
338 | + } |
|
339 | + if ($a['hdate'] > $b['hdate']) { |
|
340 | + return -1; |
|
341 | + } |
|
298 | 342 | } |
299 | 343 | |
300 | 344 | # Lastly by speech position within a debate. |
301 | - if ($a['hpos'] == $b['hpos']) return 0; |
|
345 | + if ($a['hpos'] == $b['hpos']) { |
|
346 | + return 0; |
|
347 | + } |
|
302 | 348 | return ($a['hpos'] > $b['hpos']) ? 1 : -1; |
303 | 349 | } |
304 | 350 | |
@@ -317,7 +363,8 @@ discard block |
||
317 | 363 | $success = send_template_email($d, $m, true, true); # true = "Precedence: bulk", want bounces |
318 | 364 | mlog("sent ... "); |
319 | 365 | # sleep if time between sending mails is less than a certain number of seconds on average |
320 | - if (((time() - $start_time) / $sentemails) < 0.5 ) { # number of seconds per mail not to be quicker than |
|
366 | + if (((time() - $start_time) / $sentemails) < 0.5 ) { |
|
367 | +# number of seconds per mail not to be quicker than |
|
321 | 368 | mlog("pausing ... "); |
322 | 369 | sleep(1); |
323 | 370 | } |
@@ -326,8 +373,10 @@ discard block |
||
326 | 373 | $success = 1; |
327 | 374 | } |
328 | 375 | mlog("done\n"); |
329 | - if (!$success) $globalsuccess = 0; |
|
330 | -} |
|
376 | + if (!$success) { |
|
377 | + $globalsuccess = 0; |
|
378 | + } |
|
379 | + } |
|
331 | 380 | |
332 | 381 | function text_html_to_email($s) { |
333 | 382 | $s = preg_replace('#</?(i|small)>#', '', $s); |
@@ -133,14 +133,14 @@ |
||
133 | 133 | ); |
134 | 134 | |
135 | 135 | foreach ($all_topics as $name => $topic) { |
136 | - $existing = $topics->getTopic($name); |
|
137 | - if ($existing) { |
|
138 | - print "$name already exists\n"; |
|
139 | - } else { |
|
140 | - $topic['slug'] = $name; |
|
141 | - $topic['description'] = $topic['blurb']; |
|
142 | - $topic = new MySociety\TheyWorkForYou\Topic($topic); |
|
143 | - $topic->save(); |
|
144 | - print "created $name\n"; |
|
145 | - } |
|
136 | + $existing = $topics->getTopic($name); |
|
137 | + if ($existing) { |
|
138 | + print "$name already exists\n"; |
|
139 | + } else { |
|
140 | + $topic['slug'] = $name; |
|
141 | + $topic['description'] = $topic['blurb']; |
|
142 | + $topic = new MySociety\TheyWorkForYou\Topic($topic); |
|
143 | + $topic->save(); |
|
144 | + print "created $name\n"; |
|
145 | + } |
|
146 | 146 | } |
@@ -2,7 +2,7 @@ |
||
2 | 2 | |
3 | 3 | <?php |
4 | 4 | |
5 | -include_once dirname(__FILE__) .'/../www/includes/easyparliament/init.php'; |
|
5 | +include_once dirname(__FILE__) . '/../www/includes/easyparliament/init.php'; |
|
6 | 6 | |
7 | 7 | $topics = new MySociety\TheyWorkForYou\Topics(); |
8 | 8 |
@@ -23,19 +23,19 @@ discard block |
||
23 | 23 | $toemail = ''; |
24 | 24 | $template = 'alert_gone'; |
25 | 25 | for ($k=1; $k<$argc; $k++) { |
26 | - if ($argv[$k] == '--nomail') |
|
27 | - $nomail = true; |
|
28 | - if (preg_match('#^--only=(.*)$#', $argv[$k], $m)) |
|
29 | - $onlyemail = $m[1]; |
|
30 | - if (preg_match('#^--from=(.*)$#', $argv[$k], $m)) |
|
31 | - $fromemail = $m[1]; |
|
32 | - if (preg_match('#^--to=(.*)$#', $argv[$k], $m)) |
|
33 | - $toemail = $m[1]; |
|
34 | - if (preg_match('#^--template=(.*)$#', $argv[$k], $m)) { |
|
35 | - $template = $m[1]; |
|
36 | - # Tee hee |
|
37 | - $template = "../../../../../../../../../../home/twfy-live/email-alert-templates/alert_mailout_$template"; |
|
38 | - } |
|
26 | + if ($argv[$k] == '--nomail') |
|
27 | + $nomail = true; |
|
28 | + if (preg_match('#^--only=(.*)$#', $argv[$k], $m)) |
|
29 | + $onlyemail = $m[1]; |
|
30 | + if (preg_match('#^--from=(.*)$#', $argv[$k], $m)) |
|
31 | + $fromemail = $m[1]; |
|
32 | + if (preg_match('#^--to=(.*)$#', $argv[$k], $m)) |
|
33 | + $toemail = $m[1]; |
|
34 | + if (preg_match('#^--template=(.*)$#', $argv[$k], $m)) { |
|
35 | + $template = $m[1]; |
|
36 | + # Tee hee |
|
37 | + $template = "../../../../../../../../../../home/twfy-live/email-alert-templates/alert_mailout_$template"; |
|
38 | + } |
|
39 | 39 | } |
40 | 40 | |
41 | 41 | #if (DEVSITE) |
@@ -43,8 +43,8 @@ discard block |
||
43 | 43 | |
44 | 44 | if ($nomail) mlog("NOT SENDING EMAIL\n"); |
45 | 45 | if (($fromemail && $onlyemail) || ($toemail && $onlyemail)) { |
46 | - mlog("Can't have both from/to and only!\n"); |
|
47 | - exit; |
|
46 | + mlog("Can't have both from/to and only!\n"); |
|
47 | + exit; |
|
48 | 48 | } |
49 | 49 | |
50 | 50 | $active = 0; |
@@ -68,22 +68,22 @@ discard block |
||
68 | 68 | $members = array(); |
69 | 69 | $start_time = time(); |
70 | 70 | foreach ($alertdata as $alertitem) { |
71 | - $active++; |
|
72 | - $email = $alertitem['email']; |
|
71 | + $active++; |
|
72 | + $email = $alertitem['email']; |
|
73 | 73 | if ($onlyemail && $email != $onlyemail) continue; |
74 | 74 | if ($fromemail && strtolower($email) == $fromemail) $fromflag = true; |
75 | 75 | if ($fromemail && !$fromflag) continue; |
76 | 76 | if ($toemail && strtolower($email) >= $toemail) continue; |
77 | 77 | $criteria_raw = $alertitem['criteria']; |
78 | 78 | |
79 | - if (!strstr($criteria_raw, 'speaker:')) continue; |
|
79 | + if (!strstr($criteria_raw, 'speaker:')) continue; |
|
80 | 80 | |
81 | - preg_match('#speaker:(\d+)#', $criteria_raw, $m); |
|
82 | - $person_id = $m[1]; |
|
83 | - if (!isset($members[$person_id])) { |
|
81 | + preg_match('#speaker:(\d+)#', $criteria_raw, $m); |
|
82 | + $person_id = $m[1]; |
|
83 | + if (!isset($members[$person_id])) { |
|
84 | 84 | $queries++; |
85 | 85 | $members[$person_id] = new MEMBER(array('person_id' => $person_id)); |
86 | - } |
|
86 | + } |
|
87 | 87 | $member = $members[$person_id]; |
88 | 88 | if ($member->current_member_anywhere()) continue; |
89 | 89 | |
@@ -96,29 +96,29 @@ discard block |
||
96 | 96 | 'John Reid', 'Angela Smith', 'Don Touhig', 'Michael Wills', 'Ian Paisley', |
97 | 97 | ))) continue; |
98 | 98 | |
99 | - if ($email != $current['email']) { |
|
100 | - if ($email_text) |
|
99 | + if ($email != $current['email']) { |
|
100 | + if ($email_text) |
|
101 | 101 | write_and_send_email($current, $email_text, $template); |
102 | - $current['email'] = $email; |
|
103 | - $current['token'] = $alertitem['alert_id'] . '-' . $alertitem['registrationtoken']; |
|
104 | - $email_text = array(); |
|
105 | - $q = $db->query('SELECT user_id FROM users WHERE email = :email', array( |
|
102 | + $current['email'] = $email; |
|
103 | + $current['token'] = $alertitem['alert_id'] . '-' . $alertitem['registrationtoken']; |
|
104 | + $email_text = array(); |
|
105 | + $q = $db->query('SELECT user_id FROM users WHERE email = :email', array( |
|
106 | 106 | ':email' => $email)); |
107 | 107 | if ($q->rows() > 0) { |
108 | 108 | $user_id = $q->field(0, 'user_id'); |
109 | 109 | $registered++; |
110 | - } else { |
|
111 | - $user_id = 0; |
|
112 | - $unregistered++; |
|
113 | - } |
|
114 | - mlog("\nEMAIL: $email, uid $user_id; memory usage : ".memory_get_usage()."\n"); |
|
115 | - } |
|
110 | + } else { |
|
111 | + $user_id = 0; |
|
112 | + $unregistered++; |
|
113 | + } |
|
114 | + mlog("\nEMAIL: $email, uid $user_id; memory usage : ".memory_get_usage()."\n"); |
|
115 | + } |
|
116 | 116 | |
117 | 117 | $lh = $member->left_house(); |
118 | 118 | $lh = array_shift($lh); |
119 | 119 | $text = '* ' . $member->full_name() . ', left ' . $lh['date_pretty']; |
120 | 120 | if (!in_array($text, $email_text)) |
121 | - $email_text[] = $text; |
|
121 | + $email_text[] = $text; |
|
122 | 122 | } |
123 | 123 | if ($email_text) |
124 | 124 | write_and_send_email($current, $email_text, $template); |
@@ -127,39 +127,39 @@ discard block |
||
127 | 127 | |
128 | 128 | $sss = "Active alerts: $active\nEmail lookups: $registered registered, $unregistered unregistered\nQuery lookups: $queries\nSent emails: $sentemails\n"; |
129 | 129 | if ($globalsuccess) { |
130 | - $sss .= 'Everything went swimmingly, in '; |
|
130 | + $sss .= 'Everything went swimmingly, in '; |
|
131 | 131 | } else { |
132 | - $sss .= 'Something went wrong! Total time: '; |
|
132 | + $sss .= 'Something went wrong! Total time: '; |
|
133 | 133 | } |
134 | 134 | $sss .= (getmicrotime()-$global_start)."\n\n"; |
135 | 135 | mlog($sss); |
136 | 136 | mlog(date('r') . "\n"); |
137 | 137 | |
138 | 138 | function write_and_send_email($current, $data, $template) { |
139 | - global $globalsuccess, $sentemails, $nomail, $start_time; |
|
140 | - |
|
141 | - $sentemails++; |
|
142 | - mlog("SEND $sentemails : Sending email to $current[email] ... "); |
|
143 | - $d = array('to' => $current['email'], 'template' => $template); |
|
144 | - $m = array( |
|
145 | - 'DATA' => join("\n", $data), |
|
146 | - 'MANAGE' => 'https://www.theyworkforyou.com/D/' . $current['token'], |
|
139 | + global $globalsuccess, $sentemails, $nomail, $start_time; |
|
140 | + |
|
141 | + $sentemails++; |
|
142 | + mlog("SEND $sentemails : Sending email to $current[email] ... "); |
|
143 | + $d = array('to' => $current['email'], 'template' => $template); |
|
144 | + $m = array( |
|
145 | + 'DATA' => join("\n", $data), |
|
146 | + 'MANAGE' => 'https://www.theyworkforyou.com/D/' . $current['token'], |
|
147 | 147 | 'ALERT_IS' => count($data)==1 ? 'alert is' : 'alerts are', |
148 | 148 | 'ALERTS' => count($data)==1 ? 'an alert' : 'some alerts', |
149 | - ); |
|
150 | - if (!$nomail) { |
|
151 | - $success = send_template_email($d, $m, true); |
|
152 | - mlog("sent ... "); |
|
153 | - # sleep if time between sending mails is less than a certain number of seconds on average |
|
154 | - if (((time() - $start_time) / $sentemails) < 0.5 ) { # number of seconds per mail not to be quicker than |
|
155 | - mlog("pausing ... "); |
|
156 | - sleep(1); |
|
157 | - } |
|
158 | - } else { |
|
159 | - mlog(join('', $data)); |
|
160 | - $success = 1; |
|
161 | - } |
|
162 | - mlog("done\n"); |
|
163 | - if (!$success) $globalsuccess = 0; |
|
149 | + ); |
|
150 | + if (!$nomail) { |
|
151 | + $success = send_template_email($d, $m, true); |
|
152 | + mlog("sent ... "); |
|
153 | + # sleep if time between sending mails is less than a certain number of seconds on average |
|
154 | + if (((time() - $start_time) / $sentemails) < 0.5 ) { # number of seconds per mail not to be quicker than |
|
155 | + mlog("pausing ... "); |
|
156 | + sleep(1); |
|
157 | + } |
|
158 | + } else { |
|
159 | + mlog(join('', $data)); |
|
160 | + $success = 1; |
|
161 | + } |
|
162 | + mlog("done\n"); |
|
163 | + if (!$success) $globalsuccess = 0; |
|
164 | 164 | } |
165 | 165 |
@@ -139,7 +139,7 @@ |
||
139 | 139 | global $globalsuccess, $sentemails, $nomail, $start_time; |
140 | 140 | |
141 | 141 | $sentemails++; |
142 | - mlog("SEND $sentemails : Sending email to $current[email] ... "); |
|
142 | + mlog("send $sentemails : Sending email to $current[email] ... "); |
|
143 | 143 | $d = array('to' => $current['email'], 'template' => $template); |
144 | 144 | $m = array( |
145 | 145 | 'DATA' => join("\n", $data), |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | $fromflag = false; |
23 | 23 | $toemail = ''; |
24 | 24 | $template = 'alert_gone'; |
25 | -for ($k=1; $k<$argc; $k++) { |
|
25 | +for ($k = 1; $k < $argc; $k++) { |
|
26 | 26 | if ($argv[$k] == '--nomail') |
27 | 27 | $nomail = true; |
28 | 28 | if (preg_match('#^--only=(.*)$#', $argv[$k], $m)) |
@@ -111,7 +111,7 @@ discard block |
||
111 | 111 | $user_id = 0; |
112 | 112 | $unregistered++; |
113 | 113 | } |
114 | - mlog("\nEMAIL: $email, uid $user_id; memory usage : ".memory_get_usage()."\n"); |
|
114 | + mlog("\nEMAIL: $email, uid $user_id; memory usage : " . memory_get_usage() . "\n"); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | $lh = $member->left_house(); |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | } else { |
132 | 132 | $sss .= 'Something went wrong! Total time: '; |
133 | 133 | } |
134 | -$sss .= (getmicrotime()-$global_start)."\n\n"; |
|
134 | +$sss .= (getmicrotime() - $global_start) . "\n\n"; |
|
135 | 135 | mlog($sss); |
136 | 136 | mlog(date('r') . "\n"); |
137 | 137 | |
@@ -144,14 +144,14 @@ discard block |
||
144 | 144 | $m = array( |
145 | 145 | 'DATA' => join("\n", $data), |
146 | 146 | 'MANAGE' => 'https://www.theyworkforyou.com/D/' . $current['token'], |
147 | - 'ALERT_IS' => count($data)==1 ? 'alert is' : 'alerts are', |
|
148 | - 'ALERTS' => count($data)==1 ? 'an alert' : 'some alerts', |
|
147 | + 'ALERT_IS' => count($data) == 1 ? 'alert is' : 'alerts are', |
|
148 | + 'ALERTS' => count($data) == 1 ? 'an alert' : 'some alerts', |
|
149 | 149 | ); |
150 | 150 | if (!$nomail) { |
151 | 151 | $success = send_template_email($d, $m, true); |
152 | 152 | mlog("sent ... "); |
153 | 153 | # sleep if time between sending mails is less than a certain number of seconds on average |
154 | - if (((time() - $start_time) / $sentemails) < 0.5 ) { # number of seconds per mail not to be quicker than |
|
154 | + if (((time() - $start_time) / $sentemails) < 0.5) { # number of seconds per mail not to be quicker than |
|
155 | 155 | mlog("pausing ... "); |
156 | 156 | sleep(1); |
157 | 157 | } |
@@ -23,14 +23,18 @@ discard block |
||
23 | 23 | $toemail = ''; |
24 | 24 | $template = 'alert_gone'; |
25 | 25 | for ($k=1; $k<$argc; $k++) { |
26 | - if ($argv[$k] == '--nomail') |
|
27 | - $nomail = true; |
|
28 | - if (preg_match('#^--only=(.*)$#', $argv[$k], $m)) |
|
29 | - $onlyemail = $m[1]; |
|
30 | - if (preg_match('#^--from=(.*)$#', $argv[$k], $m)) |
|
31 | - $fromemail = $m[1]; |
|
32 | - if (preg_match('#^--to=(.*)$#', $argv[$k], $m)) |
|
33 | - $toemail = $m[1]; |
|
26 | + if ($argv[$k] == '--nomail') { |
|
27 | + $nomail = true; |
|
28 | + } |
|
29 | + if (preg_match('#^--only=(.*)$#', $argv[$k], $m)) { |
|
30 | + $onlyemail = $m[1]; |
|
31 | + } |
|
32 | + if (preg_match('#^--from=(.*)$#', $argv[$k], $m)) { |
|
33 | + $fromemail = $m[1]; |
|
34 | + } |
|
35 | + if (preg_match('#^--to=(.*)$#', $argv[$k], $m)) { |
|
36 | + $toemail = $m[1]; |
|
37 | + } |
|
34 | 38 | if (preg_match('#^--template=(.*)$#', $argv[$k], $m)) { |
35 | 39 | $template = $m[1]; |
36 | 40 | # Tee hee |
@@ -41,7 +45,9 @@ discard block |
||
41 | 45 | #if (DEVSITE) |
42 | 46 | # $nomail = true; |
43 | 47 | |
44 | -if ($nomail) mlog("NOT SENDING EMAIL\n"); |
|
48 | +if ($nomail) { |
|
49 | + mlog("NOT SENDING EMAIL\n"); |
|
50 | +} |
|
45 | 51 | if (($fromemail && $onlyemail) || ($toemail && $onlyemail)) { |
46 | 52 | mlog("Can't have both from/to and only!\n"); |
47 | 53 | exit; |
@@ -70,13 +76,23 @@ discard block |
||
70 | 76 | foreach ($alertdata as $alertitem) { |
71 | 77 | $active++; |
72 | 78 | $email = $alertitem['email']; |
73 | - if ($onlyemail && $email != $onlyemail) continue; |
|
74 | - if ($fromemail && strtolower($email) == $fromemail) $fromflag = true; |
|
75 | - if ($fromemail && !$fromflag) continue; |
|
76 | - if ($toemail && strtolower($email) >= $toemail) continue; |
|
79 | + if ($onlyemail && $email != $onlyemail) { |
|
80 | + continue; |
|
81 | + } |
|
82 | + if ($fromemail && strtolower($email) == $fromemail) { |
|
83 | + $fromflag = true; |
|
84 | + } |
|
85 | + if ($fromemail && !$fromflag) { |
|
86 | + continue; |
|
87 | + } |
|
88 | + if ($toemail && strtolower($email) >= $toemail) { |
|
89 | + continue; |
|
90 | + } |
|
77 | 91 | $criteria_raw = $alertitem['criteria']; |
78 | 92 | |
79 | - if (!strstr($criteria_raw, 'speaker:')) continue; |
|
93 | + if (!strstr($criteria_raw, 'speaker:')) { |
|
94 | + continue; |
|
95 | + } |
|
80 | 96 | |
81 | 97 | preg_match('#speaker:(\d+)#', $criteria_raw, $m); |
82 | 98 | $person_id = $m[1]; |
@@ -85,7 +101,9 @@ discard block |
||
85 | 101 | $members[$person_id] = new MEMBER(array('person_id' => $person_id)); |
86 | 102 | } |
87 | 103 | $member = $members[$person_id]; |
88 | - if ($member->current_member_anywhere()) continue; |
|
104 | + if ($member->current_member_anywhere()) { |
|
105 | + continue; |
|
106 | + } |
|
89 | 107 | |
90 | 108 | if (in_array($member->full_name(), array( |
91 | 109 | 'Mr Paul Boateng', 'Mrs Helen Liddell', 'Jack McConnell', 'Tim Boswell', |
@@ -94,11 +112,14 @@ discard block |
||
94 | 112 | 'Hilary Armstrong', 'Des Browne', 'Quentin Davies', 'Beverley Hughes', |
95 | 113 | 'John Hutton', 'Jim Knight', 'Thomas McAvoy', 'John McFall', 'John Prescott', |
96 | 114 | 'John Reid', 'Angela Smith', 'Don Touhig', 'Michael Wills', 'Ian Paisley', |
97 | - ))) continue; |
|
115 | + ))) { |
|
116 | + continue; |
|
117 | + } |
|
98 | 118 | |
99 | 119 | if ($email != $current['email']) { |
100 | - if ($email_text) |
|
101 | - write_and_send_email($current, $email_text, $template); |
|
120 | + if ($email_text) { |
|
121 | + write_and_send_email($current, $email_text, $template); |
|
122 | + } |
|
102 | 123 | $current['email'] = $email; |
103 | 124 | $current['token'] = $alertitem['alert_id'] . '-' . $alertitem['registrationtoken']; |
104 | 125 | $email_text = array(); |
@@ -117,11 +138,13 @@ discard block |
||
117 | 138 | $lh = $member->left_house(); |
118 | 139 | $lh = array_shift($lh); |
119 | 140 | $text = '* ' . $member->full_name() . ', left ' . $lh['date_pretty']; |
120 | - if (!in_array($text, $email_text)) |
|
121 | - $email_text[] = $text; |
|
122 | -} |
|
123 | -if ($email_text) |
|
141 | + if (!in_array($text, $email_text)) { |
|
142 | + $email_text[] = $text; |
|
143 | + } |
|
144 | + } |
|
145 | +if ($email_text) { |
|
124 | 146 | write_and_send_email($current, $email_text, $template); |
147 | +} |
|
125 | 148 | |
126 | 149 | mlog("\n"); |
127 | 150 | |
@@ -151,7 +174,8 @@ discard block |
||
151 | 174 | $success = send_template_email($d, $m, true); |
152 | 175 | mlog("sent ... "); |
153 | 176 | # sleep if time between sending mails is less than a certain number of seconds on average |
154 | - if (((time() - $start_time) / $sentemails) < 0.5 ) { # number of seconds per mail not to be quicker than |
|
177 | + if (((time() - $start_time) / $sentemails) < 0.5 ) { |
|
178 | +# number of seconds per mail not to be quicker than |
|
155 | 179 | mlog("pausing ... "); |
156 | 180 | sleep(1); |
157 | 181 | } |
@@ -160,6 +184,8 @@ discard block |
||
160 | 184 | $success = 1; |
161 | 185 | } |
162 | 186 | mlog("done\n"); |
163 | - if (!$success) $globalsuccess = 0; |
|
164 | -} |
|
187 | + if (!$success) { |
|
188 | + $globalsuccess = 0; |
|
189 | + } |
|
190 | + } |
|
165 | 191 |
@@ -26,9 +26,13 @@ |
||
26 | 26 | $body = strip_tags($q->field($i, 'body')); |
27 | 27 | $qq = $db->query('select time_to_sec(atime) as atime from hansard,video_timestamps where hansard.gid=video_timestamps.gid and deleted=0 and video_status in (5,7) and hdate="' . $hdate . '" and hpos=' . ($hpos+1) . ' group by video_timestamps.gid'); |
28 | 28 | $next_atime = $qq->field(0, 'atime'); |
29 | - if (!$next_atime) continue; |
|
29 | + if (!$next_atime) { |
|
30 | + continue; |
|
31 | + } |
|
30 | 32 | $duration = $next_atime - $atime; |
31 | - if ($duration<=0) continue; |
|
33 | + if ($duration<=0) { |
|
34 | + continue; |
|
35 | + } |
|
32 | 36 | $words = preg_split('/\W+/', $body, -1, PREG_SPLIT_NO_EMPTY); |
33 | 37 | $num_words = count($words); |
34 | 38 | $speed = $num_words / ($duration/60); |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | $db = new ParlDB; |
6 | 6 | |
7 | 7 | $q = $db->query('select distinct(person_id) from hansard where video_status in (5,7) and person_id>0 limit 5'); |
8 | -for ($i=0; $i<$q->rows(); $i++) { |
|
8 | +for ($i = 0; $i < $q->rows(); $i++) { |
|
9 | 9 | $spid = $q->field($i, 'person_id'); |
10 | 10 | calculate_speed($db, $spid); |
11 | 11 | } |
@@ -18,20 +18,20 @@ discard block |
||
18 | 18 | $total_words = 0; |
19 | 19 | $total_speed = 0; |
20 | 20 | $num = 0; |
21 | - for ($i=0; $i<$q->rows(); $i++) { |
|
21 | + for ($i = 0; $i < $q->rows(); $i++) { |
|
22 | 22 | $hpos = $q->field($i, 'hpos'); |
23 | 23 | $hdate = $q->field($i, 'hdate'); |
24 | 24 | $gid = $q->field($i, 'gid'); |
25 | 25 | $atime = $q->field($i, 'atime'); |
26 | 26 | $body = strip_tags($q->field($i, 'body')); |
27 | - $qq = $db->query('select time_to_sec(atime) as atime from hansard,video_timestamps where hansard.gid=video_timestamps.gid and deleted=0 and video_status in (5,7) and hdate="' . $hdate . '" and hpos=' . ($hpos+1) . ' group by video_timestamps.gid'); |
|
27 | + $qq = $db->query('select time_to_sec(atime) as atime from hansard,video_timestamps where hansard.gid=video_timestamps.gid and deleted=0 and video_status in (5,7) and hdate="' . $hdate . '" and hpos=' . ($hpos + 1) . ' group by video_timestamps.gid'); |
|
28 | 28 | $next_atime = $qq->field(0, 'atime'); |
29 | 29 | if (!$next_atime) continue; |
30 | 30 | $duration = $next_atime - $atime; |
31 | - if ($duration<=0) continue; |
|
31 | + if ($duration <= 0) continue; |
|
32 | 32 | $words = preg_split('/\W+/', $body, -1, PREG_SPLIT_NO_EMPTY); |
33 | 33 | $num_words = count($words); |
34 | - $speed = $num_words / ($duration/60); |
|
34 | + $speed = $num_words / ($duration / 60); |
|
35 | 35 | $total_speed += $speed; |
36 | 36 | print "$gid, $num_words words, from $atime to $next_atime, duration $duration s, speed $speed wpm\n"; |
37 | 37 | $total += $duration; |
@@ -39,12 +39,12 @@ discard block |
||
39 | 39 | $num++; |
40 | 40 | } |
41 | 41 | |
42 | - $total_min = $total/60; |
|
42 | + $total_min = $total / 60; |
|
43 | 43 | |
44 | 44 | print "Person ID $spid\n"; |
45 | - print "Average length = " . ($total/$num) . "s\n"; |
|
46 | - print "Average speed = " . ($total_words/$total_min) . "wpm\n"; |
|
47 | - print "Average of speeds = " . ($total_speed/$num) . "wpm\n"; |
|
45 | + print "Average length = " . ($total / $num) . "s\n"; |
|
46 | + print "Average speed = " . ($total_words / $total_min) . "wpm\n"; |
|
47 | + print "Average of speeds = " . ($total_speed / $num) . "wpm\n"; |
|
48 | 48 | print "\n"; |
49 | 49 | } |
50 | 50 |
@@ -325,10 +325,10 @@ discard block |
||
325 | 325 | |
326 | 326 | $msps = array( |
327 | 327 | array( |
328 | - 'person_id' => "19", |
|
329 | - 'name' => "Mr Regional MSP1", |
|
330 | - 'constituency' => "Mid Scotland and Fife", |
|
331 | - 'house' => "4" |
|
328 | + 'person_id' => "19", |
|
329 | + 'name' => "Mr Regional MSP1", |
|
330 | + 'constituency' => "Mid Scotland and Fife", |
|
331 | + 'house' => "4" |
|
332 | 332 | ), |
333 | 333 | array( |
334 | 334 | 'person_id' => "20", |
@@ -340,10 +340,10 @@ discard block |
||
340 | 340 | $this->assertEquals($msps, \MySociety\TheyWorkForYou\Member::getRegionalList('KY16 8YG', 4, 'SPE')); |
341 | 341 | $mlas = array( |
342 | 342 | array( |
343 | - 'person_id' => "21", |
|
344 | - 'name' => "Mr Regional MLA1", |
|
345 | - 'constituency' => "Belfast West", |
|
346 | - 'house' => "3" |
|
343 | + 'person_id' => "21", |
|
344 | + 'name' => "Mr Regional MLA1", |
|
345 | + 'constituency' => "Belfast West", |
|
346 | + 'house' => "3" |
|
347 | 347 | ), |
348 | 348 | array( |
349 | 349 | 'person_id' => "22", |
@@ -11,7 +11,7 @@ |
||
11 | 11 | */ |
12 | 12 | public function getDataSet() |
13 | 13 | { |
14 | - return $this->createMySQLXMLDataSet(dirname(__FILE__).'/_fixtures/member.xml'); |
|
14 | + return $this->createMySQLXMLDataSet(dirname(__FILE__) . '/_fixtures/member.xml'); |
|
15 | 15 | } |
16 | 16 | |
17 | 17 | /** |
@@ -18,7 +18,7 @@ |
||
18 | 18 | /** |
19 | 19 | * Test converting a postcode to a constituency |
20 | 20 | */ |
21 | - public function testPostcodeToConstituency() |
|
21 | + public function testPostcodeToConstituency() |
|
22 | 22 | { |
23 | 23 | $this->assertEquals( |
24 | 24 | 'Cities of London and Westminster', |
@@ -12,7 +12,7 @@ |
||
12 | 12 | */ |
13 | 13 | public function getDataSet() |
14 | 14 | { |
15 | - return $this->createMySQLXMLDataSet(dirname(__FILE__).'/_fixtures/postcode.xml'); |
|
15 | + return $this->createMySQLXMLDataSet(dirname(__FILE__) . '/_fixtures/postcode.xml'); |
|
16 | 16 | } |
17 | 17 | |
18 | 18 | /** |