Skip to content
This repository was archived by the owner on Aug 9, 2021. It is now read-only.

Commit ce02bd7

Browse files
authored
Merge branch 'develop' into feature/installer_improvements
2 parents 799a13a + d9e2b18 commit ce02bd7

18 files changed

+291
-248
lines changed

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ env:
1313
- AFTER_SUCCESS_BRANCH=9.3/bugfixes
1414
- secure: Y9sG3lZ3Fn3t5BXvcMJQxWsdSUVQgF4M08E6oouYrRc95HEj3ZwZOqp6Df58u8CQFA0EKJyvCBLn8UicvHGMKAD0RwGLBdSP4Ji9gJRZkyMZi79awSshdva/c8dqVQrRd4asuTNQfcagVJpNDnY8sYusw504JUilK3vFVp+39nNZUkcvT69NGVIlXzgHTYinBkVuqDhf5eVtcLcaESLEshrg+5ZERdm+0KifdJVREzhicJxofnmTl/wBsIP7XiQqspljf2/SxLqreGmWXYXUfqIwIOVtsd9fkZChQCz8USC7P427tH6styRDYuMCtvA9b/T/XacSdKFbuDezff3NbIM3b5BebDyCrOK5MGSOdRUY5RuyZN4R5LjePUE++9QNCUPeDSkfb23v0VfuqXIRAxfdtik517GzFy6O7/e6FU1msVZlGQED7Uek9nqnupj+0lIq+99Jcm1UCNJu1NTL2Tv80XXqySaxyE4Sedq/FiYAsy1bo2cg2367I2b4FhFXaJCKkFHcdjHXAeurkRy/brSPhBNoOO5/GA3RepUErgly4P8TLZqHNZv8rgMUoQ88sdwDyXG7dY4UwWiTlCkxMBTqBqJanlTMA9zn2bYyMDioTGnA7+VYAA8cddjFOMVrmmuFJ+YV2x1+5B5qd+Wt8RPwcPQDyqaiN5amb1HGeMA=
1515
matrix:
16-
- GLPI_BRANCH=9.3.0 FI_BRANCH=glpi9.3+1.0
17-
- GLPI_BRANCH=9.3/bugfixes FI_BRANCH=glpi9.3+1.0
16+
- GLPI_BRANCH=9.3.0 FI_BRANCH=glpi9.3+1.1
17+
- GLPI_BRANCH=9.3/bugfixes FI_BRANCH=glpi9.3
1818
- GLPI_BRANCH=master FI_BRANCH=master
1919

2020
php:

