@@ -87,10 +87,11 @@ discard block |
||
| 87 | 87 | try |
| 88 | 88 | { |
| 89 | 89 | $dbconn = IcingaDbConnection::fromResourceName($DBname); |
| 90 | - } |
|
| 91 | - catch (Exception $e) |
|
| 90 | + } catch (Exception $e) |
|
| 92 | 91 | { |
| 93 | - if ($test) return array(2,$DBname); |
|
| 92 | + if ($test) { |
|
| 93 | + return array(2,$DBname); |
|
| 94 | + } |
|
| 94 | 95 | $this->redirectNow('trapdirector/settings?dberror=2'); |
| 95 | 96 | return null; |
| 96 | 97 | } |
@@ -98,10 +99,11 @@ discard block |
||
| 98 | 99 | try |
| 99 | 100 | { |
| 100 | 101 | $db=$dbconn->getConnection(); |
| 101 | - } |
|
| 102 | - catch (Exception $e) |
|
| 102 | + } catch (Exception $e) |
|
| 103 | 103 | { |
| 104 | - if ($test) return array(3,$DBname,$e->getMessage()); |
|
| 104 | + if ($test) { |
|
| 105 | + return array(3,$DBname,$e->getMessage()); |
|
| 106 | + } |
|
| 105 | 107 | $this->redirectNow('trapdirector/settings?dberror=3'); |
| 106 | 108 | return null; |
| 107 | 109 | } |
@@ -113,55 +115,72 @@ discard block |
||
| 113 | 115 | $version=$db->fetchRow($query); |
| 114 | 116 | if ( ($version == null) || ! property_exists($version,'value') ) |
| 115 | 117 | { |
| 116 | - if ($test) return array(4,$DBname); |
|
| 118 | + if ($test) { |
|
| 119 | + return array(4,$DBname); |
|
| 120 | + } |
|
| 117 | 121 | $this->redirectNow('trapdirector/settings?dberror=4'); |
| 118 | 122 | return null; |
| 119 | 123 | } |
| 120 | 124 | if ($version->value < $this->getModuleConfig()->getDbMinVersion()) |
| 121 | 125 | { |
| 122 | - if ($test) return array(5,$version->value,$this->getModuleConfig()->getDbMinVersion()); |
|
| 126 | + if ($test) { |
|
| 127 | + return array(5,$version->value,$this->getModuleConfig()->getDbMinVersion()); |
|
| 128 | + } |
|
| 123 | 129 | $this->redirectNow('trapdirector/settings?dberror=5'); |
| 124 | 130 | return null; |
| 125 | 131 | } |
| 126 | - } |
|
| 127 | - catch (Exception $e) |
|
| 132 | + } catch (Exception $e) |
|
| 128 | 133 | { |
| 129 | - if ($test) return array(3,$DBname,$e->getMessage()); |
|
| 134 | + if ($test) { |
|
| 135 | + return array(3,$DBname,$e->getMessage()); |
|
| 136 | + } |
|
| 130 | 137 | $this->redirectNow('trapdirector/settings?dberror=4'); |
| 131 | 138 | return null; |
| 132 | 139 | } |
| 133 | 140 | } |
| 134 | - if ($test) return array(0,''); |
|
| 141 | + if ($test) { |
|
| 142 | + return array(0,''); |
|
| 143 | + } |
|
| 135 | 144 | return $dbconn; |
| 136 | 145 | } |
| 137 | 146 | |
| 138 | 147 | public function getDb($test=false) |
| 139 | 148 | { |
| 140 | - if ($this->trapDB != null && $test = false) return $this->trapDB; |
|
| 149 | + if ($this->trapDB != null && $test = false) { |
|
| 150 | + return $this->trapDB; |
|
| 151 | + } |
|
| 141 | 152 | |
| 142 | 153 | $dbresource=$this->Config()->get('config', 'database'); |
| 143 | 154 | |
| 144 | 155 | if ( ! $dbresource ) |
| 145 | 156 | { |
| 146 | - if ($test) return array(1,''); |
|
| 157 | + if ($test) { |
|
| 158 | + return array(1,''); |
|
| 159 | + } |
|
| 147 | 160 | $this->redirectNow('trapdirector/settings?dberror=1'); |
| 148 | 161 | return null; |
| 149 | 162 | } |
| 150 | 163 | $retDB=$this->getDbByName($dbresource,$test,true); |
| 151 | - if ($test == true) return $retDB; |
|
| 164 | + if ($test == true) { |
|
| 165 | + return $retDB; |
|
| 166 | + } |
|
| 152 | 167 | $this->trapDB=$retDB; |
| 153 | 168 | return $this->trapDB; |
| 154 | 169 | } |
| 155 | 170 | |
| 156 | 171 | public function getIdoDb($test=false) |
| 157 | 172 | { |
| 158 | - if ($this->icingaDB != null && $test = false) return $this->icingaDB; |
|
| 173 | + if ($this->icingaDB != null && $test = false) { |
|
| 174 | + return $this->icingaDB; |
|
| 175 | + } |
|
| 159 | 176 | // TODO : get ido database directly from icingaweb2 config -> (or not if using only API) |
| 160 | 177 | $dbresource=$this->Config()->get('config', 'IDOdatabase');; |
| 161 | 178 | |
| 162 | 179 | if ( ! $dbresource ) |
| 163 | 180 | { |
| 164 | - if ($test) return array(1,'No database in config.ini'); |
|
| 181 | + if ($test) { |
|
| 182 | + return array(1,'No database in config.ini'); |
|
| 183 | + } |
|
| 165 | 184 | $this->redirectNow('trapdirector/settings?idodberror=1'); |
| 166 | 185 | return null; |
| 167 | 186 | } |
@@ -169,10 +188,11 @@ discard block |
||
| 169 | 188 | try |
| 170 | 189 | { |
| 171 | 190 | $dbconn = IcingaDbConnection::fromResourceName($dbresource); |
| 172 | - } |
|
| 173 | - catch (Exception $e) |
|
| 191 | + } catch (Exception $e) |
|
| 174 | 192 | { |
| 175 | - if ($test) return array(2,"Database $dbresource does not exists in IcingaWeb2"); |
|
| 193 | + if ($test) { |
|
| 194 | + return array(2,"Database $dbresource does not exists in IcingaWeb2"); |
|
| 195 | + } |
|
| 176 | 196 | $this->redirectNow('trapdirector/settings?idodberror=2'); |
| 177 | 197 | return null; |
| 178 | 198 | } |
@@ -192,8 +212,7 @@ discard block |
||
| 192 | 212 | { |
| 193 | 213 | return array(4,"$dbresource does not look like an IDO database"); |
| 194 | 214 | } |
| 195 | - } |
|
| 196 | - catch (Exception $e) |
|
| 215 | + } catch (Exception $e) |
|
| 197 | 216 | { |
| 198 | 217 | return array(3,"Error connecting to $dbresource : " . $e->getMessage()); |
| 199 | 218 | } |
@@ -441,8 +460,7 @@ discard block |
||
| 441 | 460 | if (isset($common_services[$service->name2]['num'])) |
| 442 | 461 | { |
| 443 | 462 | $common_services[$service->name2]['num'] +=1; |
| 444 | - } |
|
| 445 | - else |
|
| 463 | + } else |
|
| 446 | 464 | { |
| 447 | 465 | $common_services[$service->name2]['num']=1; |
| 448 | 466 | $common_services[$service->name2]['name']=$service->name; |
@@ -586,7 +604,9 @@ discard block |
||
| 586 | 604 | $condition=($condition===null)?'':$condition.' AND '; |
| 587 | 605 | $condition.="trap_oid='$oid'"; |
| 588 | 606 | } |
| 589 | - if($condition === null) return null; |
|
| 607 | + if($condition === null) { |
|
| 608 | + return null; |
|
| 609 | + } |
|
| 590 | 610 | $query=$db->delete( |
| 591 | 611 | $this->getModuleConfig()->getTrapTableName(), |
| 592 | 612 | $condition |
@@ -614,7 +634,9 @@ discard block |
||
| 614 | 634 | $condition=($condition==null)?'':$condition.' AND '; |
| 615 | 635 | $condition.="trap_oid='$oid'"; |
| 616 | 636 | } |
| 617 | - if($condition ==null) return 0; |
|
| 637 | + if($condition ==null) { |
|
| 638 | + return 0; |
|
| 639 | + } |
|
| 618 | 640 | $query=$db->select() |
| 619 | 641 | ->from( |
| 620 | 642 | $this->getModuleConfig()->getTrapTableName(), |
@@ -638,18 +660,28 @@ discard block |
||
| 638 | 660 | array('value'=>'value')) |
| 639 | 661 | ->where('name=?',$element); |
| 640 | 662 | $return_row=$db->fetchRow($query); |
| 641 | - if ($return_row==null) // value does not exists |
|
| 663 | + if ($return_row==null) { |
|
| 664 | + // value does not exists |
|
| 642 | 665 | { |
| 643 | 666 | $default=$this->getModuleConfig()->getDBConfigDefaults(); |
| 644 | - if ( ! isset($default[$element])) return null; // no default and not value |
|
| 667 | + } |
|
| 668 | + if ( ! isset($default[$element])) { |
|
| 669 | + return null; |
|
| 670 | + } |
|
| 671 | + // no default and not value |
|
| 645 | 672 | |
| 646 | 673 | $this->addDBConfigValue($element,$default[$element]); |
| 647 | 674 | return $default[$element]; |
| 648 | 675 | } |
| 649 | - if ($return_row->value == null) // value id empty |
|
| 676 | + if ($return_row->value == null) { |
|
| 677 | + // value id empty |
|
| 650 | 678 | { |
| 651 | 679 | $default=$this->getModuleConfig()->getDBConfigDefaults(); |
| 652 | - if ( ! isset($default[$element])) return null; // no default and not value |
|
| 680 | + } |
|
| 681 | + if ( ! isset($default[$element])) { |
|
| 682 | + return null; |
|
| 683 | + } |
|
| 684 | + // no default and not value |
|
| 653 | 685 | $this->setDBConfigValue($element,$default[$element]); |
| 654 | 686 | return $default[$element]; |
| 655 | 687 | } |