Failed Conditions
Pull Request — master (#1326)
by Nick
26:02 queued 20:44
created
scripts/create_initial_topics.php 2 patches
Indentation   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -133,14 +133,14 @@
 block discarded – undo
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
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -2,7 +2,7 @@
 block discarded – undo
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
 
Please login to merge, or discard this patch.
scripts/mprss.php 4 patches
Indentation   +45 added lines, -45 removed lines patch added patch discarded remove patch
@@ -20,49 +20,49 @@  discard block
 block discarded – undo
20 20
 
21 21
 $starttime = time();
22 22
 for ($personrow=0; $personrow<$q->rows(); $personrow++) {
23
-	$person_id = $q->field($personrow, 'person_id');
23
+    $person_id = $q->field($personrow, 'person_id');
24 24
 
25
-	$args = array ( 'person_id' => $person_id );
26
-	$speeches = $HANSARDLIST->display('person', $args, 'none');
25
+    $args = array ( 'person_id' => $person_id );
26
+    $speeches = $HANSARDLIST->display('person', $args, 'none');
27 27
 		
28
-	// Some data about this person that we'll need for the feed.
29
-	$MEMBER = new MEMBER(array('person_id' => $person_id));
30
-	$MPURL = new URL('mp');
31
-	$MPURL->insert(array('pid'=>$person_id));
32
-	$mpurl = $MPURL->generate();
28
+    // Some data about this person that we'll need for the feed.
29
+    $MEMBER = new MEMBER(array('person_id' => $person_id));
30
+    $MPURL = new URL('mp');
31
+    $MPURL->insert(array('pid'=>$person_id));
32
+    $mpurl = $MPURL->generate();
33 33
 		
34
-	$date = gmdate('Y-m-d');
35
-	$time = gmdate('H:i:s');
36
-	$datenow = $date . 'T' . $time . '+00:00';
34
+    $date = gmdate('Y-m-d');
35
+    $time = gmdate('H:i:s');
36
+    $datenow = $date . 'T' . $time . '+00:00';
37 37
 		
38
-	// Prepare the meat of the RSS file.
39
-	$items = '';
40
-	$entries = '';
41
-	if (isset ($speeches['rows']) && count($speeches['rows']) > 0) {
38
+    // Prepare the meat of the RSS file.
39
+    $items = '';
40
+    $entries = '';
41
+    if (isset ($speeches['rows']) && count($speeches['rows']) > 0) {
42 42
 		
43
-		foreach ($speeches['rows'] as $n => $row) {
43
+        foreach ($speeches['rows'] as $n => $row) {
44 44
 		
45
-			// While we're linking to individual speeches,
46
-			// the text is the body of the parent, ie (sub)section.
47
-			$title = _htmlentities(str_replace('&#8212;', '-', $row['parent']['body']));
45
+            // While we're linking to individual speeches,
46
+            // the text is the body of the parent, ie (sub)section.
47
+            $title = _htmlentities(str_replace('&#8212;', '-', $row['parent']['body']));
48 48
 
49
-			$link = isset($row['listurl']) ? $row['listurl'] : '';
50
-			$link = 'https://' . DOMAIN . $link;
49
+            $link = isset($row['listurl']) ? $row['listurl'] : '';
50
+            $link = 'https://' . DOMAIN . $link;
51 51
 				
52
-			$description = _htmlentities(trim_characters($row['body'], 0, 200));
53
-			$contentencoded = $row['body'];
52
+            $description = _htmlentities(trim_characters($row['body'], 0, 200));
53
+            $contentencoded = $row['body'];
54 54
 				
55
-			$hdate = format_date($row['hdate'], 'Y-m-d');
56
-			if ($row['htime'] != NULL) {
57
-				$htime = format_time($row['htime'], 'H:i:s');
58
-			} else {
59
-				$htime = '00:00:00';
60
-			}
55
+            $hdate = format_date($row['hdate'], 'Y-m-d');
56
+            if ($row['htime'] != NULL) {
57
+                $htime = format_time($row['htime'], 'H:i:s');
58
+            } else {
59
+                $htime = '00:00:00';
60
+            }
61 61
 				
62
-			$date = $hdate . 'T' . $htime . '+00:00';
62
+            $date = $hdate . 'T' . $htime . '+00:00';
63 63
 				
64
-			$items .= '<rdf:li rdf:resource="' . $link . '" />' . "\n";
65
-			$entries .= "<item rdf:about=\"$link\">
64
+            $items .= '<rdf:li rdf:resource="' . $link . '" />' . "\n";
65
+            $entries .= "<item rdf:about=\"$link\">
66 66
 	<title>$title</title>
67 67
 	<link>$link</link>
68 68
 	<description>$description</description>
@@ -71,11 +71,11 @@  discard block
 block discarded – undo
71 71
 </item>
72 72
 ";
73 73
 		
74
-		}	
75
-	}
74
+        }	
75
+    }
76 76
 		
77
-	// Prepare the whole text of the RSS file.
78
-	$rsstext = '<?xml version="1.0" encoding="utf-8"?>
77
+    // Prepare the whole text of the RSS file.
78
+    $rsstext = '<?xml version="1.0" encoding="utf-8"?>
79 79
 <rdf:RDF
80 80
   xmlns:dc="http://purl.org/dc/elements/1.1/"
81 81
   xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
@@ -101,15 +101,15 @@  discard block
 block discarded – undo
101 101
 
102 102
 </rdf:RDF>';
103 103
 		
104
-	// Write the text to the file...
105
-	$filename = $rsspath . $person_id . '.rdf';
106
-	$fh = @fopen($filename, "w");
107
-	if (!$fh) { # Problem writing, just carry on
108
-		echo "Could not write to file ($filename)\n";
109
-		continue;
110
-	}
111
-	fwrite($fh, $rsstext);
112
-	fclose ($fh);
104
+    // Write the text to the file...
105
+    $filename = $rsspath . $person_id . '.rdf';
106
+    $fh = @fopen($filename, "w");
107
+    if (!$fh) { # Problem writing, just carry on
108
+        echo "Could not write to file ($filename)\n";
109
+        continue;
110
+    }
111
+    fwrite($fh, $rsstext);
112
+    fclose ($fh);
113 113
 }
114 114
 
115 115
 #print "Took " . (time()-$starttime) . " seconds\n";
Please login to merge, or discard this patch.
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -3,13 +3,13 @@  discard block
 block discarded – undo
3 3
 // Generates the RSS feeds for currently sitting MPs.
4 4
 
5 5
 include '../www/includes/easyparliament/init.php';
6
-include_once INCLUDESPATH . 'easyparliament/member.php';
6
+include_once INCLUDESPATH.'easyparliament/member.php';
7 7
 
8 8
 // Where all the RSS feeds go.
9
-$rsspath = BASEDIR . '/rss/mp/';
9
+$rsspath = BASEDIR.'/rss/mp/';
10 10
 
11 11
 // Make things group writable.
12
-umask (002);
12
+umask(002);
13 13
 
14 14
 $HANSARDLIST = new HANSARDLIST();
15 15
 $db = $HANSARDLIST->db;
@@ -19,10 +19,10 @@  discard block
 block discarded – undo
19 19
 if ($q->rows() <= 0) exit;
20 20
 
21 21
 $starttime = time();
22
-for ($personrow=0; $personrow<$q->rows(); $personrow++) {
22
+for ($personrow = 0; $personrow < $q->rows(); $personrow++) {
23 23
 	$person_id = $q->field($personrow, 'person_id');
24 24
 
25
-	$args = array ( 'person_id' => $person_id );
25
+	$args = array('person_id' => $person_id);
26 26
 	$speeches = $HANSARDLIST->display('person', $args, 'none');
27 27
 		
28 28
 	// Some data about this person that we'll need for the feed.
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
 		
34 34
 	$date = gmdate('Y-m-d');
35 35
 	$time = gmdate('H:i:s');
36
-	$datenow = $date . 'T' . $time . '+00:00';
36
+	$datenow = $date.'T'.$time.'+00:00';
37 37
 		
38 38
 	// Prepare the meat of the RSS file.
39 39
 	$items = '';
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 			$title = _htmlentities(str_replace('&#8212;', '-', $row['parent']['body']));
48 48
 
49 49
 			$link = isset($row['listurl']) ? $row['listurl'] : '';
50
-			$link = 'https://' . DOMAIN . $link;
50
+			$link = 'https://'.DOMAIN.$link;
51 51
 				
52 52
 			$description = _htmlentities(trim_characters($row['body'], 0, 200));
53 53
 			$contentencoded = $row['body'];
@@ -59,9 +59,9 @@  discard block
 block discarded – undo
59 59
 				$htime = '00:00:00';
60 60
 			}
61 61
 				
62
-			$date = $hdate . 'T' . $htime . '+00:00';
62
+			$date = $hdate.'T'.$htime.'+00:00';
63 63
 				
64
-			$items .= '<rdf:li rdf:resource="' . $link . '" />' . "\n";
64
+			$items .= '<rdf:li rdf:resource="'.$link.'" />'."\n";
65 65
 			$entries .= "<item rdf:about=\"$link\">
66 66
 	<title>$title</title>
67 67
 	<link>$link</link>
@@ -82,34 +82,34 @@  discard block
 block discarded – undo
82 82
   xmlns="http://purl.org/rss/1.0/"
83 83
   xmlns:content="http://purl.org/rss/1.0/modules/content/">
84 84
 		
85
-<channel rdf:about="https://' . DOMAIN . $mpurl . '">
86
-<title>' . entities_to_numbers($MEMBER->full_name()) . '\'s recent appearances (TheyWorkForYou)</title>
87
-<link>https://' . DOMAIN . $mpurl . '</link>
85
+<channel rdf:about="https://' . DOMAIN.$mpurl.'">
86
+<title>' . entities_to_numbers($MEMBER->full_name()).'\'s recent appearances (TheyWorkForYou)</title>
87
+<link>https://' . DOMAIN.$mpurl.'</link>
88 88
 <description></description>
89 89
 <dc:language>en-gb</dc:language>
90 90
 <dc:creator>TheyWorkForYou.com</dc:creator>
91
-<dc:date>' . $datenow . '</dc:date>
91
+<dc:date>' . $datenow.'</dc:date>
92 92
 
93 93
 <items>
94 94
 <rdf:Seq>
95
-' . $items . '</rdf:Seq>
95
+' . $items.'</rdf:Seq>
96 96
 </items>
97 97
 
98 98
 </channel>
99 99
 
100
-' . $entries . '
100
+' . $entries.'
101 101
 
102 102
 </rdf:RDF>';
103 103
 		
104 104
 	// Write the text to the file...
105
-	$filename = $rsspath . $person_id . '.rdf';
105
+	$filename = $rsspath.$person_id.'.rdf';
106 106
 	$fh = @fopen($filename, "w");
107 107
 	if (!$fh) { # Problem writing, just carry on
108 108
 		echo "Could not write to file ($filename)\n";
109 109
 		continue;
110 110
 	}
111 111
 	fwrite($fh, $rsstext);
112
-	fclose ($fh);
112
+	fclose($fh);
113 113
 }
114 114
 
115 115
 #print "Took " . (time()-$starttime) . " seconds\n";
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -16,7 +16,9 @@
 block discarded – undo
16 16
 
17 17
 // Get all the person ids we need feeds for...
18 18
 $q = $db->query("SELECT person_id FROM member WHERE left_house='9999-12-31'");
19
-if ($q->rows() <= 0) exit;
19
+if ($q->rows() <= 0) {
20
+    exit;
21
+}
20 22
 
21 23
 $starttime = time();
22 24
 for ($personrow=0; $personrow<$q->rows(); $personrow++) {
Please login to merge, or discard this patch.
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -53,7 +53,7 @@
 block discarded – undo
53 53
 			$contentencoded = $row['body'];
54 54
 				
55 55
 			$hdate = format_date($row['hdate'], 'Y-m-d');
56
-			if ($row['htime'] != NULL) {
56
+			if ($row['htime'] != null) {
57 57
 				$htime = format_time($row['htime'], 'H:i:s');
58 58
 			} else {
59 59
 				$htime = '00:00:00';
Please login to merge, or discard this patch.
scripts/alertgonemps.php 4 patches
Indentation   +60 added lines, -60 removed lines patch added patch discarded remove patch
@@ -23,19 +23,19 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
Spacing   +10 added lines, -10 removed lines patch added patch discarded remove patch
@@ -11,7 +11,7 @@  discard block
 block discarded – undo
11 11
 
12 12
 include_once '../www/includes/easyparliament/init.php';
13 13
 ini_set('memory_limit', -1);
14
-include_once INCLUDESPATH . 'easyparliament/member.php';
14
+include_once INCLUDESPATH.'easyparliament/member.php';
15 15
 
16 16
 $global_start = getmicrotime();
17 17
 $db = new ParlDB;
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
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))
@@ -100,7 +100,7 @@  discard block
 block discarded – undo
100 100
 		if ($email_text)
101 101
             write_and_send_email($current, $email_text, $template);
102 102
 		$current['email'] = $email;
103
-		$current['token'] = $alertitem['alert_id'] . '-' . $alertitem['registrationtoken'];
103
+		$current['token'] = $alertitem['alert_id'].'-'.$alertitem['registrationtoken'];
104 104
 		$email_text = array();
105 105
 		$q = $db->query('SELECT user_id FROM users WHERE email = :email', array(
106 106
             ':email' => $email));
@@ -116,7 +116,7 @@  discard block
 block discarded – undo
116 116
 
117 117
     $lh = $member->left_house();
118 118
     $lh = array_shift($lh);
119
-    $text = '* ' . $member->full_name() . ', left ' . $lh['date_pretty'];
119
+    $text = '* '.$member->full_name().', left '.$lh['date_pretty'];
120 120
     if (!in_array($text, $email_text))
121 121
 	    $email_text[] = $text;
122 122
 }
@@ -131,9 +131,9 @@  discard block
 block discarded – undo
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
-mlog(date('r') . "\n");
136
+mlog(date('r')."\n");
137 137
 
138 138
 function write_and_send_email($current, $data, $template) {
139 139
 	global $globalsuccess, $sentemails, $nomail, $start_time;
@@ -143,15 +143,15 @@  discard block
 block discarded – undo
143 143
 	$d = array('to' => $current['email'], 'template' => $template);
144 144
 	$m = array(
145 145
 		'DATA' => join("\n", $data),
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',
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',
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
 		}
Please login to merge, or discard this patch.
Braces   +49 added lines, -24 removed lines patch added patch discarded remove patch
@@ -23,14 +23,18 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
@@ -160,6 +183,8 @@  discard block
 block discarded – undo
160 183
 		$success = 1;
161 184
 	}
162 185
 	mlog("done\n");
163
-	if (!$success) $globalsuccess = 0;
164
-}
186
+	if (!$success) {
187
+	    $globalsuccess = 0;
188
+	}
189
+	}
165 190
 
