From be1df49ebd38386bea48917acda82dfc0b763cdc Mon Sep 17 00:00:00 2001 From: Domingo Oropeza Date: Thu, 13 Sep 2018 16:05:15 -0400 Subject: [PATCH] fix(install): set missing agent base url on cli_install Signed-off-by: Domingo Oropeza --- install/install.php | 25 +++++++------------ .../2_Integration/Deploy/DeploymirrorTest.php | 16 +++++++++--- 2 files changed, 21 insertions(+), 20 deletions(-) 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/2_Integration/Deploy/DeploymirrorTest.php b/phpunit/2_Integration/Deploy/DeploymirrorTest.php index 28f778d6ab..071edd7def 100644 --- a/phpunit/2_Integration/Deploy/DeploymirrorTest.php +++ b/phpunit/2_Integration/Deploy/DeploymirrorTest.php @@ -57,15 +57,23 @@ public function testGestList() { (`id`, `name`, `entities_id`, `completename`, `level`, `tag`) VALUES (2, 'entity B', 0, 'Root entity > entity B', 2, 'entB')"); + $iterator = $DB->request([ + 'SELECT' => 'value', + 'FROM' => Config::getTable(), + 'WHERE' => ['name' => 'url_base'], + ]); + $row = $iterator->next(); + $agent_base_url = rtrim($row['value'], '/'); + $DB->query("INSERT INTO `glpi_plugin_fusioninventory_entities` (`id`, `entities_id`, `transfers_id_auto`, `agent_base_url`) - VALUES (NULL, 0, 0, 'http://localhost:8080/glpi')"); + VALUES (NULL, 0, 0, '" . $agent_base_url . "')"); $DB->query("INSERT INTO `glpi_plugin_fusioninventory_entities` (`id`, `entities_id`, `transfers_id_auto`, `agent_base_url`) - VALUES (NULL, 1, 0, 'http://localhost:8080/glpi')"); + VALUES (NULL, 1, 0, '" . $agent_base_url . "')"); $DB->query("INSERT INTO `glpi_plugin_fusioninventory_entities` (`id`, `entities_id`, `transfers_id_auto`, `agent_base_url`) - VALUES (NULL, 2, 0, 'http://localhost:8080/glpi')"); + VALUES (NULL, 2, 0, '" . $agent_base_url . "')"); //Set root entity with child entities $_SESSION['glpiactive_entity'] = 0; @@ -141,7 +149,7 @@ public function testGestList() { 'entities_id' => 2 ]); - $server_download_url = "http://localhost:8080/glpi/plugins/fusioninventory/b/deploy/?action=getFilePart&file="; + $server_download_url = $agent_base_url . "/plugins/fusioninventory/b/deploy/?action=getFilePart&file="; //Add the server's url at the end of the mirrors list $PF_CONFIG['server_as_mirror'] = true;