From 079936824b045026ba0ca118830b46a2390f3267 Mon Sep 17 00:00:00 2001 From: Domingo Oropeza Date: Thu, 13 Sep 2018 16:03:20 -0400 Subject: [PATCH 1/2] feat(install): set default user for cli_install Signed-off-by: Domingo Oropeza --- phpunit/0_Install/FusinvInstallTest.php | 4 ++-- scripts/cli_install.php | 7 ++++++- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/phpunit/0_Install/FusinvInstallTest.php b/phpunit/0_Install/FusinvInstallTest.php index 87777213ea..12046f054b 100644 --- a/phpunit/0_Install/FusinvInstallTest.php +++ b/phpunit/0_Install/FusinvInstallTest.php @@ -95,9 +95,9 @@ public function testForceInstall() { function install($force = false) { $output = []; $returncode = 0; - $command = "php -f ".FUSINV_ROOT. "/scripts/cli_install.php -- --as-user 'glpi'"; + $command = "php -f ".FUSINV_ROOT. "/scripts/cli_install.php"; if ($force) { - $command.= " --force-install"; + $command.= " -- --as-user 'glpi' --force-install"; } exec($command, $output, $returncode); $this->assertEquals(0, $returncode, diff --git a/scripts/cli_install.php b/scripts/cli_install.php index 9549e9f780..22bb546c7a 100755 --- a/scripts/cli_install.php +++ b/scripts/cli_install.php @@ -104,9 +104,14 @@ die("GLPI not installed\n"); } +$user = new User(); if (!is_null($args['--as-user'])) { - $user = new User(); $user->getFromDBbyName($args['--as-user']); +} else { + $user->getFromDBbyName('glpi'); +} + +if (!$user->isNewItem()) { $auth = new Auth(); $auth->auth_succeded = true; $auth->user = $user; From a03bbd3fee322b3c03f6754c4ded3423ef00b3b7 Mon Sep 17 00:00:00 2001 From: Domingo Oropeza Date: Thu, 13 Sep 2018 16:05:15 -0400 Subject: [PATCH 2/2] fix(install): set missing agent base url on cli_install Signed-off-by: Domingo Oropeza --- inc/inventorycomputerlib.class.php | 2 +- install/install.php | 25 +++++++++---------------- phpunit/bootstrap.php | 4 ++++ 3 files changed, 14 insertions(+), 17 deletions(-) diff --git a/inc/inventorycomputerlib.class.php b/inc/inventorycomputerlib.class.php index 545b3f5cbb..fb1376322a 100644 --- a/inc/inventorycomputerlib.class.php +++ b/inc/inventorycomputerlib.class.php @@ -173,7 +173,7 @@ function updateComputer($a_computerinventory, $computers_id, $no_history, $setdy //OS exists, check for updates $same = true; foreach ($input_os as $key => $value) { - if ($ios->fields[$key] != $value) { + if (key_exists($key, $ios->fields) && $ios->fields[$key] != $value) { $same = false; break; } diff --git a/install/install.php b/install/install.php index 75c7b62b1a..89fdae3863 100644 --- a/install/install.php +++ b/install/install.php @@ -337,22 +337,15 @@ function pluginFusioninventoryInstall($version, $migrationname = 'Migration') { /* * Define when install agent_base_url in glpi_plugin_fusioninventory_entities */ - $full_url = filter_input(INPUT_SERVER, "PHP_SELF"); - $https = filter_input(INPUT_SERVER, "HTTPS"); - $http_host = filter_input(INPUT_SERVER, "HTTP_HOST"); - if (!empty($full_url) && !strstr($full_url, 'cli_install.php')) { - if (!empty($https)) { - $agent_base_url = 'https://'.$http_host.$full_url; - } else { - $agent_base_url = 'http://'.$http_host.$full_url; - } - $agent_base_url = str_replace('/front/plugin.form.php', '', $agent_base_url); - $DB->update( - 'glpi_plugin_fusioninventory_entities', [ - 'agent_base_url' => $agent_base_url - ], [ - 'id' => 1 - ] + $iterator = $DB->request([ + 'SELECT' => 'value', + 'FROM' => Config::getTable(), + 'WHERE' => ['name' => 'url_base'], + ]); + if ($row = $iterator->next()) { + $DB->update('glpi_plugin_fusioninventory_entities', + ['agent_base_url' => rtrim($row['value'], '/')], + ['id' => 1] ); } diff --git a/phpunit/bootstrap.php b/phpunit/bootstrap.php index 66ab3bed62..c281da0c69 100644 --- a/phpunit/bootstrap.php +++ b/phpunit/bootstrap.php @@ -9,6 +9,10 @@ include('./glpi/inc/includes.php'); +Config::setConfigurationValues('core', [ + 'url_base' => 'http://localhost:8088' +]); + if (!defined('FUSINV_ROOT')) { define('FUSINV_ROOT', GLPI_ROOT . DIRECTORY_SEPARATOR . '/plugins/fusioninventory'); set_include_path(