Passed
Push — master ( 5a5c41...fade3b )
by Cody
04:50 queued 10s
created
plugins/af_psql_trgm/init.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@  discard block
 block discarded – undo
41 41
 	}
42 42
 
43 43
 	public function get_js() {
44
-		return file_get_contents(__DIR__ . "/init.js");
44
+		return file_get_contents(__DIR__."/init.js");
45 45
 	}
46 46
 
47 47
 	public function showrelated() {
@@ -98,7 +98,7 @@  discard block
 block discarded – undo
98 98
 
99 99
 				print "</div>";
100 100
 
101
-				print "<div style='text-align : right' class='text-muted'>" . smart_date_time(strtotime($line["updated"])) . "</div>";
101
+				print "<div style='text-align : right' class='text-muted'>".smart_date_time(strtotime($line["updated"]))."</div>";
102 102
 
103 103
 				print "</li>";
104 104
 			}
@@ -163,24 +163,24 @@  discard block
 block discarded – undo
163 163
 			print_hidden("method", "save");
164 164
 			print_hidden("plugin", "af_psql_trgm");
165 165
 
166
-			print "<h2>" . __("Global settings") . "</h2>";
166
+			print "<h2>".__("Global settings")."</h2>";
167 167
 
168 168
 			print_notice("Enable for specific feeds in the feed editor.");
169 169
 
170 170
 			print "<fieldset>";
171 171
 
172
-			print "<label>" . __("Minimum similarity:") . "</label> ";
172
+			print "<label>".__("Minimum similarity:")."</label> ";
173 173
 			print "<input dojoType=\"dijit.form.NumberSpinner\"
174 174
 				placeholder=\"0.75\" id='psql_trgm_similarity'
175 175
 				required=\"1\" name=\"similarity\" value=\"$similarity\">";
176 176
 
177
-			print "<div dojoType='dijit.Tooltip' connectId='psql_trgm_similarity' position='below'>" .
178
-				__("PostgreSQL trigram extension returns string similarity as a floating point number (0-1). Setting it too low might produce false positives, zero disables checking.") .
177
+			print "<div dojoType='dijit.Tooltip' connectId='psql_trgm_similarity' position='below'>".
178
+				__("PostgreSQL trigram extension returns string similarity as a floating point number (0-1). Setting it too low might produce false positives, zero disables checking.").
179 179
 				"</div>";
180 180
 
181 181
 			print "</fieldset><fieldset>";
182 182
 
183
-			print "<label>" . __("Minimum title length:") . "</label> ";
183
+			print "<label>".__("Minimum title length:")."</label> ";
184 184
 			print "<input dojoType=\"dijit.form.NumberSpinner\"
185 185
 				placeholder=\"32\"
186 186
 				required=\"1\" name=\"min_title_length\" value=\"$min_title_length\">";
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 
190 190
 			print "<label class='checkbox'>";
191 191
 			print_checkbox("enable_globally", $enable_globally);
192
-			print " " . __("Enable for all feeds:");
192
+			print " ".__("Enable for all feeds:");
193 193
 			print "</label>";
194 194
 
195 195
 			print "</fieldset>";
@@ -204,14 +204,14 @@  discard block
 block discarded – undo
204 204
 			$this->host->set($this, "enabled_feeds", $enabled_feeds);
205 205
 
206 206
 			if (count($enabled_feeds) > 0) {
207
-				print "<h3>" . __("Currently enabled for (click to edit):") . "</h3>";
207
+				print "<h3>".__("Currently enabled for (click to edit):")."</h3>";
208 208
 
209 209
 				print "<ul class=\"panel panel-scrollable list list-unstyled\">";
210 210
 				foreach ($enabled_feeds as $f) {
211
-					print "<li>" .
211
+					print "<li>".
212 212
 						"<i class='material-icons'>rss_feed</i> <a href='#'
213
-							onclick='CommonDialogs.editFeed($f)'>" .
214
-						Feeds::getFeedTitle($f) . "</a></li>";
213
+							onclick='CommonDialogs.editFeed($f)'>".
214
+						Feeds::getFeedTitle($f)."</a></li>";
215 215
 				}
216 216
 				print "</ul>";
217 217
 			}
Please login to merge, or discard this patch.
Braces   +42 added lines, -14 removed lines patch added patch discarded remove patch
@@ -15,10 +15,16 @@  discard block
 block discarded – undo
15 15
 		$min_title_length = (int) $_POST["min_title_length"];
16 16
 		$enable_globally = checkbox_to_sql_bool($_POST["enable_globally"]);
17 17
 