inc/mqttclient.class.php

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,15 +144,14 @@ public function subscribe($topic = "#", $qos = 0) {
144144
*/
145145
public function publish($topic, $message, $qos = 0, $retain = 0) {
146146
try {
147-
if (self::$mqtt !== false) {
148-
$log = new PluginFlyvemdmMqttlog();
149-
if (self::$mqtt->publish_sync($topic, $message, $qos, $retain)) {
150-
$log->saveOutgoingMqttMessage($topic, $message);
151-
return true;
152-
}
153-
} else {
147+
if (self::$mqtt === false) {
154148
throw new Exception("Cannot connect to broker");
155149
}
150+
if (self::$mqtt->publish_sync($topic, $message, $qos, $retain)) {
151+
$log = new PluginFlyvemdmMqttlog();
152+
$log->saveOutgoingMqttMessage($topic, $message);
153+
return true;
154+
}
156155
} catch (Exception $e) {
157156
$error = "Exception while puslishing on $topic : '$message'\n" . $e->getMessage();
158157
$trace = $e->getTraceAsString();

inc/mqttlog.class.php

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,37 @@ protected function saveMqttMessage($direction, $topicList, $msg) {
100100
$msg = $DB->escape($msg);
101101
foreach ($topicList as $topic) {
102102
$topic = $DB->escape($topic);
103+
104+
$chunks = explode('/', $topic, 4);
105+
if ($chunks[0] == '' || !isset($chunks[3])) {
106+
// avoid to save invalid topic formats as starting
107+
// with tailing slash or empty topic strings
108+
continue;
109+
}
110+
111+
$itemtype = '';
112+
$itemId = '';
113+
switch ($chunks[1]) {
114+
case 'fleet':
115+
$itemtype = PluginFlyvemdmFleet::getType();
116+
$itemId = $chunks[2];
117+
break;
118+
case 'agent':
119+
$computer = new Computer();
120+
$computer->getFromDBByCrit(['serial' => $chunks[2]]);
121+
$agent = new PluginFlyvemdmAgent();
122+
$agent->getFromDBByCrit([$computer::getForeignKeyField() => $computer->getID()]);
123+
$itemtype = $agent::getType();
124+
$itemId = $agent->getID();
125+
break;
126+
}
127+
103128
$this->fields['date'] = date('Y-m-d H:i:s');
104129
$this->fields['direction'] = $direction;
105-
$this->fields['topic'] = $topic;
130+
$this->fields['topic'] = $chunks[3];
106131
$this->fields['message'] = $msg;
132+
$this->fields['itemtype'] = $itemtype;
133+
$this->fields['items_id'] = $itemId;
107134
unset($this->fields['id']);
108135
$this->addToDB();
109136
}
@@ -192,10 +219,9 @@ public static function findLogs(PluginFlyvemdmNotifiableInterface $item) {
192219
global $DB;
193220

194221
$condition = [
195-
'DISTINCT FIELDS' => ['id', 'date', 'topic', 'message'],
196-
'WHERE' => ['topic' => ['LIKE', $item->getTopic() . '%']],
222+
'FIELDS' => ['id', 'date', 'topic', 'message'],
223+
'WHERE' => ['itemtype' => $item::getType(), 'items_id' => $item->getID()],
197224
'GROUPBY' => 'topic',
198-
'ORDER' => ['date DESC', 'id DESC'],
199225
];
200226

201227
$result = $DB->request(static::getTable(), $condition);

install/mysql/plugin_flyvemdm_empty.sql

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,12 @@ CREATE TABLE IF NOT EXISTS `glpi_plugin_flyvemdm_mqttlogs` (
104104
`date` datetime DEFAULT NULL,
105105
`direction` varchar(1) NOT NULL DEFAULT '' COMMENT 'I for received message, O for sent message',
106106
`topic` varchar(255) NOT NULL DEFAULT '',
107-
`message` varchar(255) DEFAULT NULL,
107+
`message` mediumtext DEFAULT NULL,
108+
`itemtype` varchar(255) DEFAULT NULL,
109+
`items_id` int(11) NOT NULL DEFAULT '0',
108110
PRIMARY KEY (`id`),
111+
KEY `itemtype` (`itemtype`),
112+
KEY `items_id` (`items_id`),
109113
KEY `date` (`date`),
110114
KEY `topic` (`topic`)
111115
) ENGINE=MyISAM DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci COMMENT='Received MQTT messages log';

install/upgrade_to_2_0.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,32 @@ public function upgrade(Migration $migration) {
355355
$table = 'glpi_plugin_flyvemdm_mqttupdatequeues';
356356
$migration->dropTable($table);
357357

358+
$table = 'glpi_plugin_flyvemdm_mqttlogs';
359+
$migration->changeField($table, 'message', 'message', 'mediumtext');
360+
$migration->addField($table, 'itemtype', 'string', ['after' => 'message']);
361+
$migration->addField($table, 'items_id', 'integer', ['after' => 'itemtype']);
362+
$migration->addKey($table, 'itemtype', 'itemtype');
363+
$migration->addKey($table, 'items_id', 'items_id');
364+
if (!$DB->fieldExists($table, 'name')) {
365+
// upgrade fleets logs to their new format
366+
$migration->addPostQuery("UPDATE $table as t1,
367+
(SELECT id, SUBSTRING_INDEX(SUBSTRING_INDEX(topic, '/', 3), '/', -1) as new_items_id,
368+
SUBSTRING(REPLACE(topic, SUBSTRING_INDEX(topic, '/', 3), ''), 2) as new_topic
369+
FROM $table WHERE topic NOT LIKE '/%' and topic like '%/fleet/%') as t2
370+
SET t1.itemtype = 'PluginFlyvemdmFleet', t1.items_id = t2.new_items_id,
371+
t1.topic = t2.new_topic, t1.topic = t2.new_topic WHERE t1.id = t2.id");
372+
373+
// upgrade agents logs to their new format
374+
$migration->addPostQuery("UPDATE $table as t1,
375+
(SELECT m.id, c.id as new_items_id,
376+
SUBSTRING(REPLACE(topic, SUBSTRING_INDEX(topic, '/', 3), ''), 2) as new_topic
377+
FROM $table as m, glpi_computers as c
378+
WHERE topic NOT LIKE '/%' and topic like '%/agent/%'
379+
AND serial = SUBSTRING_INDEX(SUBSTRING_INDEX(topic, '/', 3), '/', -1)) as t2
380+
SET t1.itemtype = 'PluginFlyvemdmAgent', t1.items_id = t2.new_items_id,
381+
t1.topic = t2.new_topic, t1.topic = t2.new_topic WHERE t1.id = t2.id");
382+
}
383+
358384
// Fix PascalCase symbols
359385
$query = "UPDATE `glpi_plugin_flyvemdm_policies`
360386
SET `symbol` = 'maximumFailedPasswordsForWipe'

tests/before_script.sh

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,19 @@ composer install --no-dev --no-interaction
3333
mkdir plugins/fusioninventory && git clone --depth=35 $FI_SOURCE -b $FI_BRANCH plugins/fusioninventory
3434
IFS=/ read -a repo <<< $TRAVIS_REPO_SLUG
3535
mv ../${repo[1]} plugins/flyvemdm
36+
37+
# patch Fusion Inventory when needed
3638
cd plugins/fusioninventory
37-
if [[ $FI_BRANCH == "glpi9.2+1.0" ]] ; then patch -p1 --batch < ../flyvemdm/tests/patches/fi-fix-obsolete-query.patch; fi
38-
if [[ $FI_BRANCH == "master" ]] ; then patch -p1 --batch < ../flyvemdm/tests/patches/fi-raise-max-version.patch; fi
39+
if [[ $FI_BRANCH == "master" ]] ; then patch -p1 --batch < ../flyvemdm/tests/patches/fusioninventory/fi-raise-max-version.patch; fi
40+
if [[ $FI_BRANCH == "master" ]] ; then patch -p1 --batch < ../flyvemdm/tests/patches/fusioninventory/compat-glpi-9-3-2.diff; fi
41+
if [[ $FI_BRANCH == "glpi9.3" ]] ; then patch -p1 --batch < ../flyvemdm/tests/patches/fusioninventory/compat-glpi-9-3-2.diff; fi
3942
cd ../..
4043

4144
# patch GLPI when needed
42-
if [[ $GLPI_BRANCH == "9.2.1" ]] ; then patch -p1 --batch < plugins/flyvemdm/tests/patches/10f8dabfc5e20bb5a4e7d4ba4b93706871156a8a.diff; fi
45+
# if [[ $GLPI_BRANCH == "9.2.1" ]] ; then patch -p1 --batch < plugins/flyvemdm/tests/patches/glpi/10f8dabfc5e20bb5a4e7d4ba4b93706871156a8a.diff; fi
4346

4447
# prepare plugin to test
4548
cd plugins/flyvemdm
46-
if [[ $GLPI_BRANCH == "master" ]] ; then patch -p1 --batch < tests/patches/glpi-allow-test-on-master-branch.patch; fi
49+
if [[ $GLPI_BRANCH == "master" ]] ; then patch -p1 --batch < tests/patches/allow-test-on-master-branch.patch; fi
4750
composer install --no-interaction
4851

Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
diff --git a/inc/collectrule.class.php b/inc/collectrule.class.php
2+
index 55e700c0f..9df0c229b 100644
3+
--- a/inc/collectrule.class.php
4+
+++ b/inc/collectrule.class.php
5+
@@ -115,7 +115,7 @@ class PluginFusioninventoryCollectRule extends Rule {
6+
* @param array $params
7+
* @return array
8+
*/
9+
- function executeActions($output, $params) {
10+
+ function executeActions($output, $params, array $input = []) {
11+
12+
PluginFusioninventoryToolbox::logIfExtradebug(
13+
"pluginFusioninventory-rules-collect",
14+
@@ -181,7 +181,7 @@ class PluginFusioninventoryCollectRule extends Rule {
15+
default:
16+
//plugins actions
17+
$executeaction = clone $this;
18+
- $output = $executeaction->executePluginsActions($action, $output, $params);
19+
+ $output = $executeaction->executePluginsActions($action, $output, $params, $input);
20+
break;
21+
22+
}
23+
diff --git a/inc/formatconvert.class.php b/inc/formatconvert.class.php
24+
index 506cb2aec..59ad31d96 100644
25+
--- a/inc/formatconvert.class.php
26+
+++ b/inc/formatconvert.class.php
27+
@@ -1598,7 +1598,8 @@ class PluginFusioninventoryFormatconvert {
28+
'VERSION' => 'version',
29+
'COMMENTS' => 'comment',
30+
'INSTALLDATE' => 'date_install',
31+
- 'SYSTEM_CATEGORY' => '_system_category']);
32+
+ 'SYSTEM_CATEGORY' => '_system_category',
33+
+ 'OPERATIONG_SYSTEM' => 'operatingsystems_id']);
34+
if (!isset($array_tmp['name'])
35+
|| $array_tmp['name'] == '') {
36+
if (isset($a_softwares['GUID'])
37+
@@ -1632,11 +1633,13 @@ class PluginFusioninventoryFormatconvert {
38+
//for software dictionnary
39+
if ($nb_RuleDictionnarySoftware > 0) {
40+
$rule_input = [
41+
- "name" => $array_tmp['name'],
42+
- "manufacturer" => $array_tmp['manufacturers_id'],
43+
- "old_version" => $array_tmp['version'],
44+
- "entities_id" => $entities_id_software,
45+
- "_system_category" => $array_tmp['_system_category']
46+
+ "name" => $array_tmp['name'],
47+
+ "manufacturer" => $array_tmp['manufacturers_id'],
48+
+ "old_version" => $array_tmp['version'],
49+
+ "entities_id" => $entities_id_software,
50+
+ "operatingsystems_id" => $array_tmp['operatingsystems_id'],
51+
+ "_system_category" => $array_tmp['_system_category'],
52+
+ "device_id" => isset($a_inventory['Computer']['device_id']) ? $a_inventory['Computer']['device_id'] : 0,
53+
];
54+
$res_rule = $rulecollection->processAllRules($rule_input);
55+
}
56+
diff --git a/inc/inventorycomputerinventory.class.php b/inc/inventorycomputerinventory.class.php
57+
index 8b0a1186c..aae4783a3 100644
58+
--- a/inc/inventorycomputerinventory.class.php
59+
+++ b/inc/inventorycomputerinventory.class.php
60+
@@ -474,6 +474,7 @@ class PluginFusioninventoryInventoryComputerInventory {
61+
$a_computerinventory,
62+
$items_id);
63+
}
64+
+ $a_computerinventory['Computer']['device_id'] = $this->device_id;
65+
$a_computerinventory = $pfFormatconvert->computerSoftwareTransformation(
66+
$a_computerinventory,
67+
$entities_id);
68+
@@ -581,7 +582,7 @@ class PluginFusioninventoryInventoryComputerInventory {
69+
'computer');
70+
}
71+
} else if ($itemtype == 'PluginFusioninventoryUnmanaged') {
72+
-
73+
+ $a_computerinventory['Computer']['device_id'] = $this->device_id;
74+
$a_computerinventory = $pfFormatconvert->computerSoftwareTransformation(
75+
$a_computerinventory,
76+
$entities_id);
77+
diff --git a/inc/inventoryruleentity.class.php b/inc/inventoryruleentity.class.php
78+
index c4e57a977..a13e1ad7f 100644
79+
--- a/inc/inventoryruleentity.class.php
80+
+++ b/inc/inventoryruleentity.class.php
81+
@@ -117,7 +117,7 @@ class PluginFusioninventoryInventoryRuleEntity extends Rule {
82+
* @param array $params
83+
* @return array
84+
*/
85+
- function executeActions($output, $params) {
86+
+ function executeActions($output, $params, array $input = []) {
87+
88+
PluginFusioninventoryToolbox::logIfExtradebug(
89+
"pluginFusioninventory-rules-entity",
90+
@@ -395,7 +395,7 @@ class PluginFusioninventoryInventoryRuleEntity extends Rule {
91+
if ($this->checkCriterias($input)) {
92+
unset($output["_no_rule_matches"]);
93+
$refoutput = $output;
94+
- $output = $this->executeActions($output, $params);
95+
+ $output = $this->executeActions($output, $params, $input);
96+
if (!isset($output['pass_rule'])) {
97+
$this->updateOnlyCriteria($options, $refoutput, $output);
98+
//Hook
99+
diff --git a/inc/inventoryruleimport.class.php b/inc/inventoryruleimport.class.php
100+
index a9454f521..f60115f41 100644
101+
--- a/inc/inventoryruleimport.class.php
102+
+++ b/inc/inventoryruleimport.class.php
103+
@@ -716,7 +716,7 @@ class PluginFusioninventoryInventoryRuleImport extends Rule {
104+
* @param array $params
105+
* @return array
106+
*/
107+
- function executeActions($output, $params) {
108+
+ function executeActions($output, $params, array $input = []) {
109+
if (isset($params['class'])) {
110+
$class = $params['class'];
111+
} else if (isset($_SESSION['plugin_fusioninventory_classrulepassed'])) {
112+
diff --git a/inc/inventoryrulelocation.class.php b/inc/inventoryrulelocation.class.php
113+
index f0e8edeab..05ddf6199 100644
114+
--- a/inc/inventoryrulelocation.class.php
115+
+++ b/inc/inventoryrulelocation.class.php
116+
@@ -117,7 +117,7 @@ class PluginFusioninventoryInventoryRuleLocation extends Rule {
117+
* @param array $params
118+
* @return array
119+
*/
120+
- function executeActions($output, $params) {
121+
+ function executeActions($output, $params, array $input = []) {
122+
123+
PluginFusioninventoryToolbox::logIfExtradebug(
124+
"pluginFusioninventory-rules-location",
125+
diff --git a/phpunit/1_Unit/SoftwareUpdateTest.php b/phpunit/1_Unit/SoftwareUpdateTest.php
126+
index d5203f33a..f30f94428 100644
127+
--- a/phpunit/1_Unit/SoftwareUpdateTest.php
128+
+++ b/phpunit/1_Unit/SoftwareUpdateTest.php
129+
@@ -162,9 +162,12 @@ class SoftwareUpdateTest extends RestoreDatabase_TestCase {
130+
'PUBLISHER' => 'fusioninventory team',
131+
'NAME' => 'fusioninventory',
132+
'VERSION' => '0.85+1.0',
133+
- 'SYSTEM_CATEGORY' => 'devel'
134+
+ 'SYSTEM_CATEGORY' => 'devel',
135+
+ 'OPERATIONG_SYSTEM' => 0
136+
];
137+
138+
+ $a_software['Computer']['device_id'] = 0;
139+
+
140+
$pfFormatconvert = new PluginFusioninventoryFormatconvert();
141+
$a_return = $pfFormatconvert->computerSoftwareTransformation($a_software, 0);
142+

0 commit comments

Comments
 (0)