Project

General

Profile

Revision ad6689da

IDad6689dab313422a6e82633e880db45853e85c67
Parent 077e4de7
Child 1be75264

Added by Francois POIROTTE about 7 years ago

Davantage de correction liées aux conventions

Change-Id: I7680cf42d0b10ac300d44085d695e15064d33094
Reviewed-on: https://vigilo-dev.si.c-s.fr/review/2369
Tested-by: Build system <>
Reviewed-by: Francois POIROTTE <>

View differences:

phpcs.xml
10 10
        -->
11 11
        <exclude name="PSR1.Classes.ClassDeclaration.MissingNamespace"/>
12 12
    </rule>
13

  
14
    <rule ref="Squiz.WhiteSpace.OperatorSpacing">
15
        <properties>
16
            <property name="ignoreNewlines" value="true" />
17
        </properties>
18
    </rule>
19

  
13 20
    <encoding>utf-8</encoding>
14 21
</ruleset>
src/Vigilo/VigiloArg.php
20 20
            }
21 21
            $values = $new_values;
22 22
        } elseif (!is_string($values) && !is_int($values)
23
            && !is_bool($values) && !is_float($values)
24
        ) {
23
            && !is_bool($values) && !is_float($values)) {
25 24
            throw new \RuntimeException();
26 25
        } else {
27 26
            $values = (string) $values;
28 27
        }
29 28

  
30
        $this->name = $name;
31
        $this->values = $values;
29
        $this->name     = $name;
30
        $this->values   = $values;
32 31
    }
33 32

  
34 33
    public function getName()
src/Vigilo/VigiloGroups.php
3 3
class VigiloGroups extends VigiloXml
4 4
{
5 5
    protected $name;
6
    protected $grps;
6
    protected $groups;
7 7

  
8 8
    public function __construct($name)
9 9
    {
10
        $this->name = $name;
11
        $this->grps=array();
10
        $this->name     = $name;
11
        $this->groups   = array();
12 12
    }
13 13
    
14 14
    public function getName()
......
18 18

  
19 19
    public function addSubGroup(VigiloGroups $subGroup)
20 20
    {
21
        $this->grps[$subGroup->getName()] = $subGroup;
21
        $this->groups[$subGroup->getName()] = $subGroup;
22 22
    }
23 23

  
24 24
    public function __toString()
......
26 26
        return self::sprintf(
27 27
            '<group name="%s">%s</group>',
28 28
            $this->name,
29
            $this->grps
29
            $this->groups
30 30
        );
31 31
    }