18
-		if ($similarity < 0) $similarity = 0;
19
-		if ($similarity > 1) $similarity = 1;
18
+		if ($similarity < 0) {
19
+			$similarity = 0;
20
+		}
21
+		if ($similarity > 1) {
22
+			$similarity = 1;
23
+		}
20 24
 
21
-		if ($min_title_length < 0) $min_title_length = 0;
25
+		if ($min_title_length < 0) {
26
+			$min_title_length = 0;
27
+		}
22 28
 
23 29
 		$similarity = sprintf("%.2f", $similarity);
24 30
 
@@ -121,7 +127,9 @@  discard block
 block discarded – undo
121 127
 	}
122 128
 
123 129
 	public function hook_prefs_tab($args) {
124
-		if ($args != "prefFeeds") return;
130
+		if ($args != "prefFeeds") {
131
+			return;
132
+		}
125 133
 
126 134
 		print "<div dojoType=\"dijit.layout.AccordionPane\"
127 135
 			title=\"<i class='material-icons'>extension</i> ".__('Mark similar articles as read')."\">";
@@ -140,8 +148,12 @@  discard block
 block discarded – undo
140 148
 			$min_title_length = $this->host->get($this, "min_title_length");
141 149
 			$enable_globally = $this->host->get($this, "enable_globally");
142 150
 
143
-			if (!$similarity) $similarity = '0.75';
144
-			if (!$min_title_length) $min_title_length = '32';
151
+			if (!$similarity) {
152
+				$similarity = '0.75';
153
+			}
154
+			if (!$min_title_length) {
155
+				$min_title_length = '32';
156
+			}
145 157
 
146 158
 			print "<form dojoType=\"dijit.form.Form\">";
147 159
 
@@ -198,7 +210,9 @@  discard block
 block discarded – undo
198 210
 			print "</form>";
199 211
 
200 212
 			$enabled_feeds = $this->host->get($this, "enabled_feeds");
201
-			if (!array($enabled_feeds)) $enabled_feeds = array();
213
+			if (!array($enabled_feeds)) {
214
+				$enabled_feeds = array();
215
+			}
202 216
 
203 217
 			$enabled_feeds = $this->filter_unknown_feeds($enabled_feeds);
204 218
 			$this->host->set($this, "enabled_feeds", $enabled_feeds);
@@ -225,7 +239,9 @@  discard block
 block discarded – undo
225 239
 		print "<section>";
226 240
 
227 241
 		$enabled_feeds = $this->host->get($this, "enabled_feeds");
228
-		if (!array($enabled_feeds)) $enabled_feeds = array();
242
+		if (!array($enabled_feeds)) {
243
+			$enabled_feeds = array();
244
+		}
229 245
 
230 246
 		$key = array_search($feed_id, $enabled_feeds);
231 247
 		$checked = $key !== FALSE ? "checked" : "";
@@ -242,7 +258,9 @@  discard block
 block discarded – undo
242 258
 
243 259
 	public function hook_prefs_save_feed($feed_id) {
244 260
 		$enabled_feeds = $this->host->get($this, "enabled_feeds");
245
-		if (!is_array($enabled_feeds)) $enabled_feeds = array();
261
+		if (!is_array($enabled_feeds)) {
262
+			$enabled_feeds = array();
263
+		}
246 264
 
247 265
 		$enable = checkbox_to_sql_bool($_POST["trgm_similarity_enabled"]);
248 266
 		$key = array_search($feed_id, $enabled_feeds);
@@ -262,24 +280,34 @@  discard block
 block discarded – undo
262 280
 
263 281
 	public function hook_article_filter($article) {
264 282
 
265
-		if (DB_TYPE != "pgsql") return $article;
283
+		if (DB_TYPE != "pgsql") {
284
+			return $article;
285
+		}
266 286
 
267 287
 		$res = $this->pdo->query("select 'similarity'::regproc");
268
-		if (!$res->fetch()) return $article;
288
+		if (!$res->fetch()) {
289
+			return $article;
290
+		}
269 291
 
270 292
 		$enable_globally = $this->host->get($this, "enable_globally");
271 293
 
272 294
 		if (!$enable_globally) {
273 295
 			$enabled_feeds = $this->host->get($this, "enabled_feeds");
274 296
 			$key = array_search($article["feed"]["id"], $enabled_feeds);
275
-			if ($key === FALSE) return $article;
297
+			if ($key === FALSE) {
298
+				return $article;
299
+			}
276 300
 		}
277 301
 
278 302
 		$similarity = (float) $this->host->get($this, "similarity");
279
-		if ($similarity < 0.01) return $article;
303
+		if ($similarity < 0.01) {
304
+			return $article;
305
+		}
280 306
 
281 307
 		$min_title_length = (int) $this->host->get($this, "min_title_length");
282
-		if (mb_strlen($article["title"]) < $min_title_length) return $article;
308
+		if (mb_strlen($article["title"]) < $min_title_length) {
309
+			return $article;
310
+		}
283 311
 
284 312
 		$owner_uid = $article["owner_uid"];
285 313
 		$entry_guid = $article["guid_hashed"];
Please login to merge, or discard this patch.
plugins/toggle_sidebar/init.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@
 block discarded – undo
16 16
 	}
17 17
 
18 18
 	public function get_js() {
19
-		return file_get_contents(__DIR__ . "/init.js");
19
+		return file_get_contents(__DIR__."/init.js");
20 20
 	}
21 21
 
22 22
 	public function hook_main_toolbar_button() {
Please login to merge, or discard this patch.
api/index.php 3 patches
Indentation   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -5,9 +5,9 @@  discard block
 block discarded – undo
5 5
 require_once "..".DIRECTORY_SEPARATOR."config.php";
6 6
 
7 7
 set_include_path(dirname(__FILE__).PATH_SEPARATOR.
8
-    dirname(dirname(__FILE__)).PATH_SEPARATOR.
9
-    dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR."include".PATH_SEPARATOR.
10
-    get_include_path());
8
+	dirname(dirname(__FILE__)).PATH_SEPARATOR.
9
+	dirname(dirname(__FILE__)).DIRECTORY_SEPARATOR."include".PATH_SEPARATOR.
10
+	get_include_path());
11 11
 
12 12
 chdir("..");
13 13
 
@@ -24,33 +24,33 @@  discard block
 block discarded – undo
24 24
 ini_set("session.gc_maxlifetime", 86400);
25 25
 
26 26
 if (defined('ENABLE_GZIP_OUTPUT') && ENABLE_GZIP_OUTPUT &&
27
-        function_exists("ob_gzhandler")) {
27
+		function_exists("ob_gzhandler")) {
28 28
 
29
-    ob_start("ob_gzhandler");
29
+	ob_start("ob_gzhandler");
30 30
 } else {
31
-    ob_start();
31
+	ob_start();
32 32
 }
33 33
 
34 34
 $input = file_get_contents("php://input");
35 35
 
36 36
 if (defined('_API_DEBUG_HTTP_ENABLED') && _API_DEBUG_HTTP_ENABLED) {
37
-    // Override $_REQUEST with JSON-encoded data if available
38
-    // fallback on HTTP parameters
39
-    if ($input) {
40
-        $input = json_decode($input, true);
41
-        if ($input) $_REQUEST = $input;
42
-    }
37
+	// Override $_REQUEST with JSON-encoded data if available
38
+	// fallback on HTTP parameters
39
+	if ($input) {
40
+		$input = json_decode($input, true);
41
+		if ($input) $_REQUEST = $input;
42
+	}
43 43
 } else {
44
-    // Accept JSON only
45
-    $input = json_decode($input, true);
46
-    $_REQUEST = $input;
44
+	// Accept JSON only
45
+	$input = json_decode($input, true);
46
+	$_REQUEST = $input;
47 47
 }
48 48
 
49 49
 if ($_REQUEST["sid"]) {
50
-    session_id($_REQUEST["sid"]);
51
-    @session_start();
50
+	session_id($_REQUEST["sid"]);
51
+	@session_start();
52 52
 } else if (defined('_API_DEBUG_HTTP_ENABLED')) {
53
-    @session_start();
53
+	@session_start();
54 54
 }
55 55
 
56 56
 startup_gettext();
@@ -58,17 +58,17 @@  discard block
 block discarded – undo
58 58
 if (!init_plugins()) return;
59 59
 
60 60
 if ($_SESSION["uid"]) {
61
-    if (!validate_session()) {
62
-        header("Content-Type: text/json");
61
+	if (!validate_session()) {
62
+		header("Content-Type: text/json");
63 63
 
64
-        print json_encode(array("seq" => -1,
65
-            "status" => 1,
66
-            "content" => array("error" => "NOT_LOGGED_IN")));
64
+		print json_encode(array("seq" => -1,
65
+			"status" => 1,
66
+			"content" => array("error" => "NOT_LOGGED_IN")));
67 67
 
68
-        return;
69
-    }
68
+		return;
69
+	}
70 70
 
71
-    load_user_plugins( $_SESSION["uid"]);
71
+	load_user_plugins( $_SESSION["uid"]);
72 72
 }
73 73
 
74 74
 $method = strtolower($_REQUEST["op"]);
@@ -76,12 +76,12 @@  discard block
 block discarded – undo
76 76
 $handler = new API($_REQUEST);
77 77
 
78 78
 if ($handler->before($method)) {
79
-    if ($method && method_exists($handler, $method)) {
80
-        $handler->$method();
81
-    } else if (method_exists($handler, 'index')) {
82
-        $handler->index($method);
83
-    }
84
-    $handler->after();
79
+	if ($method && method_exists($handler, $method)) {
80
+		$handler->$method();
81
+	} else if (method_exists($handler, 'index')) {
82
+		$handler->index($method);
83
+	}
84
+	$handler->after();
85 85
 }
86 86
 
87 87
 header("Api-Content-Length: " . ob_get_length());
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
         return;
69 69
     }
70 70
 
71
-    load_user_plugins( $_SESSION["uid"]);
71
+    load_user_plugins($_SESSION["uid"]);
72 72
 }
