Skip to content

Commit

Permalink
update install function to check config
Browse files Browse the repository at this point in the history
  • Loading branch information
Mary-Clb committed Jan 8, 2025
1 parent 1162306 commit a0ea0c2
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
22 changes: 14 additions & 8 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,21 @@
*/

use GlpiPlugin\Centreon\Host;
use GLPIKey;

/**
* Plugin install process
*
* @return boolean
*/
function plugin_centreon_install()
function plugin_centreon_install($version)
{
/** @var DBmysql $DB */
global $DB;

$default_charset = DBConnection::getDefaultCharset();
$default_collation = DBConnection::getDefaultCollation();

$migration = new \Migration(PLUGIN_CENTREON_VERSION);

$table = GlpiPlugin\Centreon\Host::getTable();
if (!$DB->tableExists($table)) {
$query = "CREATE TABLE `$table` (
Expand All @@ -60,9 +59,16 @@ function plugin_centreon_install()
COLLATE={$default_collation}";
$DB->queryOrDie($query, $DB->error());
}
Toolbox::logDebug($table);
$migration->executeMigration();

$centreon_password = Config::getConfigurationValue('plugin:centreon', 'centreon-password');
/**Migration to 1.0.1 */
if ($centreon_password !== null) {
$decrypted_pwd = @(new GLPIKey())->decrypt($centreon_password);
if ($decrypted_pwd == '') {
Config::setConfigurationValues('plugin:centreon', [
'centreon-password' => (new GLPIKey())->encrypt($centreon_password)
]);
}
}
return true;
}

Expand All @@ -85,10 +91,10 @@ function plugin_centreon_uninstall()
$DB->error();
}

return true;

$config = new \Config();
$config->deleteByCriteria(['context' => 'plugin:centreon']);

return true;
}

function plugin_centreon_getAddSearchOptionsNew($itemtype)
Expand Down
2 changes: 1 addition & 1 deletion setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
* -------------------------------------------------------------------------
*/

define('PLUGIN_CENTREON_VERSION', '1.0.0');
define('PLUGIN_CENTREON_VERSION', '1.0.2');

// Minimal GLPI version, inclusive
define('PLUGIN_CENTREON_MIN_GLPI_VERSION', '10.0.0');
Expand Down
1 change: 0 additions & 1 deletion src/Host.php
Original file line number Diff line number Diff line change
Expand Up @@ -459,5 +459,4 @@ public static function getSpecificValueToDisplay($field, $values, array $options

return parent::getSpecificValueToDisplay($field, $values, $options);
}

}

0 comments on commit a0ea0c2

Please sign in to comment.