Completed
Pull Request — master (#2146)
by Christian
09:32
created
html/user/submit_rpc_handler.php 2 patches
Doc Comments   +26 added lines patch added patch discarded remove patch
@@ -30,6 +30,9 @@  discard block
 block discarded – undo
30 30
 ini_set('display_errors', true);
31 31
 ini_set('display_startup_errors', true);
32 32
 
33
+/**
34
+ * @param string $name
35
+ */
33 36
 function get_wu($name) {
34 37
     $name = BoincDb::escape_string($name);
35 38
     $wu = BoincWorkunit::lookup("name='$name'");
@@ -37,6 +40,9 @@  discard block
 block discarded – undo
37 40
     return $wu;
38 41
 }
39 42
 
43
+/**
44
+ * @param string $name
45
+ */
40 46
 function get_submit_app($name) {
41 47
     $name = BoincDb::escape_string($name);
42 48
     $app = BoincApp::lookup("name='$name'");
@@ -76,6 +82,9 @@  discard block
 block discarded – undo
76 82
     return $y;
77 83
 }
78 84
 
85
+/**
86
+ * @param SimpleXMLElement|null $template
87
+ */
79 88
 function est_elapsed_time($r, $template) {
80 89
     // crude estimate: batch FLOPs / project FLOPS
81 90
     //
@@ -131,6 +140,9 @@  discard block
 block discarded – undo
131 140
 // The arg is the batch-level template, if any.
132 141
 // Jobs may have their own templates.
133 142
 //
143
+/**
144
+ * @param SimpleXMLElement $template
145
+ */
134 146
 function validate_batch($jobs, $template) {
135 147
     $i = 0;
136 148
     $n = count($template->file_info);
@@ -200,6 +212,11 @@  discard block
 block discarded – undo
200 212
 
201 213
 // submit a list of jobs with a single create_work command.
202 214
 //
215
+/**
216
+ * @param SimpleXMLElement|null $template
217
+ * @param double $priority
218
+ * @param integer $app_version_num
219
+ */
203 220
 function submit_jobs(
204 221
     $jobs, $template, $app, $batch_id, $priority, $app_version_num,
205 222
     $input_template_filename,        // batch-level; can also specify per job
@@ -279,6 +296,9 @@  discard block
 block discarded – undo
279 296
 // Check whether the template is already in our map.
280 297
 // If not, write it to a temp file.
281 298
 //
299
+/**
300
+ * @param stdClass $job
301
+ */
282 302
 function make_input_template($job) {
283 303
     global $input_templates;
284 304
     if (!array_key_exists($job->input_template_xml, $input_templates)) {
@@ -295,6 +315,9 @@  discard block
 block discarded – undo
295 315
 // A little different because these have to exist for life of job.
296 316
 // Store them in templates/tmp/, with content-based filenames
297 317
 //
318
+/**
319
+ * @param stdClass $job
320
+ */
298 321
 function make_output_template($job) {
299 322
     global $output_templates;
300 323
     if (!array_key_exists($job->output_template_xml, $output_templates)) {
@@ -489,6 +512,9 @@  discard block
 block discarded – undo
489 512
     ";
490 513
 }
491 514
 
515
+/**
516
+ * @param integer $get_cpu_time
517
+ */
492 518
 function print_batch_params($batch, $get_cpu_time) {
493 519
     $app = BoincApp::lookup_id($batch->app_id);
494 520
     if (!$app) $app->name = "none";
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
     if ($template) {
55 55
         $t = (double)$template->workunit->rsc_fpops_est;
56 56
     }
57
-    foreach($r->batch->job as $job) {
57
+    foreach ($r->batch->job as $job) {
58 58
         $y = (double)$job->rsc_fpops_est;
59 59
         if ($y) {
60 60
             $x += $y;
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 function est_elapsed_time($r, $template) {
80 80
     // crude estimate: batch FLOPs / project FLOPS
81 81
     //
82
-    return batch_flop_count($r, $template) / project_flops();
82
+    return batch_flop_count($r, $template)/project_flops();
83 83
 }
84 84
 
85 85
 // if batch-level input template filename was given, read it;
@@ -89,9 +89,9 @@  discard block
 block discarded – undo
89 89
 //
90 90
 function read_input_template($app, $r) {
91 91
     if ((isset($r->batch)) && (isset($r->batch->workunit_template_file)) && ($r->batch->workunit_template_file)) {
92
-        $path = project_dir() . "/templates/".$r->batch->workunit_template_file;
92
+        $path = project_dir()."/templates/".$r->batch->workunit_template_file;
93 93
     } else {
94
-        $path = project_dir() . "/templates/$app->name"."_in";
94
+        $path = project_dir()."/templates/$app->name"."_in";
95 95
     }
96 96
     if (file_exists($path)) {
97 97
         $x = simplexml_load_file($path);
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 function validate_batch($jobs, $template) {
135 135
     $i = 0;
136 136
     $n = count($template->file_info);
137
-    foreach($jobs as $job) {
137
+    foreach ($jobs as $job) {
138 138
         $m = count($job->input_files);
139 139
         if ($n != $m) {
140 140
             xml_error(-1, "wrong # of input files for job $i: need $n, got $m");
@@ -189,7 +189,7 @@  discard block
 block discarded – undo
189 189
 // stage all the files
190 190
 //
191 191
 function stage_files(&$jobs) {
192
-    foreach($jobs as $job) {
192
+    foreach ($jobs as $job) {
193 193
         foreach ($job->input_files as $file) {
194 194
             if ($file->mode != "remote") {
195 195
                 $file->name = stage_file($file);
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
 //
203 203
 function submit_jobs(
204 204
     $jobs, $template, $app, $batch_id, $priority, $app_version_num,
205
-    $input_template_filename,        // batch-level; can also specify per job
205
+    $input_template_filename, // batch-level; can also specify per job
206 206
     $output_template_filename
207 207
 ) {
208 208
     global $input_templates, $output_templates;
@@ -211,7 +211,7 @@  discard block
 block discarded – undo
211 211
     // one line per job
212 212
     //
213 213
     $x = "";
214
-    foreach($jobs as $job) {
214
+    foreach ($jobs as $job) {
215 215
         if ($job->name) {
216 216
             $x .= " --wu_name $job->name";
217 217
         }
@@ -243,8 +243,8 @@  discard block
 block discarded – undo
243 243
         $x .= "\n";
244 244
     }
245 245
 
246
-    $errfile = "/tmp/create_work_" . getmypid() . ".err";
247
-    $cmd = "cd " . project_dir() . "; ./bin/create_work --appname $app->name --batch $batch_id --priority $priority";
246
+    $errfile = "/tmp/create_work_".getmypid().".err";
247
+    $cmd = "cd ".project_dir()."; ./bin/create_work --appname $app->name --batch $batch_id --priority $priority";
248 248
     if ($input_template_filename) {
249 249
         $cmd .= " --wu_template templates/$input_template_filename";
250 250
     }
@@ -325,7 +325,7 @@  discard block
 block discarded – undo
325 325
 //
326 326
 function xml_get_jobs($r) {
327 327
     $jobs = array();
328
-    foreach($r->batch->job as $j) {
328
+    foreach ($r->batch->job as $j) {
329 329
         $job = new StdClass;
330 330
         $job->input_files = array();
331 331
         $job->command_line = (string)$j->command_line;
@@ -401,14 +401,14 @@  discard block
 block discarded – undo
401 401
     // - use that for batch logical end time and job priority
402 402
     //
403 403
     $total_flops = 0;
404
-    foreach($jobs as $job) {
404
+    foreach ($jobs as $job) {
405 405
         //print_r($job);
406 406
         if ($job->rsc_fpops_est) {
407 407
             $total_flops += $job->rsc_fpops_est;
408 408
         } else if ($job->input_template && $job->input_template->workunit->rsc_fpops_est) {
409
-            $total_flops += (double) $job->input_template->workunit->rsc_fpops_est;
409
+            $total_flops += (double)$job->input_template->workunit->rsc_fpops_est;
410 410
         } else {
411
-            $x = (double) $template->workunit->rsc_fpops_est;
411
+            $x = (double)$template->workunit->rsc_fpops_est;
412 412
             if ($x) {
413 413
                 $total_flops += $x;
414 414
             } else {
@@ -416,7 +416,7 @@  discard block
 block discarded – undo
416 416
             }
417 417
         }
418 418
     }
419
-    $cmd = "cd " . project_dir() . "/bin; ./adjust_user_priority --user $user->id --flops $total_flops --app $app->name";
419
+    $cmd = "cd ".project_dir()."/bin; ./adjust_user_priority --user $user->id --flops $total_flops --app $app->name";
420 420
     $x = exec($cmd);
421 421
     if (!is_numeric($x) || (double)$x == 0) {
422 422
         xml_error(-1, "$cmd returned $x");
@@ -531,7 +531,7 @@  discard block
 block discarded – undo
531 531
 }
532 532
 
533 533
 function n_outfiles($wu) {
534
-    $path = project_dir() . "/$wu->output_template_filename";
534
+    $path = project_dir()."/$wu->output_template_filename";
535 535
     $r = simplexml_load_file($path);
536 536
     return count($r->file_info);
537 537
 }
@@ -726,7 +726,7 @@  discard block
 block discarded – undo
726 726
 ";
727 727
         if ($result->server_state == 5) {   // over?
728 728
             $paths = get_outfile_paths($result);
729
-            foreach($paths as $path) {
729
+            foreach ($paths as $path) {
730 730
                 if (is_file($path)) {
731 731
                     $size = filesize($path);
732 732
                     echo "        <outfile>
@@ -766,7 +766,7 @@  discard block
 block discarded – undo
766 766
     } else {
767 767
         $results = BoincResult::enum("workunitid=$job_id");
768 768
         foreach ($results as $r) {
769
-            switch($r->outcome) {
769
+            switch ($r->outcome) {
770 770
             case 1:
771 771
             case 3:
772 772
             case 6:
@@ -874,8 +874,8 @@  discard block
 block discarded – undo
874 874
     }
875 875
 
876 876
     list($user, $user_submit) = authenticate_user($r, $app);
877
-    $in = file_get_contents(project_dir() . "/templates/".$app->name."_in");
878
-    $out = file_get_contents(project_dir() . "/templates/".$app->name."_out");
877
+    $in = file_get_contents(project_dir()."/templates/".$app->name."_in");
878
+    $out = file_get_contents(project_dir()."/templates/".$app->name."_out");
879 879
     if ($in === false || $out === false) {
880 880
         xml_error(-1, "template file missing");
881 881
     }
@@ -886,7 +886,7 @@  discard block
 block discarded – undo
886 886
 
887 887
 function ping($r) {
888 888
     xml_start_tag("ping");
889
-    BoincDb::get();     // errors out if DB down or web disabled
889
+    BoincDb::get(); // errors out if DB down or web disabled
890 890
     echo "<success>1</success>
891 891
         </ping>
892 892
     ";
@@ -952,10 +952,10 @@  discard block
 block discarded – undo
952 952
 if ($request_log) {
953 953
     $request_log_dir = parse_config(get_config(), "<log_dir>");
954 954
     if ($request_log_dir) {
955
-        $request_log = $request_log_dir . "/" . $request_log;
955
+        $request_log = $request_log_dir."/".$request_log;
956 956
     }
957 957
     if ($file = fopen($request_log, "a+")) {
958
-        fwrite($file, "\n<submit_rpc_handler date=\"" . date(DATE_ATOM) . "\">\n" . $_POST['request'] . "\n</submit_rpc_handler>\n");
958
+        fwrite($file, "\n<submit_rpc_handler date=\"".date(DATE_ATOM)."\">\n".$_POST['request']."\n</submit_rpc_handler>\n");
959 959
         fclose($file);
960 960
     }
961 961
 }
Please login to merge, or discard this patch.