Revision 925171f8
[#1637] Propagation du nom du template
Evite que le nom du template Vigilo associé à la machine ne soit perdu
lorsqu'on modifie un objet rattaché à la machine (IPAddress,
NetworkName, SoftwareInstallation, etc.).
Change-Id: I6e4b7df2d926547bf19afc8de6e2469caf54867c
Refs: #1637
Reviewed-on: https://vigilo-dev.si.c-s.fr/review/2576
Tested-by: Build system <qa@vigilo-dev.si.c-s.fr>
Reviewed-by: Francois POIROTTE <francois.poirotte@c-s.fr>
src/plugins/vigilo/inc/abstractmonitoreditem.class.php | ||
---|---|---|
55 | 55 |
|
56 | 56 |
protected function selectTemplates() |
57 | 57 |
{ |
58 |
$template = isset($this->item->fields['vigilo_template']) ? |
|
59 |
$this->item->fields['vigilo_template'] : null; |
|
58 |
$template = PluginVigiloTemplate::getTemplateNameForItem($this->item); |
|
60 | 59 |
if (null !== $template) { |
61 | 60 |
$this->children[] = new VigiloTemplate($template); |
62 | 61 |
} |
src/plugins/vigilo/inc/template.class.php | ||
---|---|---|
97 | 97 |
} |
98 | 98 |
return $res; |
99 | 99 |
} |
100 |
|
|
101 |
public static function getTemplateIndexForItem(CommonDBTM $item) |
|
102 |
{ |
|
103 |
$tpl = self::getTemplateNameForItem($item); |
|
104 |
if (null === $tpl) { |
|
105 |
return null; |
|
106 |
} |
|
107 |
|
|
108 |
$templates = self::getTemplates(); |
|
109 |
$index = array_search($tpl, $templates, true); |
|
110 |
return (false !== $index ? $index : null); |
|
111 |
} |
|
112 |
|
|
113 |
public static function getTemplateNameForItem(CommonDBTM $item) |
|
114 |
{ |
|
115 |
global $DB; |
|
116 |
|
|
117 |
$id = $item->getID(); |
|
118 |
$query = <<<SQL |
|
119 |
SELECT `template` |
|
120 |
FROM glpi_plugin_vigilo_template |
|
121 |
WHERE `id` = $id; |
|
122 |
SQL; |
|
123 |
|
|
124 |
$result = $DB->query($query); |
|
125 |
if (!$result) { |
|
126 |
return null; |
|
127 |
} |
|
128 |
|
|
129 |
return $DB->result($result, 0, "template"); |
|
130 |
} |
|
100 | 131 |
} |
src/plugins/vigilo/vigilo_hooks.php | ||
---|---|---|
6 | 6 |
// concernant les équipements supportés. |
7 | 7 |
public function preItemUpdate($item) |
8 | 8 |
{ |
9 |
global $DB; |
|
10 |
|
|
11 |
$id = $item->getID(); |
|
12 |
$query = <<<SQL |
|
13 |
SELECT `template` |
|
14 |
FROM glpi_plugin_vigilo_template |
|
15 |
WHERE `id` = $id; |
|
16 |
SQL; |
|
17 |
|
|
18 |
$item->fields['vigilo_template'] = 0; |
|
19 |
$result = $DB->query($query); |
|
20 |
if ($result) { |
|
21 |
$tpl = $DB->result($result, 0, "template"); |
|
22 |
$templates = PluginVigiloTemplate::getTemplates(); |
|
23 |
$index = array_search($tpl, $templates, true); |
|
24 |
if (false !== $index) { |
|
25 |
$item->fields['vigilo_template'] = $index; |
|
26 |
} |
|
27 |
} |
|
9 |
$index = PluginVigiloTemplate::getTemplateIndexForItem($item); |
|
10 |
$item->fields['vigilo_template'] = (int) $index; |
|
28 | 11 |
} |
29 | 12 |
|
30 | 13 |
public function itemAddOrUpdate($item) |
... | ... | |
43 | 26 |
ON DUPLICATE KEY UPDATE `template` = '$template'; |
44 | 27 |
SQL; |
45 | 28 |
$DB->query($query); |
46 |
$item->fields['vigilo_template'] = $templates[$tplId]; |
|
47 |
} else { |
|
48 |
$item->fields['vigilo_template'] = null; |
|
49 | 29 |
} |
50 | 30 |
|
51 | 31 |
// Si la mise à jour modifie le technicien associé à la machine, |
Also available in: Unified diff