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

Commit

Permalink
feat(config): lock mqtt prefix setting
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <[email protected]>
  • Loading branch information
btry committed Aug 1, 2018
1 parent 36c1e27 commit f52f0f4
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 21 deletions.
4 changes: 0 additions & 4 deletions inc/agent.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -545,10 +545,6 @@ public function prepareInputForUpdate($input) {
public function post_addItem() {
// Notify the agent about its fleets
$this->updateSubscription();

if (PluginFlyvemdmConfig::canUpdate()) {
// Here we must update mqtt_prefix_locked
}
}

public function post_getFromDB() {
Expand Down
2 changes: 1 addition & 1 deletion inc/common.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -209,7 +209,7 @@ public static function getGlpiVersion() {
}

/**
* Removes the mqtt prefix from
* Removes the mqtt prefix from a MQTT topic
*
* @param string $topic Topic to modify
* @param boolean $readConfig set to True to force reading the configuration
Expand Down
17 changes: 10 additions & 7 deletions inc/config.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,16 @@ public static function configUpdate($input) {
}
}

//lock mqtt prefix if needed
$DbUtil = new DbUtils();
$agentsCount = $DbUtil->countElementsInTable('glpi_plugin_flyvemdm_agents');
$fleetsCount = $DbUtil->countElementsInTable('glpi_plugin_flyvemdm_fleets');
$invitationCount = $DbUtil->countElementsInTable('glpi_plugin_flyvemdm_invitations');
if ($agentsCount + $fleetsCount + $invitationCount > 0) {
unset($input['mqtt_prefix']);
Session::addMessageAfterRedirect(__('Update of MQTT prefix ignored (invitations, agents or fleets created)', 'flyvemdm'), false, WARNING);
}

if (isset($_SESSION['plugin_flyvemdm_wizard_step'])) {
$input = static::processStep($input);
if (count($input) > 0 && $input !== false) {
Expand Down Expand Up @@ -530,11 +540,4 @@ public function isGlpiConfigured() {

return true;
}

public function prepareInputForUpdate($input) {
if ($input['mqtt_prefix'] != $this->fields['mqtt_prefix'] && $this->fields['mqtt_prefix_locked'] == 0) {
$input['mqtt_prefix_locked'] = 1;
}
return $input;
}
}
4 changes: 0 additions & 4 deletions inc/fleet.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,10 +302,6 @@ public function post_addItem() {
$topic = $this->getTopic();
$this->notify("$topic/Policy/$policyName", null, 0, 1);
}

if (PluginFlyvemdmConfig::canUpdate()) {
// Here we must update mqtt_prefix_locked
}
}

/**
Expand Down
4 changes: 0 additions & 4 deletions inc/invitation.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -270,10 +270,6 @@ public function post_addItem() {

// Sent invitation email
$this->sendInvitation();

if (PluginFlyvemdmConfig::canUpdate()) {
// Here we must update mqtt_prefix_locked
}
}

public function post_updateItem($history = 1) {
Expand Down
1 change: 0 additions & 1 deletion install/installer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,6 @@ protected function createInitialConfig() {
'mqtt_user' => self::BACKEND_MQTT_USER,
'mqtt_passwd' => $MdmMqttPassword,
'mqtt_prefix' => '',
'mqtt_prefix_locked' => '0',
'instance_id' => $instanceId,
'registered_profiles_id' => '',
'guest_profiles_id' => '',
Expand Down

0 comments on commit f52f0f4

Please sign in to comment.