Please login to merge, or discard this patch.
Upper-Lower-Casing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -139,7 +139,7 @@
 block discarded – undo
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),
Please login to merge, or discard this patch.
scripts/video-speed.php 2 patches
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -26,9 +26,13 @@
 block discarded – undo
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);
Please login to merge, or discard this patch.
tests/MemberTest.php 1 patch
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -325,10 +325,10 @@  discard block
 block discarded – undo
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
 block discarded – undo
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",
Please login to merge, or discard this patch.
tests/FetchPageTestCase.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
     protected function base_fetch_page($vars, $dir, $page = 'index.php', $req_uri = '')
10 10
     {
11 11
         foreach ($vars as $k => $v) {
12
-            $vars[$k] =  $k . '=' . urlencode($v);
12
+            $vars[$k] = $k.'='.urlencode($v);
13 13
         }
14 14
 
15 15
         if (!$req_uri) {
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
         }
18 18
 
19 19
         $vars = join('&', $vars);
20
-        $command = 'parse_str($argv[1], $_GET); include_once("tests/Bootstrap.php"); chdir("www/docs/' . $dir . '"); include_once("' . $page . '");';
20
+        $command = 'parse_str($argv[1], $_GET); include_once("tests/Bootstrap.php"); chdir("www/docs/'.$dir.'"); include_once("'.$page.'");';
21 21
         $page = `REQUEST_URI=$req_uri REMOTE_ADDR=127.0.0.1 php -e -r '$command' -- '$vars'`;
22 22
 
23 23
         return $page;
Please login to merge, or discard this patch.
tests/PostcodeTest.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -18,7 +18,7 @@
 block discarded – undo
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',
Please login to merge, or discard this patch.
tests/AlertsPageTest.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -21,37 +21,37 @@
 block discarded – undo
21 21
 
22 22
     public function testFetchPage()
23 23
     {
24
-        $page = $this->fetch_page( array() );
24
+        $page = $this->fetch_page(array());
25 25
         $this->assertContains('TheyWorkForYou Email Alerts', $page);
26 26
     }
27 27
 
28 28
     public function testKeywordOnly() {
29
-        $page = $this->fetch_page( array( 'alertsearch' => 'elephant') );
29
+        $page = $this->fetch_page(array('alertsearch' => 'elephant'));
30 30
         $this->assertContains('Receive alerts when [elephant] is mentioned', $page);
31 31
     }
32 32
 
33 33
     public function testPostCodeOnly() {
34
-        $page = $this->fetch_page( array( 'alertsearch' => 'SE17 3HE') );
34
+        $page = $this->fetch_page(array('alertsearch' => 'SE17 3HE'));
35 35
         $this->assertContains('when Mrs Test Current-MP', $page);
36 36
     }
37 37
 
38 38
     public function testPostCodeWithKeyWord()
39 39
     {
40
-        $page = $this->fetch_page( array( 'alertsearch' => 'SE17 3HE elephant') );
40
+        $page = $this->fetch_page(array('alertsearch' => 'SE17 3HE elephant'));
41 41
         $this->assertContains('You have used a postcode and something else', $page);
42 42
         $this->assertContains('Mentions of [elephant] by Mrs Test Current-MP', $page);
43 43
         $this->assertNotContains('by your MSP', $page);
44 44
     }
45 45
 
46 46
     public function testScottishPostcodeWithKeyword() {
47
-        $page = $this->fetch_page( array( 'alertsearch' => 'PH6 2DB elephant') );
47
+        $page = $this->fetch_page(array('alertsearch' => 'PH6 2DB elephant'));
48 48
         $this->assertContains('You have used a postcode and something else', $page);
49 49
         $this->assertContains('Mentions of [elephant] by your MP, Mr Test2 Current-MP', $page);
50 50
         $this->assertContains('Mentions of [elephant] by your MSP, Mrs Test Current-MSP', $page);
51 51
     }
52 52
 
53 53
     public function testPostcodeAndKeywordWithNoSittingMP() {
54
-        $page = $this->fetch_page( array( 'alertsearch' => 'OX1 4LF elephant') );
54
+        $page = $this->fetch_page(array('alertsearch' => 'OX1 4LF elephant'));
55 55
         $this->assertContains('You have used a postcode and something else', $page);
56 56
         $this->assertNotContains('Did you mean to get alerts for when your MP', $page);
57 57
     }
Please login to merge, or discard this patch.
tests/DivisionsTest.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
 
9 9
     public function getDataSet()
10 10
     {
11
-        return $this->createMySQLXMLDataSet(dirname(__FILE__) . '/_fixtures/divisions.xml');
11
+        return $this->createMySQLXMLDataSet(dirname(__FILE__).'/_fixtures/divisions.xml');
12 12
     }
13 13
 
14 14
     private function fetch_page($vars)
@@ -17,17 +17,17 @@  discard block
 block discarded – undo
17 17
     }