32 32
}
src/Vigilo/VigiloHost.php
40 40
    {
41 41
        $template_name = $this->computer->getField("template_name");
42 42

  
43
        if ($template_name && $template_name !== "N/A") {
43
        if ($template_name && "N/A" !== $template_name) {
44 44
            $this->children[] = new VigiloHostTemplate($this->computer->getField("template_name"));
45 45
        }
46 46

  
47 47
        $template_number = $this->computer->getField("vigilo_template");
48
        if ($template_number !== '0' && $template_number !== 'N/A') {
48
        if ('0' !== $template_number && 'N/A' !== $template_number) {
49 49
            $common_dbtm = new CommonDBTM();
50 50
            $template_name = PluginVigiloVigiloTemplate::getVigiloTemplateNameByID($template_number);
51 51
            $this->children[] = new VigiloHostTemplate($template_name);
......
59 59
    {
60 60
        $location = new Location();
61 61
        $location->getFromDB($this->computer->fields["locations_id"]);
62
        if (!($location->getName() == 'N/A')) {
63
            $locationCompleteName=explode(" > ", $location->getField("completename"));
64
            $locationRealName=implode("/", $locationCompleteName);
65
            $this->children[] = new VigiloGroup($locationRealName);
62
        if ('N/A' != $location->getName()) {
63
            $locationCompleteName   = explode(" > ", $location->getField("completename"));
64
            $locationRealName       = implode("/", $locationCompleteName);
65
            $this->children[]       = new VigiloGroup($locationRealName);
66 66
        }
67 67

  
68 68
        $entity = new Entity();
69 69
        $entity->getFromDB($this->computer->fields["entities_id"]);
70
        if (!($entity->getName() == 'N/A')) {
71
            $entityCompleteName=explode(" > ", $entity->getField("completename"));
72
            $entityRealName=implode("/", $entityCompleteName);
73
            $this->children[] = new VigiloGroup($entityRealName);
70
        if ('N/A' != $entity->getName()) {
71
            $entityCompleteName = explode(" > ", $entity->getField("completename"));
72
            $entityRealName     = implode("/", $entityCompleteName);
73
            $this->children[]   = new VigiloGroup($entityRealName);
74 74
        }
75 75

  
76 76
        $manufacturer = new Manufacturer();
77 77
        $manufacturer->getFromDB($this->computer->fields["manufacturers_id"]);
78
        if (!($manufacturer->getName() == 'N/A')) {
78
        if ('N/A' != $manufacturer->getName()) {
79 79
            $this->children[] = new VigiloGroup($manufacturer->getName());
80 80
        }
81 81
    }
......
84 84
    {
85 85
        static $address = null;
86 86

  
87
        if ($address === null && $this->agent) {
87
        if (null !== $address && $this->agent) {
88 88
            $addresses = $this->agent->getIPs();
89 89
            if (count($addresses)) {
90 90
                $address = current($addresses);
91 91
            }
92 92
        }
93 93

  
94
        if ($address === null) {
94
        if (null !== $address) {
95 95
            $address = $this->computer->getName();
96 96
            foreach ($this->addresses as $addr) {
97 97
                if (!$addr->is_ipv4()) {
......
139 139
        );
140 140

  
141 141
        foreach ($DB->query($query) as $np) {
142
            $query2 = NetworkName::getSQLRequestToSearchForItem("NetworkPort", $np['id']);
143
            $port = new NetworkPort();
144
            $ethport = new NetworkPortEthernet();
142
            $query2     = NetworkName::getSQLRequestToSearchForItem("NetworkPort", $np['id']);
143
            $port       = new NetworkPort();
144
            $ethport    = new NetworkPortEthernet();
145 145
            $port->getFromDB($np['id']);
146
            if ($port->getName() == 'lo') {
146
            if ('lo' == $port->getName()) {
147 147
                continue;
148 148
            }
149 149

  
150
            $args   = array();
151
            $label  = isset($port->fields['comment']) ? $port->fields['comment'] : $port->getName();
152
            $ethport = $ethport->find('networkports_id=' . $np['id']);
150
            $args       = array();
151
            $label      = isset($port->fields['comment']) ? $port->fields['comment'] : $port->getName();
152
            $ethport    = $ethport->find('networkports_id=' . $np['id']);
153 153
            foreach ($ethport as $rowEthPort) {
154 154
                if ($rowEthPort['speed']) {
155 155
                    $args[] = new VigiloArg('max', $rowEthPort['speed']);
......
177 177

  
178 178
    protected function monitorSoftwares()
179 179
    {
180
        global $DB;
181
        $listOfTest=new VigiloTestSoftware($this->computer);
182
        $computerSoftwareVersion=new Computer_SoftwareVersion();
183
        $ids=$computerSoftwareVersion->find('computers_id=' . $this->computer->getID());
180
        $listOfTest = new VigiloTestSoftware($this->computer);
181
        $computerSoftwareVersion = new Computer_SoftwareVersion();
182
        $ids = $computerSoftwareVersion->find('computers_id=' . $this->computer->getID());
184 183
        foreach ($ids as $id) {
185 184
            if ($id['softwareversions_id']) {
186
                $softwareVersion=new SoftwareVersion();
187
                $ids2=$softwareVersion->find('id=' . $id['softwareversions_id']);
185
                $softwareVersion = new SoftwareVersion();
186
                $ids2 = $softwareVersion->find('id=' . $id['softwareversions_id']);
188 187
                foreach ($ids2 as $id2) {
189 188
                    if ($id2['softwares_id']) {
190
                        $software=new Software();
189
                        $software = new Software();
191 190
                        $software->getFromDB($id2['softwares_id']);
192 191
                        $listOfTest->addRelevantTestWith($software->getName());
193 192
                    }
......
195 194
            }
196 195
        }
197 196
        foreach ($listOfTest->getTable() as $test) {
198
             $this->children[]=$test;
197
             $this->children[] = $test;
199 198
        }
200 199
    }
201 200

  
......
225 224

  
226 225
    public function __toString()
227 226
    {
228
        $outXML=new DOMdocument();
229
        $outXML->preserveWhiteSpace=false;
230
        $outXML->formatOutput=true;
227
        $outXML = new DOMDocument();
228
        $outXML->preserveWhiteSpace = false;
229
        $outXML->formatOutput       = true;
231 230
        $outXML->loadXML(
232 231
            self::sprintf(
233 232
                '<?xml version="1.0"?>' .
src/Vigilo/VigiloLocation.php
8 8

  
9 9
    public function __construct()
10 10
    {
11
        $this->childrenLocation=array();
12
        $this->childrenEntity=array();
13
        $this->childrenManufacturer=array();
11
        $this->childrenLocation     = array();
12
        $this->childrenEntity       = array();
13
        $this->childrenManufacturer = array();
14 14
        $this->selectLocations();
15 15
        $this->selectEntities();
16 16
        $this->selectManufacturers();
......
18 18

  
19 19
    protected function selectManufacturers()
20 20
    {
21
        global $DB;
22
        $manufacturers=new Manufacturer();
23
        $manufacturers=$manufacturers->find();
21
        $manufacturers = new Manufacturer();
22
        $manufacturers = $manufacturers->find();
24 23
        foreach ($manufacturers as $manufacturer) {
25 24
            $this->childrenManufacturer[] = new VigiloGroups($manufacturer["name"]);
26 25
        }
......
28 27

  
29 28
    protected function selectEntities()
30 29
    {
31
        global $DB;
32
        $entities=new Entity();
33
        $entities=$entities->find("", "completename");
34
        $ancestors=array();
30
        $entities   = new Entity();
31
        $entities   = $entities->find("", "completename");
32
        $ancestors  = array();
35 33
        foreach ($entities as $entity) {
36
            $currentLevel=$entity["level"];
37
            if ($currentLevel==1 && isset($ancestors[1])) {
38
                $this->childrenEntity[]=$ancestors[1];
34
            $currentLevel = $entity["level"];
35
            if ($currentLevel == 1 && isset($ancestors[1])) {
36
                $this->childrenEntity[] = $ancestors[1];
39 37
            }
40 38
            $tempEntity = new VigiloGroups($entity["name"]);
41
            $ancestors[$currentLevel]=$tempEntity;
39
            $ancestors[$currentLevel] = $tempEntity;
42 40
            if ($currentLevel != 1) {
43
                $ancestors[$currentLevel-1]->addSubGroup($tempEntity);
41
                $ancestors[$currentLevel - 1]->addSubGroup($tempEntity);
44 42
            }
45 43
        }
46
        $this->childrenEntity[]=$ancestors[1];
44
        $this->childrenEntity[] = $ancestors[1];
47 45
    }
48 46

  
49 47
    protected function selectLocations()
50 48
    {
51
        global $DB;
52
        $locations=new Location();
53
        $locations=$locations->find("", "completename");
54
        $ancestors=array();
49
        $locations = new Location();
50
        $locations = $locations->find("", "completename");
51
        $ancestors = array();
55 52
        foreach ($locations as $location) {
56
            $currentLevel=$location["level"];
57
            if ($currentLevel==1 && isset($ancestors[1])) {
58
                $this->childrenLocation[]=$ancestors[1];
53
            $currentLevel = $location["level"];
54
            if ($currentLevel == 1 && isset($ancestors[1])) {
55
                $this->childrenLocation[] = $ancestors[1];
59 56
            }
60 57
            $tempLocation = new VigiloGroups($location["name"]);
61
            $ancestors[$currentLevel]=$tempLocation;
58
            $ancestors[$currentLevel] = $tempLocation;
62 59
            if ($currentLevel != 1) {
63
                $ancestors[$currentLevel-1]->addSubGroup($tempLocation);
60
                $ancestors[$currentLevel - 1]->addSubGroup($tempLocation);
64 61
            }
65 62
        }
66
        $this->childrenLocation[]=$ancestors[1];
63
        $this->childrenLocation[] = $ancestors[1];
67 64
    }
68 65
  
69 66
    public function __toString()
70 67
    {
71
        $outXML=new DOMdocument();
72
        $outXML->preserveWhiteSpace=false;
73
        $outXML->formatOutput=true;
68
        $outXML = new DOMDocument();
69
        $outXML->preserveWhiteSpace = false;
70
        $outXML->formatOutput       = true;
74 71
        $outXML->loadXML(
75 72
            self::sprintf(
76 73
                '<groups>
src/Vigilo/VigiloNetworkEquipment.php
46 46
    {
47 47
        $location = new Location();
48 48
        $location->getFromDB($this->network->fields["locations_id"]);
49
        if (!($location->getName()=='N/A')) {
50
            $locationCompleteName=explode(" > ", $location->getField("completename"));
51
            $locationRealName=implode("/", $locationCompleteName);
52
            $this->children[] = new VigiloGroup($locationRealName);
49
        if ('N/A' !== $location->getName()) {
50
            $locationCompleteName   = explode(" > ", $location->getField("completename"));
51
            $locationRealName       = implode("/", $locationCompleteName);
52
            $this->children[]       = new VigiloGroup($locationRealName);
53 53
        }
54 54

  
55 55
        $entity = new Entity();
56 56
        $entity->getFromDB($this->network->fields["entities_id"]);
57
        if (!($entity->getName()=='N/A')) {
58
            $entityCompleteName=explode(" > ", $entity->getField("completename"));
59
            $entityRealName=implode("/", $entityCompleteName);
60
            $this->children[] = new VigiloGroup($entityRealName);
57
        if ('N/A' !== $entity->getName()) {
58
            $entityCompleteName = explode(" > ", $entity->getField("completename"));
59
            $entityRealName     = implode("/", $entityCompleteName);
60
            $this->children[]   = new VigiloGroup($entityRealName);
61 61
        }
62 62

  
63 63
        $manufacturer = new Manufacturer();
64 64
        $manufacturer->getFromDB($this->network->fields["manufacturers_id"]);
65
        if (!($manufacturer->getName()=='N/A')) {
65
        if ('N/A' !== $manufacturer->getName()) {
66 66
            $this->children[] = new VigiloGroup($manufacturer->getName());
67 67
        }
68 68
    }
......
105 105
        );
106 106

  
107 107
        foreach ($DB->query($query) as $np) {
108
            $query2 = NetworkName::getSQLRequestToSearchForItem("NetworkPort", $np['id']);
109
            $port = new NetworkPort();
110
            $ethport = new NetworkPortEthernet();
108
            $query2     = NetworkName::getSQLRequestToSearchForItem("NetworkPort", $np['id']);
109
            $port       = new NetworkPort();
110
            $ethport    = new NetworkPortEthernet();
111 111
            $port->getFromDB($np['id']);
112 112
            if ($port->getName() == 'lo') {
113 113
                continue;
114 114
            }
115 115

  
116
            $args   = array();
117
            $label  = isset($port->fields['comment']) ? $port->fields['comment'] : $port->getName();
118
            $ethport = $ethport->find('networkports_id=' . $np['id']);
116
            $args       = array();
117
            $label      = isset($port->fields['comment']) ? $port->fields['comment'] : $port->getName();
118
            $ethport    = $ethport->find('networkports_id=' . $np['id']);
119 119
            foreach ($ethport as $rowEthPort) {
120 120
                if ($rowEthPort['speed']) {
121 121
                    $args[] = new VigiloArg('max', $rowEthPort['speed']);
......
143 143

  
144 144
    public function __toString()
145 145
    {
146
        $outXML=new DOMdocument();
147
        $outXML->preserveWhiteSpace=false;
148
        $outXML->formatOutput=true;
146
        $outXML = new DOMDocument();
147
        $outXML->preserveWhiteSpace = false;
148
        $outXML->formatOutput       = true;
149 149
        $outXML->loadXML(
150 150
            self::sprintf(
151 151
                '<?xml version="1.0"?>' .
src/Vigilo/VigiloPrinter.php
46 46
    {
47 47
        $location = new Location();
48 48
        $location->getFromDB($this->network->fields["locations_id"]);
49
        if (!($location->getName()=='N/A')) {
50
            $locationCompleteName=explode(" > ", $location->getField("completename"));
51
            $locationRealName=implode("/", $locationCompleteName);
52
            $this->children[] = new VigiloGroup($locationRealName);
49
        if ('N/A' !== $location->getName()) {
50
            $locationCompleteName   = explode(" > ", $location->getField("completename"));
51
            $locationRealName       = implode("/", $locationCompleteName);
52
            $this->children[]       = new VigiloGroup($locationRealName);
53 53
        }
54 54

  
55 55
        $entity = new Entity();
56 56
        $entity->getFromDB($this->network->fields["entities_id"]);
57
        if (!($entity->getName()=='N/A')) {
58
            $entityCompleteName=explode(" > ", $entity->getField("completename"));
59
            $entityRealName=implode("/", $entityCompleteName);
60
            $this->children[] = new VigiloGroup($entityRealName);
57
        if ('N/A' !== $entity->getName()) {
58
            $entityCompleteName = explode(" > ", $entity->getField("completename"));
59
            $entityRealName     = implode("/", $entityCompleteName);
60
            $this->children[]   = new VigiloGroup($entityRealName);
61 61
        }
62 62

  
63 63
        $manufacturer = new Manufacturer();
64 64
        $manufacturer->getFromDB($this->network->fields["manufacturers_id"]);
65
        if (!($manufacturer->getName()=='N/A')) {
65
        if ('N/A' !== $manufacturer->getName()) {
66 66
            $this->children[] = new VigiloGroup($manufacturer->getName());
67 67
        }
68 68
    }
......
71 71
    {
72 72
        static $address = null;
73 73

  
74
        if ($address === null && $this->agent) {
74
        if (null === $address && $this->agent) {
75 75
            $addresses = $this->agent->getIPs();
76 76
            if (count($addresses)) {
77 77
                $address = current($addresses);
78 78
            }
79 79
        }
80 80

  
81
        if ($address === null) {
81
        if (null === $address) {
82 82
            $address = $this->network->getName();
83 83
            foreach ($this->addresses as $addr) {
84 84
                if (!$addr->is_ipv4()) {
......
113 113
                continue;
114 114
            }
115 115

  
116
            $args   = array();
117
            $label  = isset($port->fields['comment']) ? $port->fields['comment'] : $port->getName();
118
            $ethport = $ethport->find('networkports_id=' . $np['id']);
116
            $args       = array();
117
            $label      = isset($port->fields['comment']) ? $port->fields['comment'] : $port->getName();
118
            $ethport    = $ethport->find('networkports_id=' . $np['id']);
119 119
            foreach ($ethport as $rowEthPort) {
120 120
                if ($rowEthPort['speed']) {
121 121
                    $args[] = new VigiloArg('max', $rowEthPort['speed']);
......
143 143

  
144 144
    public function __toString()
145 145
    {
146
        $outXML=new DOMdocument();
147
        $outXML->preserveWhiteSpace=false;
148
        $outXML->formatOutput=true;
146
        $outXML = new DOMDocument();
147
        $outXML->preserveWhiteSpace = false;
148
        $outXML->formatOutput       = true;
149 149
        $outXML->loadXML(
150 150
            self::sprintf(
151 151
                '<?xml version="1.0"?>' .
src/Vigilo/VigiloTestSoftware.php
9 9

  
10 10
    public function __construct($computer)
11 11
    {
12
        $this->computer=$computer;
12
        $this->computer     = $computer;
13 13
        $this->softwareBase = getSoftwareList($this->computer);
14
        $this->testTable=array();
15
        $this->addedTests=array();
14
        $this->testTable    = array();
15
        $this->addedTests   = array();
16 16
    }
17 17

  
18 18
    public function getTable()
......
74 74

  
75 75
    protected function addNTPqTest()
76 76
    {
77
        $args=array();
77
        $args = array();
78 78
        $args[] = new VigiloArg('crit', 2000);
79 79
        $args[] = new VigiloArg('warn', 5000);
80 80
        return new VigiloTest('NTPq', $args);
......
92 92

  
93 93
    protected function addMemcachedTest($computer)
94 94
    {
95
        $args=array();
95
        $args = array();
96 96
        $args[] = new VigiloArg('port', 11211);
97 97
        return new VigiloTest('Memcached', $args);
98 98
    }
......
104 104

  
105 105
    protected function addPGSQLTest($computer)
106 106
    {
107
        $args=array();
107
        $args = array();
108 108
        $args[] = new VigiloArg('database', "postgres");
109 109
        $args[] = new VigiloArg('port', 5432);
110 110
        $args[] = new VigiloArg('user', "postgres");
......
113 113

  
114 114
    protected function addProxyTest()
115 115
    {
116
        $args=array();
116
        $args = array();
117 117
        $args[] = new VigiloArg('auth', "False");
118 118
        $args[] = new VigiloArg('port', 8080);
119 119
        $args[] = new VigiloArg('url', "http://www.google.fr");
......
122 122

  
123 123
    protected function addRRDcachedTest($computer)
124 124
    {
125
        $path="/var/lib/vigilo/connector-metro/rrdcached.sock";
126
        $args=array();
125
        $path = "/var/lib/vigilo/connector-metro/rrdcached.sock";
126
        $args = array();
127 127
        $args[] = new VigiloArg('crit', 0);
128 128
        $args[] = new VigiloArg('path', $path);
129 129
        $args[] = new VigiloArg('warn', 0);
......
137 137

  
138 138
    protected function addVigiloConnectorTest($type)
139 139
    {
140
        $args=array();
140
        $args = array();
141 141
        $args[] = new VigiloArg('type', $type);
142 142
        return new VigiloTest('VigiloConnector', $args);
143 143
    }
144 144

  
145 145
    protected function addVigiloCorrelatorTest()
146 146
    {
147
        $args=array();
147
        $args = array();
148 148
        //$args[] = new VigiloArg('rules', '');
149 149
        $args[] = new VigiloArg('servicename', 'vigilo-correlator');
150 150
        return new VigiloTest('VigiloCorrelator', $args);
......
152 152

  
153 153
    protected function addTestService($computer, $service)
154 154
    {
155
        $args=array();
155
        $args = array();
156 156
        $args[] = new VigiloArg('svcname', $service);
157 157
        return new VigiloTest('Service', $args);
158 158
    }
src/autoloader.php
2 2

  
3 3
function vigilo_autoloader($class_name)
4 4
{
5
    if (strncmp($class_name, 'Vigilo', 6)==0) {
5
    if (!strncmp($class_name, 'Vigilo', 6)) {
6 6
        require_once(__DIR__ . DIRECTORY_SEPARATOR . 'Vigilo' . DIRECTORY_SEPARATOR . $class_name . '.php');
7 7
    }
8 8
}
src/plugin.php
5 5
    global $PLUGIN_HOOKS;
6 6
    global $DB;
7 7
    $hooks      =& $PLUGIN_HOOKS;
8
    $p          =  "vigilo";
9
    $hookObj    =  new VigiloHooks();
8
    $p          = "vigilo";
9
    $hookObj    = new VigiloHooks();
10 10

  
11
    $hooks['csrf_compliant'][$p]        = true;
12
    $hooks['item_add'][$p]              = array("Computer" => array($hookObj, "addComputer"),
13
                                                "NetworkEquipment" => array($hookObj, "addNetworkEquipment"),
14
                                                "Printer" => array($hookObj, "addPrinter"));
15
    $hooks['item_update'][$p]           = array("Computer" => array($hookObj, "updateComputer"),
16
                                                "NetworkEquipment" => array($hookObj, "updateNetworkEquipment"),
17
                                                "Printer" => array($hookObj, "updatePrinter"));
18
    $hooks['item_purge'][$p]            = array("Computer" => array($hookObj, "delete"),
19
                                                "NetworkEquipment" => array($hookObj, "delete"),
20
                                                "Printer" => array($hookObj, "delete"));
21
    $hooks['item_delete'][$p]           = array("Computer" => array($hookObj, "delete"),
22
                                                "NetworkEquipment" => array($hookObj, "delete"),
23
                                                "Printer" => array($hookObj, "delete"));
24
    $hooks['item_restore'][$p]          = array("Computer" => array($hookObj, "addComputer"),
25
                                                "NetworkEquipment" => array($hookObj, "addNetworkEquipment"),
26
                                                "Printer" => array($hookObj, "addPrinter"));
11
    $hooks['csrf_compliant'][$p]    = true;
12
    $hooks['item_add'][$p]          = array("Computer" => array($hookObj, "addComputer"),
13
                                            "NetworkEquipment" => array($hookObj, "addNetworkEquipment"),
14
                                            "Printer" => array($hookObj, "addPrinter"));
15
    $hooks['item_update'][$p]       = array("Computer" => array($hookObj, "updateComputer"),
16
                                            "NetworkEquipment" => array($hookObj, "updateNetworkEquipment"),
17
                                            "Printer" => array($hookObj, "updatePrinter"));
18
    $hooks['item_purge'][$p]        = array("Computer" => array($hookObj, "delete"),
19
                                            "NetworkEquipment" => array($hookObj, "delete"),
20
                                            "Printer" => array($hookObj, "delete"));
21
    $hooks['item_delete'][$p]       = array("Computer" => array($hookObj, "delete"),
22
                                            "NetworkEquipment" => array($hookObj, "delete"),
23
                                            "Printer" => array($hookObj, "delete"));
24
    $hooks['item_restore'][$p]      = array("Computer" => array($hookObj, "addComputer"),
25
                                            "NetworkEquipment" => array($hookObj, "addNetworkEquipment"),
26
                                            "Printer" => array($hookObj, "addPrinter"));
27 27

  
28 28
    $events = array('item_add', 'item_update', 'item_purge', 'item_delete', 'item_restore');
29 29
    foreach ($events as $event) {
......
47 47
    $hooks["menu_toadd"][$p]['plugins'] = 'PluginVigiloMenu';
48 48
    $hooks['config_page'][$p]           = 'front/menu.php?itemtype=vigilo';
49 49
    $hooks['autoinventory_information'][$p] = array(
50
            'Computer' =>  array('PluginVigiloComputer',
51
                                 'showComputerInfo'));
50
        'Computer' => array('PluginVigiloComputer', 'showComputerInfo')
51
    );
52 52

  
53 53
    if (!FieldExists('glpi_computers', 'vigilo_template')) {
54 54
        $query = "ALTER TABLE glpi_computers ADD vigilo_template VARCHAR(30)";
src/vigilo_hooks.php
21 21
        }
22 22

  
23 23
        $res = file_put_contents($file, $host, LOCK_EX);
24
        if ($res !== false) {
24
        if (false !== $res) {
25 25
            chgrp($file, "vigiconf");
26 26
            chmod($file, 0660);
27 27
        }
......
37 37
    {
38 38
        global $DB;
39 39

  
40
        if ($computer->getField("is_template") == 0) {
40
        if (!$computer->getField("is_template")) {
41 41
            $template_id = PluginVigiloVigiloTemplate::getVigiloTemplateNameByID(
42 42
                $computer->getField("vigilo_template")
43 43
            );
......
61 61

  
62 62
    public function addNetworkEquipment($networkequipment)
63 63
    {
64
        if ($networkequipment->getField("is_template") == 0) {
65
            global $DB;
66

  
64
        if (!$networkequipment->getField("is_template")) {
67 65
            $host = new VigiloNetworkEquipment($networkequipment);
68 66
            $this->saveHost($host, "hosts");
69 67
        }
......
71 69

  
72 70
    public function addPrinter($printer)
73 71
    {
74
        if ($printer->getField("is_template") == 0) {
75
            global $DB;
76

  
72
        if (!$printer->getField("is_template")) {
77 73
            $host = new VigiloPrinter($printer);
78 74
            $this->saveHost($host, "hosts");
79 75
        }
......
86 82

  
87 83
    public function update($computer)
88 84
    {
89
        global $PLUGIN_HOOKS, $DB;
90 85
        if (isset($computer->oldvalues["name"])) {
91 86
            $this->unmonitor($computer->oldvalues["name"]);
92 87
        }
......
121 116

  
122 117
    public function manageComputerSoftwareVersion($computer_software_version)
123 118
    {
124
        global $DB;
125
        $computer=new Computer();
119
        $computer = new Computer();
126 120
        $computer->getFromDB($computer_software_version->getField("computers_id"));
127 121
        $this->updateComputer($computer);
128 122
    }
129 123

  
130 124
    public function manageSoftwares($software)
131 125
    {
132
        global $DB;
133
        $softwareVer=new SoftwareVersion();
134
        $idSoftwareVersion=$softwareVer->find('softwares_id=' . $software->getID());
126
        $softwareVer = new SoftwareVersion();
127
        $idSoftwareVersion = $softwareVer->find('softwares_id=' . $software->getID());
135 128
        foreach ($idSoftwareVersion as $idVersion) {
136
            if ($idVersion['id']) {
137
                $computerVer=new Computer_SoftwareVersion();
138
                $goodField='softwareversions_id=' . $idVersion['id'];
139
                $updateComp=$computerVer->find($goodField);
140
                foreach ($updateComp as $idComputer) {
141
                    if ($idComputer['computers_id'] != -1) {
142
                        $computer=new Computer();
143
                        $computer->getFromDB($idComputer['computers_id']);
144
                        $this->updateComputer($computer);
145
                    }
129
            if (!$idVersion['id']) {
130
                continue;
131
            }
132

  
133
            $computerVer = new Computer_SoftwareVersion();
134
            $goodField   = 'softwareversions_id=' . $idVersion['id'];
135
            $updateComp  = $computerVer->find($goodField);
136

  
137
            foreach ($updateComp as $idComputer) {
138
                if (-1 === $idComputer['computers_id']) {
139
                    continue;
146 140
                }
141

  
142
                $computer = new Computer();
143
                $computer->getFromDB($idComputer['computers_id']);
144
                $this->updateComputer($computer);
147 145
            }
148 146
        }
149 147
    }
150 148

  
151 149
    public function manageDisks($disk)
152 150
    {
153
        global $DB;
154
        $id=$disk->getField('computers_id');
155
        $computer=new Computer();
151
        $id = $disk->getField('computers_id');
152
        $computer = new Computer();
156 153
        $computer->getFromDB($id);
157 154
        $this->updateComputer($computer);
158 155
    }
159 156

  
160 157
    public function manageAddresses($address)
161 158
    {
162
        global $DB;
163 159
        $id = $address->getField('mainitems_id');
164 160
        $comp = new Computer();
165 161
        $comp->getFromDB($id);
......
168 164

  
169 165
    public function manageNetworks($network)
170 166
    {
171
        global $DB;
172 167
        $id = $network->getField('items_id');
173 168
        $itemtype = $network->getField('itemtype');
174 169
        if ($itemtype === 'Computer') {
......
192 187
        // Le nom de la méthode est imposé par GLPI.
193 188
        // @codingStandardsIgnoreEnd
194 189
        $options = array();
190

  
195 191
        if ($itemtype == 'Computer' || $itemtype == 'PluginVigiloComputer') {
196 192
            $options['7007']['table']          = 'glpi_computers';
197 193
            $options['7007']['field']          = 'vigilo_template';
......
199 195
            $options['7007']['massiveaction']  = 'TRUE';
200 196
            $options['7007']['datatype']       = 'dropdown';
201 197
        }
198

  
202 199
        return $options;
203 200
    }
204 201
}

Also available in: Unified diff