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

Commit c164cdf

Browse files
committed
feat(config): lock mqtt prefix setting
Signed-off-by: Thierry Bugier <[email protected]>
1 parent b6b28a0 commit c164cdf

6 files changed

+11
-21
lines changed

inc/agent.class.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -548,10 +548,6 @@ public function prepareInputForUpdate($input) {
548548
public function post_addItem() {
549549
// Notify the agent about its fleets
550550
$this->updateSubscription();
551-
552-
if (PluginFlyvemdmConfig::canUpdate()) {
553-
// Here we must update mqtt_prefix_locked
554-
}
555551
}
556552

557553
public function post_getFromDB() {

inc/common.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public static function endsWith($haystack, $needle) {
170170
}
171171

172172
/**
173-
* Removes the mqtt prefix from
173+
* Removes the mqtt prefix from a MQTT topic
174174
*
175175
* @param string $topic Topic to modify
176176
* @param boolean $readConfig set to True to force reading the configuration

inc/config.class.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,16 @@ public static function configUpdate($input) {
406406
}
407407
}
408408

409+
//lock mqtt prefix if needed
410+
$DbUtil = new DbUtils();
411+
$agentsCount = $DbUtil->countElementsInTable('glpi_plugin_flyvemdm_agents');
412+
$fleetsCount = $DbUtil->countElementsInTable('glpi_plugin_flyvemdm_fleets');
413+
$invitationCount = $DbUtil->countElementsInTable('glpi_plugin_flyvemdm_invitations');
414+
if ($agentsCount + $fleetsCount + $invitationCount > 0) {
415+
unset($input['mqtt_prefix']);
416+
Session::addMessageAfterRedirect(__('Update of MQTT prefix ignored (invitations, agents or fleets created)', 'flyvemdm'), false, WARNING);
417+
}
418+
409419
if (isset($_SESSION['plugin_flyvemdm_wizard_step'])) {
410420
$input = static::processStep($input);
411421
if (count($input) > 0 && $input !== false) {
@@ -531,11 +541,4 @@ public function isGlpiConfigured() {
531541

532542
return true;
533543
}
534-
535-
public function prepareInputForUpdate($input) {
536-
if ($input['mqtt_prefix'] != $this->fields['mqtt_prefix'] && $this->fields['mqtt_prefix_locked'] == 0) {
537-
$input['mqtt_prefix_locked'] = 1;
538-
}
539-
return $input;
540-
}
541544
}

inc/fleet.class.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -315,10 +315,6 @@ public function post_addItem() {
315315
$topic = $this->getTopic();
316316
$this->notify("$topic/Policy/$policyName", null, 0, 1);
317317
}
318-
319-
if (PluginFlyvemdmConfig::canUpdate()) {
320-
// Here we must update mqtt_prefix_locked
321-
}
322318
}
323319

324320
/**

inc/invitation.class.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -244,10 +244,6 @@ public function post_addItem() {
244244

245245
// Sent invitation email
246246
$this->sendInvitation();
247-
248-
if (PluginFlyvemdmConfig::canUpdate()) {
249-
// Here we must update mqtt_prefix_locked
250-
}
251247
}
252248

253249
public function post_updateItem($history = 1) {

install/installer.class.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,6 @@ protected function createInitialConfig() {
601601
'mqtt_user' => self::BACKEND_MQTT_USER,
602602
'mqtt_passwd' => $MdmMqttPassword,
603603
'mqtt_prefix' => '',
604-
'mqtt_prefix_locked' => '0',
605604
'instance_id' => $instanceId,
606605
'registered_profiles_id' => '',
607606
'guest_profiles_id' => '',

0 commit comments

Comments
 (0)