18 18
 
19 19
     private function fetch_division_page() {
20
-        return $this->fetch_page( array( 'pagetype' => 'divisions', 'pid' => 2, 'policy' => 363, 'url' => '/mp/2/test_current-mp/test_westminster_constituency/divisions' ) );
20
+        return $this->fetch_page(array('pagetype' => 'divisions', 'pid' => 2, 'policy' => 363, 'url' => '/mp/2/test_current-mp/test_westminster_constituency/divisions'));
21 21
     }
22 22
 
23 23
     private function fetch_mp_recent_page()
24 24
     {
25
-        $vars = array( 'pagetype' => 'recent', 'pid' => 2, 'url' => '/mp/2/test_current-mp/test_westminster_constituency/recent' );
25
+        $vars = array('pagetype' => 'recent', 'pid' => 2, 'url' => '/mp/2/test_current-mp/test_westminster_constituency/recent');
26 26
         return $this->base_fetch_page($vars, 'mp', 'index.php', '/mp/recent.php');
27 27
     }
28 28
 
29 29
     private function fetch_recent_page() {
30
-        return $this->base_fetch_page( array('url' => '/divisions' ), 'divisions', 'index.php', '/divisions/index.php' );
30
+        return $this->base_fetch_page(array('url' => '/divisions'), 'divisions', 'index.php', '/divisions/index.php');
31 31
     }
