Completed
Push — sessionstart ( 52a658 )
by Simon
03:37
created
PrecacheGeolocation.php 3 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -63,12 +63,12 @@
 block discarded – undo
63 63
         $database->commit();
64 64
         echo ". Committed txn.\n";
65 65
     } catch (Exception $ex) {
66
-        echo ". Encountered exception: " . $ex->getMessage(). "\n";
66
+        echo ". Encountered exception: ".$ex->getMessage()."\n";
67 67
         $database->rollBack();
68 68
         echo ". Rolled back txn\n";
69 69
         throw $ex;
70 70
     } finally {
71
-        if($database->hasActiveTransaction()){
71
+        if ($database->hasActiveTransaction()) {
72 72
             $database->rollBack();
73 73
             echo ". Rolled back txn\n";
74 74
         }
Please login to merge, or discard this patch.
Braces   +5 added lines, -3 removed lines patch added patch discarded remove patch
@@ -62,13 +62,15 @@
 block discarded – undo
62 62
         echo ". IP location fetch complete.\n";
63 63
         $database->commit();
64 64
         echo ". Committed txn.\n";
65
-    } catch (Exception $ex) {
65
+    }
66
+    catch (Exception $ex) {
66 67
         echo ". Encountered exception: " . $ex->getMessage(). "\n";
67 68
         $database->rollBack();
68 69
         echo ". Rolled back txn\n";
69 70
         throw $ex;
70
-    } finally {
71
-        if($database->hasActiveTransaction()){
71
+    }
72
+    finally {
73
+        if($database->hasActiveTransaction()) {
72 74
             $database->rollBack();
73 75
             echo ". Rolled back txn\n";
74 76
         }
Please login to merge, or discard this patch.
Indentation   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 
3 3
 if (isset($_SERVER['REQUEST_METHOD'])) {
4
-    die();
4
+	die();
5 5
 } // Web clients die.
6 6
 
7 7
 ini_set('display_errors', 1);
@@ -17,19 +17,19 @@  discard block
 block discarded – undo
17 17
 $locationProvider = new IpLocationProvider($database, $locationProviderApiKey);
18 18
 
19 19
 while (true) {
20
-    echo "Beginning txn\n";
21
-    $database->beginTransaction();
20
+	echo "Beginning txn\n";
21
+	$database->beginTransaction();
22 22
 
23
-    try {
24
-        // fetch a bunch of un-geolocated IPs from the database.
25
-        // note we have to parse the forwardedip field in the database so we can test against the geolocation table.
26
-        // This guarantees we get ten unlocated IPs back, unless there actually aren't 10 available.
27
-        // Alternatives include downloading a small set of forwarded IPs, splitting it in PHP, constructing an IN()
28
-        // clause dynamically, sending that back to the database to check if there are geolocation entries, then repeating
29
-        // until we have 10 to process - and the fact that we'd have to potentially retrieve all IPs from the database
30
-        // before we find any at all. This way keeps all of that legwork in the database, at the cost of a more complex
31
-        // query.
32
-        $statement = $database->query(<<<SQL
23
+	try {
24
+		// fetch a bunch of un-geolocated IPs from the database.
25
+		// note we have to parse the forwardedip field in the database so we can test against the geolocation table.
26
+		// This guarantees we get ten unlocated IPs back, unless there actually aren't 10 available.
27
+		// Alternatives include downloading a small set of forwarded IPs, splitting it in PHP, constructing an IN()
28
+		// clause dynamically, sending that back to the database to check if there are geolocation entries, then repeating
29
+		// until we have 10 to process - and the fact that we'd have to potentially retrieve all IPs from the database
30
+		// before we find any at all. This way keeps all of that legwork in the database, at the cost of a more complex
31
+		// query.
32
+		$statement = $database->query(<<<SQL
33 33
             SELECT p.prox
34 34
             FROM (
35 35
               SELECT trim(substring_index(substring_index(r.forwardedip, ',', n.n), ',', -1)) prox
@@ -46,38 +46,38 @@  discard block
 block discarded – undo
46 46
             WHERE NOT EXISTS (SELECT 1 FROM geolocation g WHERE g.address = p.prox)
47 47
             LIMIT 10;
48 48
 SQL
49
-        );
49
+		);
50 50
 
51
-        $missingIps = $statement->fetchAll(PDO::FETCH_COLUMN);
51
+		$missingIps = $statement->fetchAll(PDO::FETCH_COLUMN);
52 52
 
53
-        $count = count($missingIps);
54
-        if ($count === 0) {
55
-            echo ". Found nothing to do.\n";
56
-            break;
57
-        }
53
+		$count = count($missingIps);
54
+		if ($count === 0) {
55
+			echo ". Found nothing to do.\n";
56
+			break;
57
+		}
58 58
 
59
-        echo ". Picked {$count} IP addresses\n";
59
+		echo ". Picked {$count} IP addresses\n";
60 60
 
61
-        foreach ($missingIps as $ip) {
62
-            echo ". . Getting location for {$ip}...\n";
63
-            $data = json_encode($locationProvider->getIpLocation($ip));
64
-            echo ". . . {$data}\n";
65
-        }
61
+		foreach ($missingIps as $ip) {
62
+			echo ". . Getting location for {$ip}...\n";
63
+			$data = json_encode($locationProvider->getIpLocation($ip));
64
+			echo ". . . {$data}\n";
65
+		}
66 66
 
67
-        echo ". IP location fetch complete.\n";
68
-        $database->commit();
69
-        echo ". Committed txn.\n";
70
-    } catch (Exception $ex) {
71
-        echo ". Encountered exception: " . $ex->getMessage(). "\n";
72
-        $database->rollBack();
73
-        echo ". Rolled back txn\n";
74
-        throw $ex;
75
-    } finally {
76
-        if($database->hasActiveTransaction()){
77
-            $database->rollBack();
78
-            echo ". Rolled back txn\n";
79
-        }
80
-    }
67
+		echo ". IP location fetch complete.\n";
68
+		$database->commit();
69
+		echo ". Committed txn.\n";
70
+	} catch (Exception $ex) {
71
+		echo ". Encountered exception: " . $ex->getMessage(). "\n";
72
+		$database->rollBack();
73
+		echo ". Rolled back txn\n";
74
+		throw $ex;
75
+	} finally {
76
+		if($database->hasActiveTransaction()){
77
+			$database->rollBack();
78
+			echo ". Rolled back txn\n";
79
+		}
80
+	}
81 81
 }
82 82
 
83 83
 echo "Done.\n";
Please login to merge, or discard this patch.