Conditions | 12 |
Paths | 66 |
Total Lines | 75 |
Code Lines | 46 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
39 | public function updateAction() |
||
40 | { |
||
41 | $background = $this->params->get('pid', null); |
||
42 | $logLevel= $this->params->has('verb') ? 4 : 2; |
||
43 | if ($this->params->has('force-check')) { echo "Not implemented"; return;} |
||
44 | $forceCheck=$this->params->has('force-check')?True:False; |
||
45 | $pid=1; |
||
46 | if ($background != null) |
||
47 | { |
||
48 | $file=@fopen($background,'w'); |
||
49 | if ($file == false) |
||
50 | { |
||
51 | echo 'Error : cannot open pid file '.$background; |
||
52 | return 1; |
||
53 | } |
||
54 | $pid = pcntl_fork(); |
||
55 | if ($pid == -1) { |
||
56 | echo 'Error : Cannot fork process'; |
||
57 | return 1; |
||
58 | } |
||
59 | } |
||
60 | $module=Icinga::app()->getModuleManager()->getModule($this->getModuleName()); |
||
61 | require_once($module->getBaseDir() .'/bin/trap_class.php'); |
||
62 | $icingaweb2_etc=$this->Config()->get('config', 'icingaweb2_etc'); |
||
63 | $trap = new Trap($icingaweb2_etc); |
||
64 | if ($pid == 1) |
||
65 | { |
||
66 | $trap->setLogging($logLevel,'display'); |
||
67 | } |
||
68 | else |
||
69 | { // use default display TODO : if default is 'display' son process will be killed at first output.... |
||
70 | if ($pid != 0) |
||
71 | { |
||
72 | // father process |
||
73 | fwrite($file,$pid); |
||
|
|||
74 | fclose($file); |
||
75 | echo "OK : process $pid in bckground"; |
||
76 | return 0; |
||
77 | } |
||
78 | else |
||
79 | { // son process : close all file descriptors and go to a new session |
||
80 | fclose($file); |
||
81 | // $sid = posix_setsid(); |
||
82 | fclose(STDIN); |
||
83 | fclose(STDOUT); |
||
84 | fclose(STDERR); |
||
85 | try |
||
86 | { |
||
87 | $trap->mibClass->update_mib_database(false,$forceCheck); |
||
88 | } |
||
89 | catch (Exception $e) |
||
90 | { |
||
91 | $trap->logging->log('Error in updating : ' . $e->getMessage(),2); |
||
92 | } |
||
93 | unlink($background); |
||
94 | return 0; |
||
95 | } |
||
96 | |||
97 | } |
||
98 | |||
99 | try |
||
100 | { |
||
101 | echo "Update main mib database : \n"; |
||
102 | echo "# (trap found) C (trap already processed) . (every 2 seconds) : \n"; |
||
103 | $trap->mibClass->update_mib_database(true,$forceCheck); |
||
104 | echo "Done\n"; |
||
105 | |||
106 | } |
||
107 | catch (Exception $e) |
||
108 | { |
||
109 | echo 'Error in updating : ' . $e->getMessage(); |
||
110 | } |
||
111 | if ($pid != 1) |
||
112 | { |
||
113 | unlink($background); |
||
114 | } |
||
158 |