32 32
 
33 33
 
@@ -113,7 +113,7 @@  discard block
 block discarded – undo
113 113
     }
114 114
 
115 115
     public function testNotEnoughInfoStatement() {
116
-        return $this->fetch_page( array( 'pagetype' => 'divisions', 'pid' => 2, 'policy' => 810, 'url' => '/mp/2/test_current-mp/test_westminster_constituency/divisions' ) );
116
+        return $this->fetch_page(array('pagetype' => 'divisions', 'pid' => 2, 'policy' => 810, 'url' => '/mp/2/test_current-mp/test_westminster_constituency/divisions'));
117 117
         $this->assertContains('we don&rsquo;t have enough information to calculate Test Current-MP&rsquo;s position', $page);
118 118
     }
119 119
 
@@ -124,7 +124,7 @@  discard block
 block discarded – undo
124 124
     }
125 125
 
126 126
     public function testSingleDivision() {
127
-        $page = $this->base_fetch_page( array('url' => '/divisions/division.php', 'vote' => 'pw-3012-01-01-1-commons' ), 'divisions', 'division.php', '/divisions/division.php' );
127
+        $page = $this->base_fetch_page(array('url' => '/divisions/division.php', 'vote' => 'pw-3012-01-01-1-commons'), 'divisions', 'division.php', '/divisions/division.php');
128 128
         $this->assertContains('A majority of MPs  <b>voted in favour</b> of a thing', $page);
129 129
         $this->assertContains('198 for', $page);
130 130
         $this->assertContains('98 against', $page);
Please login to merge, or discard this patch.