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

Commit

Permalink
refactor(isntaller): simplify code
Browse files Browse the repository at this point in the history
Signed-off-by: Thierry Bugier <tbugier@teclib.com>
  • Loading branch information
btry authored and ajsb85 committed Mar 23, 2018
1 parent 3a81b65 commit f233c89
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions install/installer.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -647,33 +647,34 @@ protected function createBackendMqttUser($MdmMqttUser, $MdmMqttPassword) {
$mqttUser = new PluginFlyvemdmMqttuser();

// Check the MQTT user account for the plugin exists
if (!$mqttUser->getFromDBByCrit(['user' => $MdmMqttUser])) {
// Create the MQTT user account for the plugin
if (!$mqttUser->add([
'user' => $MdmMqttUser,
'password' => $MdmMqttPassword,
'enabled' => '1',
'_acl' => [
[
'topic' => '#',
'access_level' => PluginFlyvemdmMqttacl::MQTTACL_READ_WRITE,
],
if ($mqttUser->getFromDBByCrit(['user' => $MdmMqttUser])) {
return;
}
// Create the MQTT user account for the plugin
if (!$mqttUser->add([
'user' => $MdmMqttUser,
'password' => $MdmMqttPassword,
'enabled' => '1',
'_acl' => [
[
'topic' => '#',
'access_level' => PluginFlyvemdmMqttacl::MQTTACL_READ_WRITE,
],
])) {
// Failed to create the account
$this->migration->displayWarning('Unable to create the MQTT account for FlyveMDM : ' . $DB->error());
} else {
// Check the ACL has been created
$aclList = $mqttUser->getACLs();
$mqttAcl = array_shift($aclList);
if ($mqttAcl === null) {
$this->migration->displayWarning('Unable to create the MQTT ACL for FlyveMDM : ' . $DB->error());
}

// Save MQTT credentials in configuration
Config::setConfigurationValues("flyvemdm",
['mqtt_user' => $MdmMqttUser, 'mqtt_passwd' => $MdmMqttPassword]);
],
])) {
// Failed to create the account
$this->migration->displayWarning('Unable to create the MQTT account for FlyveMDM : ' . $DB->error());
} else {
// Check the ACL has been created
$aclList = $mqttUser->getACLs();
$mqttAcl = array_shift($aclList);
if ($mqttAcl === null) {
$this->migration->displayWarning('Unable to create the MQTT ACL for FlyveMDM : ' . $DB->error());
}

// Save MQTT credentials in configuration
Config::setConfigurationValues('flyvemdm',
['mqtt_user' => $MdmMqttUser, 'mqtt_passwd' => $MdmMqttPassword]);
}
}

Expand Down

0 comments on commit f233c89

Please sign in to comment.