73 73
 
74 74
 $method = strtolower($_REQUEST["op"]);
@@ -84,6 +84,6 @@  discard block
 block discarded – undo
84 84
     $handler->after();
85 85
 }
86 86
 
87
-header("Api-Content-Length: " . ob_get_length());
87
+header("Api-Content-Length: ".ob_get_length());
88 88
 
89 89
 ob_end_flush();
Please login to merge, or discard this patch.
Braces   +6 added lines, -2 removed lines patch added patch discarded remove patch
@@ -38,7 +38,9 @@  discard block
 block discarded – undo
38 38
     // fallback on HTTP parameters
39 39
     if ($input) {
40 40
         $input = json_decode($input, true);
41
-        if ($input) $_REQUEST = $input;
41
+        if ($input) {
42
+        	$_REQUEST = $input;
43
+        }
42 44
     }
43 45
 } else {
44 46
     // Accept JSON only
@@ -55,7 +57,9 @@  discard block
 block discarded – undo
55 57
 
56 58
 startup_gettext();
57 59
 
58
-if (!init_plugins()) return;
60
+if (!init_plugins()) {
61
+	return;
62
+}
59 63
 
60 64
 if ($_SESSION["uid"]) {
61 65
     if (!validate_session()) {
Please login to merge, or discard this patch.
update_daemon2.php 2 patches
Indentation   +138 added lines, -138 removed lines patch added patch discarded remove patch
@@ -1,7 +1,7 @@  discard block
 block discarded – undo
1 1
 #!/usr/bin/env php
2 2
 <?php
3 3
 set_include_path(dirname(__FILE__) .DIRECTORY_SEPARATOR."include" . PATH_SEPARATOR .
4
-    get_include_path());
4
+	get_include_path());
5 5
 
6 6
 declare(ticks = 1);
7 7
 chdir(dirname(__FILE__));
@@ -23,16 +23,16 @@  discard block
 block discarded – undo
23 23
 require_once "db-prefs.php";
24 24
 
25 25
 if (!function_exists('pcntl_fork')) {
26
-    die("error: This script requires PHP compiled with PCNTL module.\n");
26
+	die("error: This script requires PHP compiled with PCNTL module.\n");
27 27
 }
28 28
 
29 29
 $options = getopt("");
30 30
 
31 31
 if (!is_array($options)) {
32
-    die("error: getopt() failed. ".
33
-        "Most probably you are using PHP CGI to run this script ".
34
-        "instead of required PHP CLI. Check tt-rss wiki page on updating feeds for ".
35
-        "additional information.\n");
32
+	die("error: getopt() failed. ".
33
+		"Most probably you are using PHP CGI to run this script ".
34
+		"instead of required PHP CLI. Check tt-rss wiki page on updating feeds for ".
35
+		"additional information.\n");
36 36
 }
37 37
 
38 38
 
@@ -44,137 +44,137 @@  discard block
 block discarded – undo
44 44
 $last_checkpoint = -1;
45 45
 
46 46
 function reap_children() {
47
-    global $children;
48
-    global $ctimes;
47
+	global $children;
48
+	global $ctimes;
49 49
 
50
-    $tmp = array();
50
+	$tmp = array();
51 51
 
52
-    foreach ($children as $pid) {
53
-        if (pcntl_waitpid($pid, $status, WNOHANG) != $pid) {
52
+	foreach ($children as $pid) {
53
+		if (pcntl_waitpid($pid, $status, WNOHANG) != $pid) {
54 54
 
55
-            if (file_is_locked("update_daemon-$pid.lock")) {
56
-                array_push($tmp, $pid);
57
-            } else {
58
-                Debug::log("[reap_children] child $pid seems active but lockfile is unlocked.");
59
-                unset($ctimes[$pid]);
55
+			if (file_is_locked("update_daemon-$pid.lock")) {
56
+				array_push($tmp, $pid);
57
+			} else {
58
+				Debug::log("[reap_children] child $pid seems active but lockfile is unlocked.");
59
+				unset($ctimes[$pid]);
60 60
 
61
-            }
62
-        } else {
63
-            Debug::log("[reap_children] child $pid reaped.");
64
-            unset($ctimes[$pid]);
65
-        }
66
-    }
61
+			}
62
+		} else {
63
+			Debug::log("[reap_children] child $pid reaped.");
64
+			unset($ctimes[$pid]);
65
+		}
66
+	}
67 67
 
68
-    $children = $tmp;
68
+	$children = $tmp;
69 69
 
70
-    return count($tmp);
70
+	return count($tmp);
71 71
 }
72 72
 
73 73
 function check_ctimes() {
74
-    global $ctimes;
74
+	global $ctimes;
75 75
 
76
-    foreach (array_keys($ctimes) as $pid) {
77
-        $started = $ctimes[$pid];
76
+	foreach (array_keys($ctimes) as $pid) {
77
+		$started = $ctimes[$pid];
78 78
 
79
-        if (time() - $started > MAX_CHILD_RUNTIME) {
80
-            Debug::log("[MASTER] child process $pid seems to be stuck, aborting...");
81
-            posix_kill($pid, SIGKILL);
82
-        }
83
-    }
79
+		if (time() - $started > MAX_CHILD_RUNTIME) {
80
+			Debug::log("[MASTER] child process $pid seems to be stuck, aborting...");
81
+			posix_kill($pid, SIGKILL);
82
+		}
83
+	}
84 84
 }
85 85
 
86 86
 function sigchld_handler($signal) {
87
-    $running_jobs = reap_children();
87
+	$running_jobs = reap_children();
88 88
 
89
-    Debug::log("[SIGCHLD] jobs left: $running_jobs");
89
+	Debug::log("[SIGCHLD] jobs left: $running_jobs");
90 90
 
91
-    pcntl_waitpid(-1, $status, WNOHANG);
91
+	pcntl_waitpid(-1, $status, WNOHANG);
92 92
 }
93 93
 
94 94
 function shutdown($caller_pid) {
95
-    if ($caller_pid == posix_getpid()) {
96
-        if (file_exists(LOCK_DIRECTORY . "/update_daemon.lock")) {
97
-            Debug::log("removing lockfile (master)...");
98
-            unlink(LOCK_DIRECTORY . "/update_daemon.lock");
99
-        }
100
-    }
95
+	if ($caller_pid == posix_getpid()) {
96
+		if (file_exists(LOCK_DIRECTORY . "/update_daemon.lock")) {
97
+			Debug::log("removing lockfile (master)...");
98
+			unlink(LOCK_DIRECTORY . "/update_daemon.lock");
99
+		}
100
+	}
101 101
 }
102 102
 
103 103
 function task_shutdown() {
104
-    $pid = posix_getpid();
104
+	$pid = posix_getpid();
105 105
 
106
-    if (file_exists(LOCK_DIRECTORY . "/update_daemon-$pid.lock")) {
107
-        Debug::log("removing lockfile ($pid)...");
108
-        unlink(LOCK_DIRECTORY . "/update_daemon-$pid.lock");
109
-    }
106
+	if (file_exists(LOCK_DIRECTORY . "/update_daemon-$pid.lock")) {
107
+		Debug::log("removing lockfile ($pid)...");
108
+		unlink(LOCK_DIRECTORY . "/update_daemon-$pid.lock");
109
+	}
110 110
 }
111 111
 
112 112
 function sigint_handler() {
113
-    Debug::log("[MASTER] SIG_INT received.\n");
114
-    shutdown(posix_getpid());
115
-    die;
113
+	Debug::log("[MASTER] SIG_INT received.\n");
114
+	shutdown(posix_getpid());
115
+	die;
116 116
 }
117 117
 
118 118
 function task_sigint_handler() {
119
-    Debug::log("[TASK] SIG_INT received.\n");
120
-    task_shutdown();
121
-    die;
119
+	Debug::log("[TASK] SIG_INT received.\n");
120
+	task_shutdown();
121
+	die;
122 122
 }
123 123
 
124 124
 pcntl_signal(SIGCHLD, 'sigchld_handler');
125 125
 
126 126
 $longopts = array(
127
-    "log:",
128
-    "log-level:",
129
-    "tasks:",
130
-    "interval:",
131
-    "quiet",
132
-    "help"
127
+	"log:",
128
+	"log-level:",
129
+	"tasks:",
130
+	"interval:",
131
+	"quiet",
132
+	"help"
133 133
 );
134 134
 
135 135
 $options = getopt("", $longopts);
136 136
 
137 137
 if (isset($options["help"]) ) {
138
-    print "Tiny Tiny RSS update daemon.\n\n";
139
-    print "Options:\n";
140
-    print "  --log FILE           - log messages to FILE\n";
141
-    print "  --log-level N        - log verbosity level\n";
142
-    print "  --tasks N            - amount of update tasks to spawn\n";
143
-    print "                         default: " . MAX_JOBS . "\n";
144
-    print "  --interval N         - task spawn interval\n";
145
-    print "                         default: " . SPAWN_INTERVAL . " seconds.\n";
146
-    print "  --quiet              - don't output messages to stdout\n";
147
-    return;
138
+	print "Tiny Tiny RSS update daemon.\n\n";
139
+	print "Options:\n";
140
+	print "  --log FILE           - log messages to FILE\n";
141
+	print "  --log-level N        - log verbosity level\n";
142
+	print "  --tasks N            - amount of update tasks to spawn\n";
143
+	print "                         default: " . MAX_JOBS . "\n";
144
+	print "  --interval N         - task spawn interval\n";
145
+	print "                         default: " . SPAWN_INTERVAL . " seconds.\n";
146
+	print "  --quiet              - don't output messages to stdout\n";
147
+	return;
148 148
 }
149 149
 
150 150
 Debug::set_enabled(true);
151 151
 
152 152
 if (isset($options["log-level"])) {
153
-    Debug::set_loglevel((int)$options["log-level"]);
153
+	Debug::set_loglevel((int)$options["log-level"]);
154 154
 }
155 155
 
156 156
 if (isset($options["log"])) {
157
-    Debug::set_quiet(isset($options['quiet']));
158
-    Debug::set_logfile($options["log"]);
159
-    Debug::log("Logging to " . $options["log"]);
157
+	Debug::set_quiet(isset($options['quiet']));
158
+	Debug::set_logfile($options["log"]);
159
+	Debug::log("Logging to " . $options["log"]);
160 160
 } else {
161
-    if (isset($options['quiet'])) {
162
-        Debug::set_loglevel(Debug::$LOG_DISABLED);
163
-    }
161
+	if (isset($options['quiet'])) {
162
+		Debug::set_loglevel(Debug::$LOG_DISABLED);
163
+	}
164 164
 }
165 165
 
166 166
 if (isset($options["tasks"])) {
167
-    Debug::log("Set to spawn " . $options["tasks"] . " children.");
168
-    $max_jobs = $options["tasks"];
167
+	Debug::log("Set to spawn " . $options["tasks"] . " children.");
168
+	$max_jobs = $options["tasks"];
169 169
 } else {
170
-    $max_jobs = MAX_JOBS;
170
+	$max_jobs = MAX_JOBS;
171 171
 }
172 172
 
173 173
 if (isset($options["interval"])) {
174
-    Debug::log("Spawn interval: " . $options["interval"] . " seconds.");
175
-    $spawn_interval = $options["interval"];
174
+	Debug::log("Spawn interval: " . $options["interval"] . " seconds.");
175
+	$spawn_interval = $options["interval"];
176 176
 } else {
177
-    $spawn_interval = SPAWN_INTERVAL;
177
+	$spawn_interval = SPAWN_INTERVAL;
178 178
 }
179 179
 
180 180
 // let's enforce a minimum spawn interval as to not forkbomb the host
@@ -182,22 +182,22 @@  discard block
 block discarded – undo
182 182
 Debug::log("Spawn interval: $spawn_interval sec");
183 183
 
184 184
 if (file_is_locked("update_daemon.lock")) {
185
-    die("error: Can't create lockfile. ".
186
-        "Maybe another daemon is already running.\n");
185
+	die("error: Can't create lockfile. ".
186
+		"Maybe another daemon is already running.\n");
187 187
 }
188 188
 
189 189
 // Try to lock a file in order to avoid concurrent update.
190 190
 $lock_handle = make_lockfile("update_daemon.lock");
191 191
 
192 192
 if (!$lock_handle) {
193
-    die("error: Can't create lockfile. ".
194
-        "Maybe another daemon is already running.\n");
193
+	die("error: Can't create lockfile. ".
194
+		"Maybe another daemon is already running.\n");
195 195
 }
196 196
 
197 197
 $schema_version = get_schema_version();
198 198
 
199 199
 if ($schema_version != SCHEMA_VERSION) {
200
-    die("Schema version is wrong, please upgrade the database.\n");
200
+	die("Schema version is wrong, please upgrade the database.\n");
201 201
 }
202 202
 
203 203
 // Protip: children close shared database handle when terminating, it's a bad idea to
@@ -205,56 +205,56 @@  discard block
 block discarded – undo
205 205
 
206 206
 while (true) {
207 207
 
208
-    // Since sleep is interupted by SIGCHLD, we need another way to
209
-    // respect the spawn interval
210
-    $next_spawn = $last_checkpoint + $spawn_interval - time();
211
-
212
-    if ($next_spawn % 60 == 0) {
213
-        $running_jobs = count($children);
214
-        Debug::log("[MASTER] active jobs: $running_jobs, next spawn at $next_spawn sec.");
215
-    }
216
-
217
-    if ($last_checkpoint + $spawn_interval < time()) {
218
-        check_ctimes();
219
-        reap_children();
220
-
221
-        for ($j = count($children); $j < $max_jobs; $j++) {
222
-            $pid = pcntl_fork();
223
-            if ($pid == -1) {
224
-                die("fork failed!\n");
225
-            } else if ($pid) {
226
-
227
-                if (!$master_handlers_installed) {
228
-                    Debug::log("[MASTER] installing shutdown handlers");
229
-                    pcntl_signal(SIGINT, 'sigint_handler');
230
-                    pcntl_signal(SIGTERM, 'sigint_handler');
231
-                    register_shutdown_function('shutdown', posix_getpid());
232
-                    $master_handlers_installed = true;
233
-                }
234
-
235
-                Debug::log("[MASTER] spawned client $j [PID:$pid]...");
236
-                array_push($children, $pid);
237
-                $ctimes[$pid] = time();
238
-            } else {
239
-                pcntl_signal(SIGCHLD, SIG_IGN);
240
-                pcntl_signal(SIGINT, 'task_sigint_handler');
241
-
242
-                register_shutdown_function('task_shutdown');
243
-
244
-                $quiet = (isset($options["quiet"])) ? "--quiet" : "";
245
-                $log = function_exists("flock") && isset($options['log']) ? '--log '.$options['log'] : '';
246
-
247
-                $my_pid = posix_getpid();
248
-
249
-                passthru(PHP_EXECUTABLE . " update.php --daemon-loop $quiet $log --task $j --pidlock $my_pid");
250
-
251
-                sleep(1);
252
-
253
-                // We exit in order to avoid fork bombing.
254
-                exit(0);
255
-            }
256
-        }
257
-        $last_checkpoint = time();
258
-    }
259
-    sleep(1);
208
+	// Since sleep is interupted by SIGCHLD, we need another way to
209
+	// respect the spawn interval
210
+	$next_spawn = $last_checkpoint + $spawn_interval - time();
211
+
212
+	if ($next_spawn % 60 == 0) {
213
+		$running_jobs = count($children);
214
+		Debug::log("[MASTER] active jobs: $running_jobs, next spawn at $next_spawn sec.");
215
+	}
216
+
217
+	if ($last_checkpoint + $spawn_interval < time()) {
218
+		check_ctimes();
219
+		reap_children();
220
+
221
+		for ($j = count($children); $j < $max_jobs; $j++) {
222
+			$pid = pcntl_fork();
223
+			if ($pid == -1) {
224
+				die("fork failed!\n");
225
+			} else if ($pid) {
226
+
227
+				if (!$master_handlers_installed) {
228
+					Debug::log("[MASTER] installing shutdown handlers");
229
+					pcntl_signal(SIGINT, 'sigint_handler');
230
+					pcntl_signal(SIGTERM, 'sigint_handler');
231
+					register_shutdown_function('shutdown', posix_getpid());
232
+					$master_handlers_installed = true;
233
+				}
234
+
235
+				Debug::log("[MASTER] spawned client $j [PID:$pid]...");
236
+				array_push($children, $pid);
237
+				$ctimes[$pid] = time();
238
+			} else {
239
+				pcntl_signal(SIGCHLD, SIG_IGN);
240
+				pcntl_signal(SIGINT, 'task_sigint_handler');
241
+
242
+				register_shutdown_function('task_shutdown');
243
+
244
+				$quiet = (isset($options["quiet"])) ? "--quiet" : "";
245
+				$log = function_exists("flock") && isset($options['log']) ? '--log '.$options['log'] : '';
246
+
247
+				$my_pid = posix_getpid();
248
+
249
+				passthru(PHP_EXECUTABLE . " update.php --daemon-loop $quiet $log --task $j --pidlock $my_pid");
250
+
251
+				sleep(1);
252
+
253
+				// We exit in order to avoid fork bombing.
254
+				exit(0);
255
+			}
256
+		}
257
+		$last_checkpoint = time();
258
+	}
259
+	sleep(1);
260 260
 }
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -1,9 +1,9 @@  discard block
 block discarded – undo
1 1
 #!/usr/bin/env php
2 2
 <?php
3
-set_include_path(dirname(__FILE__) .DIRECTORY_SEPARATOR."include" . PATH_SEPARATOR .
3
+set_include_path(dirname(__FILE__).DIRECTORY_SEPARATOR."include".PATH_SEPARATOR.
4 4
     get_include_path());
5 5
 
6
-declare(ticks = 1);
6
+declare(ticks=1);
7 7
 chdir(dirname(__FILE__));
8 8
 
9 9
 define('DISABLE_SESSIONS', true);
@@ -93,9 +93,9 @@  discard block
 block discarded – undo
93 93
 
94 94
 function shutdown($caller_pid) {
95 95
     if ($caller_pid == posix_getpid()) {
96
-        if (file_exists(LOCK_DIRECTORY . "/update_daemon.lock")) {
96
+        if (file_exists(LOCK_DIRECTORY."/update_daemon.lock")) {
97 97
             Debug::log("removing lockfile (master)...");
98
-            unlink(LOCK_DIRECTORY . "/update_daemon.lock");
98
+            unlink(LOCK_DIRECTORY."/update_daemon.lock");
99 99
         }
100 100
     }
101 101
 }
@@ -103,9 +103,9 @@  discard block
 block discarded – undo
103 103
 function task_shutdown() {
104 104
     $pid = posix_getpid();
105 105
 
106
-    if (file_exists(LOCK_DIRECTORY . "/update_daemon-$pid.lock")) {
106
+    if (file_exists(LOCK_DIRECTORY."/update_daemon-$pid.lock")) {
107 107
         Debug::log("removing lockfile ($pid)...");
108
-        unlink(LOCK_DIRECTORY . "/update_daemon-$pid.lock");
108
+        unlink(LOCK_DIRECTORY."/update_daemon-$pid.lock");
109 109
     }
110 110
 }
111 111
 
@@ -134,15 +134,15 @@  discard block
 block discarded – undo
134 134
 
135 135
 $options = getopt("", $longopts);
136 136
 
137
-if (isset($options["help"]) ) {
137
+if (isset($options["help"])) {
138 138
     print "Tiny Tiny RSS update daemon.\n\n";
139 139
     print "Options:\n";
140 140
     print "  --log FILE           - log messages to FILE\n";
141 141
     print "  --log-level N        - log verbosity level\n";
142 142
     print "  --tasks N            - amount of update tasks to spawn\n";
143
-    print "                         default: " . MAX_JOBS . "\n";
143
+    print "                         default: ".MAX_JOBS."\n";
144 144
     print "  --interval N         - task spawn interval\n";
145
-    print "                         default: " . SPAWN_INTERVAL . " seconds.\n";
145
+    print "                         default: ".SPAWN_INTERVAL." seconds.\n";
146 146
     print "  --quiet              - don't output messages to stdout\n";
147 147
     return;
148 148
 }
@@ -150,13 +150,13 @@  discard block
 block discarded – undo
150 150
 Debug::set_enabled(true);
151 151
 
152 152
 if (isset($options["log-level"])) {
153
-    Debug::set_loglevel((int)$options["log-level"]);
153
+    Debug::set_loglevel((int) $options["log-level"]);
154 154
 }
155 155
 
156 156
 if (isset($options["log"])) {
157 157
     Debug::set_quiet(isset($options['quiet']));
158 158
     Debug::set_logfile($options["log"]);
159
-    Debug::log("Logging to " . $options["log"]);
159
+    Debug::log("Logging to ".$options["log"]);
160 160
 } else {
161 161
     if (isset($options['quiet'])) {
162 162
         Debug::set_loglevel(Debug::$LOG_DISABLED);
@@ -164,14 +164,14 @@  discard block
 block discarded – undo
164 164
 }
165 165
 
166 166
 if (isset($options["tasks"])) {
167
-    Debug::log("Set to spawn " . $options["tasks"] . " children.");
167
+    Debug::log("Set to spawn ".$options["tasks"]." children.");
168 168
     $max_jobs = $options["tasks"];
169 169
 } else {
170 170
     $max_jobs = MAX_JOBS;
171 171
 }
172 172
 
173 173
 if (isset($options["interval"])) {
174
-    Debug::log("Spawn interval: " . $options["interval"] . " seconds.");
174
+    Debug::log("Spawn interval: ".$options["interval"]." seconds.");
175 175
     $spawn_interval = $options["interval"];
176 176
 } else {
177 177
     $spawn_interval = SPAWN_INTERVAL;
@@ -246,7 +246,7 @@  discard block
 block discarded – undo
246 246
 
247 247
                 $my_pid = posix_getpid();
248 248
 
249
-                passthru(PHP_EXECUTABLE . " update.php --daemon-loop $quiet $log --task $j --pidlock $my_pid");
249
+                passthru(PHP_EXECUTABLE." update.php --daemon-loop $quiet $log --task $j --pidlock $my_pid");
250 250
 
251 251
                 sleep(1);
252 252
 
Please login to merge, or discard this patch.