mirror of
https://github.com/Combodo/iTop.git
synced 2026-09-08 22:38:22 +02:00
N°9979 - Hide "keep current choice" setup button in case of a package upgrade (#1026)
* N°9979 - phstan cleanup * N°9979 - Hide keep current choice setup button in case of a package upgrade * N°9979 - optimize SQL queries
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
|
||||
class ModuleInstallationRepository
|
||||
{
|
||||
private static ModuleInstallationRepository $oInstance;
|
||||
private static ?ModuleInstallationRepository $oInstance;
|
||||
|
||||
protected function __construct()
|
||||
{
|
||||
@@ -60,6 +60,7 @@ class ModuleInstallationRepository
|
||||
CMDBSource::InitFromConfig($oConfig);
|
||||
//read db module installations
|
||||
$tableWithPrefix = $this->GetTableWithPrefix($oConfig);
|
||||
|
||||
$iRootId = CMDBSource::QueryToScalar("SELECT max(parent_id) FROM $tableWithPrefix");
|
||||
// Get the latest installed modules, without the "root" ones (iTop version and datamodel version)
|
||||
$sSQL = <<<SQL
|
||||
@@ -94,10 +95,7 @@ SQL;
|
||||
public function GetApplicationVersion(Config $oConfig)
|
||||
{
|
||||
try {
|
||||
CMDBSource::InitFromConfig($oConfig);
|
||||
$tableWithPrefix = $this->GetTableWithPrefix($oConfig);
|
||||
$sSQLQuery = "SELECT * FROM $tableWithPrefix";
|
||||
$aSelectInstall = CMDBSource::QueryToArray($sSQLQuery);
|
||||
$aSelectInstall = $this->ReadFromDB($oConfig);
|
||||
} catch (MySQLException $e) {
|
||||
// No database or erroneous information
|
||||
SetupLog::Error(
|
||||
@@ -105,8 +103,6 @@ SQL;
|
||||
null,
|
||||
[
|
||||
'host' => $oConfig->Get('db_host'),
|
||||
'user' => $oConfig->Get('db_user'),
|
||||
'pwd:' => $oConfig->Get('db_pwd'),
|
||||
'db name' => $oConfig->Get('db_name'),
|
||||
'msg' => $e->getMessage(),
|
||||
]
|
||||
|
||||
@@ -1276,14 +1276,14 @@ class RunTimeEnvironment
|
||||
* - plus the list of modules present in the "extra" directory of the build environment: data/<build_environment>-modules/
|
||||
*
|
||||
* @param string $sSourceEnv The name of the source environment to 'imitate'
|
||||
* @param null $bUseSymLinks Whether to create symbolic links instead of copies
|
||||
* @param bool|null $bUseSymLinks Whether to create symbolic links instead of copies
|
||||
* @param array $aAddedExtensions List of additional extensions to add to the build environment
|
||||
*
|
||||
* @return string[]
|
||||
* @throws \ConfigException
|
||||
* @throws \CoreException
|
||||
*/
|
||||
public function CompileFrom($sSourceEnv, $bUseSymLinks = null, $aAddedExtensions = [])
|
||||
public function CompileFrom($sSourceEnv, ?bool $bUseSymLinks = null, $aAddedExtensions = [])
|
||||
{
|
||||
$oConfig = new Config(utils::GetConfigFilePath($sSourceEnv));
|
||||
$this->InitExtensionMap($oConfig);
|
||||
|
||||
@@ -158,15 +158,45 @@ HTML
|
||||
</form>
|
||||
HTML
|
||||
);
|
||||
$oPage->add_ready_script(
|
||||
<<<JS
|
||||
|
||||
if ($this->DisplaySetupShortcutButton()) {
|
||||
$oPage->add_ready_script(
|
||||
<<<JS
|
||||
$('.ibo-setup--wizard--buttons-container tr td:nth-child(1)').before('<td style="text-align:center;"><button class="ibo-button ibo-is-alternative ibo-is-neutral" form="fast_setup"><span class="ibo-button--label">Keep current choices</span></button></td>');
|
||||
JS
|
||||
);
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function DisplaySetupShortcutButton(): bool
|
||||
{
|
||||
if ('install' === $this->oWizard->GetParameter('mode', 'install')) {
|
||||
//fresh install
|
||||
return false;
|
||||
}
|
||||
|
||||
$oConfig = utils::GetConfig();
|
||||
$res = ModuleInstallationRepository::GetInstance()->GetApplicationVersion($oConfig);
|
||||
if (false === $res) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$sProductName = $res['product_name'] ?? null;
|
||||
$sProductVersion = $res['product_version'] ?? null;
|
||||
if (is_null($sProductName) || is_null($sProductVersion)) {
|
||||
\SetupLog::Error(__METHOD__.": cannot fetch itop version", null, $res);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (ITOP_VERSION_FULL !== $sProductVersion) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (ITOP_APPLICATION === $sProductName);
|
||||
}
|
||||
|
||||
public function CanMoveForward()
|
||||
{
|
||||
return $this->bCanMoveForward;
|
||||
|
||||
134
tests/php-unit-tests/unitary-tests/setup/WizStepWelcomeTest.php
Normal file
134
tests/php-unit-tests/unitary-tests/setup/WizStepWelcomeTest.php
Normal file
@@ -0,0 +1,134 @@
|
||||
<?php
|
||||
|
||||
namespace Combodo\iTop\Test\UnitTest\Integration;
|
||||
|
||||
use Combodo\iTop\Test\UnitTest\ItopDataTestCase;
|
||||
use WizardController;
|
||||
use ModuleInstallationRepository;
|
||||
|
||||
class WizStepWelcomeTest extends ItopDataTestCase
|
||||
{
|
||||
protected function setUp(): void
|
||||
{
|
||||
parent::setUp(); // TODO: Change the autogenerated stub
|
||||
require_once(APPROOT.'/setup/wizardsteps_autoload.php');
|
||||
require_once(APPROOT.'/setup/moduleinstallation/ModuleInstallationRepository.php');
|
||||
}
|
||||
|
||||
protected function tearDown(): void
|
||||
{
|
||||
parent::tearDown(); // TODO: Change the autogenerated stub
|
||||
ModuleInstallationRepository::SetInstance(null);
|
||||
}
|
||||
|
||||
public function testDisplaySetupShortcutButton_NoButtonWhenFreshInstall()
|
||||
{
|
||||
$oWizard = $this->createMock(WizardController::class);
|
||||
$this->GivenSetupMode($oWizard);
|
||||
|
||||
$oWiz = new \WizStepWelcome($oWizard, "");
|
||||
$this->assertEquals(false, $oWiz->DisplaySetupShortcutButton());
|
||||
}
|
||||
|
||||
public function testDisplaySetupShortcutButton_NoButtonWhenNoItopVersionFetched()
|
||||
{
|
||||
$oWizard = $this->createMock(WizardController::class);
|
||||
$this->GivenSetupMode($oWizard, 'upgrade');
|
||||
|
||||
$aApplicationVersion = [
|
||||
'product_name' => ITOP_APPLICATION,
|
||||
];
|
||||
$this->GivenGetApplicationVersion($aApplicationVersion);
|
||||
|
||||
$oWiz = new \WizStepWelcome($oWizard, "");
|
||||
$this->assertEquals(false, $oWiz->DisplaySetupShortcutButton());
|
||||
}
|
||||
|
||||
public function testDisplaySetupShortcutButton_NoButtonWhenNoApplicationVersionFetched()
|
||||
{
|
||||
$oWizard = $this->createMock(WizardController::class);
|
||||
$this->GivenSetupMode($oWizard, 'upgrade');
|
||||
|
||||
$aApplicationVersion = [
|
||||
'product_version' => ITOP_VERSION_FULL,
|
||||
];
|
||||
$this->GivenGetApplicationVersion($aApplicationVersion);
|
||||
|
||||
$oWiz = new \WizStepWelcome($oWizard, "");
|
||||
$this->assertEquals(false, $oWiz->DisplaySetupShortcutButton());
|
||||
}
|
||||
|
||||
public function testDisplaySetupShortcutButton_NoButtonWhenApplicationChangeDuringUpgrade()
|
||||
{
|
||||
$oWizard = $this->createMock(WizardController::class);
|
||||
$this->GivenSetupMode($oWizard, 'upgrade');
|
||||
|
||||
$aApplicationVersion = [
|
||||
'product_version' => ITOP_VERSION_FULL,
|
||||
'product_name' => 'toto',
|
||||
];
|
||||
$this->GivenGetApplicationVersion($aApplicationVersion);
|
||||
|
||||
$oWiz = new \WizStepWelcome($oWizard, "");
|
||||
$this->assertEquals(false, $oWiz->DisplaySetupShortcutButton());
|
||||
}
|
||||
|
||||
public function testDisplaySetupShortcutButton_NoButtonWhenVersionChangeDuringUpgrade()
|
||||
{
|
||||
$oWizard = $this->createMock(WizardController::class);
|
||||
$this->GivenSetupMode($oWizard, 'upgrade');
|
||||
|
||||
$aApplicationVersion = [
|
||||
'product_version' => '6.6.6',
|
||||
'product_name' => ITOP_APPLICATION,
|
||||
];
|
||||
$this->GivenGetApplicationVersion($aApplicationVersion);
|
||||
|
||||
$oWiz = new \WizStepWelcome($oWizard, "");
|
||||
$this->assertEquals(false, $oWiz->DisplaySetupShortcutButton());
|
||||
}
|
||||
|
||||
public function testDisplaySetupShortcutButton_NoButtonWhenMySQLException()
|
||||
{
|
||||
$oWizard = $this->createMock(WizardController::class);
|
||||
$this->GivenSetupMode($oWizard, 'upgrade');
|
||||
$this->GivenGetApplicationVersion(false);
|
||||
|
||||
$oWiz = new \WizStepWelcome($oWizard, "");
|
||||
$this->assertEquals(false, $oWiz->DisplaySetupShortcutButton());
|
||||
}
|
||||
|
||||
public function testDisplaySetupShortcutButton_ButtonDisplayed()
|
||||
{
|
||||
|
||||
$oWizard = $this->createMock(WizardController::class);
|
||||
$this->GivenSetupMode($oWizard, 'upgrade');
|
||||
|
||||
$aApplicationVersion = [
|
||||
'product_version' => ITOP_VERSION_FULL,
|
||||
'product_name' => ITOP_APPLICATION,
|
||||
];
|
||||
$this->GivenGetApplicationVersion($aApplicationVersion);
|
||||
|
||||
$oWiz = new \WizStepWelcome($oWizard, "");
|
||||
$this->assertEquals(true, $oWiz->DisplaySetupShortcutButton());
|
||||
}
|
||||
|
||||
private function GivenSetupMode(WizardController $oWizardMock, $sMode = 'install'): void
|
||||
{
|
||||
$oWizardMock->expects($this->once())
|
||||
->method('GetParameter')
|
||||
->with('mode')
|
||||
->willReturn($sMode);
|
||||
}
|
||||
|
||||
private function GivenGetApplicationVersion($sExpectedReturnedValue): void
|
||||
{
|
||||
$oModuleInstallationRepository = $this->createMock(ModuleInstallationRepository::class);
|
||||
ModuleInstallationRepository::SetInstance($oModuleInstallationRepository);
|
||||
|
||||
$oModuleInstallationRepository->expects($this->once())
|
||||
->method('GetApplicationVersion')
|
||||
->willReturn($sExpectedReturnedValue);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user