Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
namespace Combodo\iTop\DataFeatureRemoval\Controller;

require_once APPROOT.'setup/feature_removal/SetupAudit.php';
require_once APPROOT.'setup/feature_removal/DryRemovalRuntimeEnvironment.php';

use Combodo\iTop\Application\Helper\Session;
use Combodo\iTop\Application\TwigBase\Controller\Controller;
Expand All @@ -20,7 +19,6 @@
use Combodo\iTop\DataFeatureRemoval\Service\DataFeatureRemoverExtensionService;
use Combodo\iTop\DataFeatureRemoval\Service\StaticDeletionPlan;
use Combodo\iTop\Service\Session\SessionParameters;
use Combodo\iTop\Setup\FeatureRemoval\DryRemovalRuntimeEnvironment;
use Combodo\iTop\Setup\FeatureRemoval\SetupAudit;
use ContextTag;
use CoreException;
Expand All @@ -39,10 +37,10 @@ class DataFeatureRemovalController extends Controller
private array $aCountClassesToCleanup = [];
private array $aAnalysisDataTable = [];
private array $aDeletionExecutionSummary = [];
private ?RuntimeEnvironment $oRuntimeEnvironment = null;

private int $iCount = 0;
private int $iColumnCount = 2;
private RunTimeEnvironment $oRuntimeEnvironment;

public function OperationMain($sErrorMessage = null): void
{
Expand Down Expand Up @@ -131,8 +129,6 @@ public function OperationAnalysisResult(): void
$aHiddenInputs['removed_extensions'] = $this->ConvertIntoSetupFormat($aRemovedExtensions);
}

$aRemoveExtensionCodes = array_keys($aRemovedExtensions);

$aParams['aAddedExtensions'] = $aAddedExtensions;
$aParams['aRemovedExtensions'] = $aRemovedExtensions;

Expand All @@ -144,9 +140,24 @@ public function OperationAnalysisResult(): void
$aParams['iColumnCount'] = $this->iColumnCount;
$aParams['aAvailableExtensions'] = $this->SplitArrayIntoColumns($this->GetExtensionsDiff($aAddedExtensions, $aRemovedExtensions), $this->iColumnCount);

$bForceCompilation = Session::Get('bForceCompilation', false);
//to make setup redirection work, we need to pass complex data structures to setup wizards (ie extension/module lists)
$sSourceEnv = MetaModel::GetEnvironment();
$this->oRuntimeEnvironment = new RunTimeEnvironment($sSourceEnv, false);

if ('[]' === $aHiddenInputs['selected_modules']) {
$oConfig = MetaModel::GetConfig();
$aSelectedExtensions = DataFeatureRemoverExtensionService::GetInstance()->GetExtensionMap()->GetSelectedExtensions($oConfig, array_keys($aAddedExtensions), array_keys($aRemovedExtensions));
$aHiddenInputs['selected_extensions'] = $this->ConvertIntoSetupFormat($aSelectedExtensions);

$aSelectedModules = []; // keep it to compile method
} else {
$aSelectedExtensions = json_decode($aHiddenInputs['selected_extensions'], true);
$aSelectedModules = json_decode($aHiddenInputs['selected_modules'], true);
}

try {
$this->Compile($aAddedExtensions, $aRemoveExtensionCodes, $bForceCompilation);
$this->Compile($aSelectedExtensions, array_keys($aRemovedExtensions), $aSelectedModules);
Comment thread
greptile-apps[bot] marked this conversation as resolved.
$aHiddenInputs['selected_modules'] = $this->ConvertIntoSetupFormat($aSelectedModules);
} catch (CoreException $e) {
$aParams['DataFeatureRemovalErrorMessage'] = $e->getHtmlDesc();
$this->DisplayPage($aParams, 'AnalysisResult');
Expand All @@ -157,19 +168,6 @@ public function OperationAnalysisResult(): void
return;
}

if ("[]" === $aHiddenInputs['selected_modules']) {
//to make setup redirection work, we need to pass complex data structures to setup wizards (ie extension/module lists)
$oConfig = MetaModel::GetConfig();
$aSelectedExtensions = DataFeatureRemoverExtensionService::GetInstance()->GetExtensionMap()->GetSelectedExtensions($oConfig, array_keys($aAddedExtensions), array_keys($aRemovedExtensions));
$aHiddenInputs['selected_extensions'] = $this->ConvertIntoSetupFormat($aSelectedExtensions);

$oRunTimeEnvironment = $this->GetRuntimeEnvironment($aAddedExtensions, $aRemovedExtensions);
$aSearchDirs = [$oRunTimeEnvironment->GetBuildDir()];
$aSelectedModules = $oRunTimeEnvironment->GetModulesToLoadFromChoices($oConfig, $aSelectedExtensions, $aSearchDirs);
$aHiddenInputs['selected_modules'] = $this->ConvertIntoSetupFormat($aSelectedModules);
}

$sSourceEnv = MetaModel::GetEnvironment();
$oSetupAudit = new SetupAudit($sSourceEnv);
$aGetRemovedClasses = array_keys($oSetupAudit->RunDataAudit());
DataFeatureRemovalLog::Debug(__METHOD__, null, ['aGetRemovedClasses' => $aGetRemovedClasses]);
Expand Down Expand Up @@ -211,42 +209,42 @@ private function ConvertIntoSetupFormat(array $aData): string
}
Comment thread
odain-cbd marked this conversation as resolved.

/**
* @param array $aAddedExtensions
* @param array $aSelectedExtensions
* @param array $aRemovedExtensions
* @param bool $bForceCompilation
* @param array $aSelectedModules
*
* @return void
* @throws \ConfigException
* @throws \CoreException
*/
private function Compile(array $aAddedExtensions, array $aRemovedExtensions, bool $bForceCompilation = true): void
private function Compile(array $aSelectedExtensions, array $aRemovedExtensions, array &$aSelectedModules): void
{
$sSourceEnv = MetaModel::GetEnvironment();
$sBuildDir = APPROOT."/env-$sSourceEnv-build";
if (! is_dir($sBuildDir)) {
SetupUtils::builddir($sBuildDir);
}
$bIsDirEmpty = count(scandir($sBuildDir)) === 2;
$bForceCompilation = Session::Get('bForceCompilation', false);

$oConfig = MetaModel::GetConfig();
if ($bIsDirEmpty || $bForceCompilation) {
Session::Unset('bForceCompilation');
$this->oRuntimeEnvironment->CopySetupFiles();
if (count($aSelectedModules) === 0) {
$aSelectedModules = $this->oRuntimeEnvironment->GetModulesToLoadFromChoices($oConfig, $aSelectedExtensions);
}
DataFeatureRemovalLog::Debug(
__METHOD__,
null,
['sSourceEnv' => $sSourceEnv, 'sBuildDir' => $sBuildDir, 'bIsDirEmpty' => $bIsDirEmpty, glob("$sBuildDir/*")]
);
$this->GetRuntimeEnvironment($aAddedExtensions, $aRemovedExtensions)->CompileFrom($sSourceEnv);
}
}

private function GetRuntimeEnvironment(array $aAddedExtensions, array $aRemovedExtensions): RunTimeEnvironment
{
if (is_null($this->oRuntimeEnvironment)) {
$sSourceEnv = MetaModel::GetEnvironment();
$this->oRuntimeEnvironment = new DryRemovalRuntimeEnvironment($sSourceEnv, $aAddedExtensions, $aRemovedExtensions);
$this->oRuntimeEnvironment->DoCompile($aSelectedExtensions, $aRemovedExtensions, $aSelectedModules, MFCompiler::CanUseSymbolicLinks());
} else {
if (count($aSelectedModules) === 0) {
$aSelectedModules = $this->oRuntimeEnvironment->GetModulesToLoadFromChoices($oConfig, $aSelectedExtensions);
}
}

return $this->oRuntimeEnvironment;
}

private function GetExecutionSummaryTable(): array
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,7 @@ public function LaunchCompile()
throw new Exception('Sorry the installation of extensions is not allowed in demo mode');
}

$aSelectModules = $oRuntimeEnv->CompileFrom('production'); // WARNING symlinks does not seem to be compatible with manual Commit

$oRuntimeEnv->CompileFrom('production'); // WARNING symlinks does not seem to be compatible with manual Commit
$oRuntimeEnv->UpdateIncludes($oConfig);

$oRuntimeEnv->InitDataModel($oConfig, true /* model only */);
Expand Down
45 changes: 45 additions & 0 deletions setup/extensionsmap.class.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -763,4 +763,49 @@ public function GetScannedModulesRootDirs(): array
{
return $this->aScannedDirs;
}

/**
* Validate extensions if an invalid extension is marked as chosen, then throw an exception
*
* @return bool true if all extensions are valid
* @throws \CoreException
*/
public function CheckExtensionsValidity(): bool
{
$bSetupFailure = false;
$aNoCodeExtensionSourceDirs = [];
$aNoCodeExtensionLabelsThatBreakSetup = [];

/** @var iTopExtension $oExtension */
foreach ($this->aExtensions as $oExtension) {
if (!$oExtension->HasCode()) {
if ($oExtension->HasLabel()) {
$sExtensionLabel = $oExtension->sLabel;
$aNoCodeExtensionSourceDirs [$sExtensionLabel] = $oExtension->sSourceDir;
} else {
$sExtensionLabel = $oExtension->sSourceDir;
$aNoCodeExtensionSourceDirs [] = $oExtension->sSourceDir;
}

if ($oExtension->IsMarkedAsChosen()) {
$aNoCodeExtensionLabelsThatBreakSetup[] = $sExtensionLabel;
$bSetupFailure = true;
}
}
}

if (count($aNoCodeExtensionSourceDirs) > 0) {
if ($bSetupFailure) {
$sErrorMessage = sprintf('Selected extension(s) cannot be installed: Missing extension code (%s)', implode(',', $aNoCodeExtensionLabelsThatBreakSetup));
$e = new CoreException($sErrorMessage);
SetupLog::Exception($sErrorMessage, $e, null, $aNoCodeExtensionSourceDirs);
throw $e;
} else {
SetupLog::Warning('Non selected extension(s) cannot be installed: Missing extension code', null, $aNoCodeExtensionSourceDirs);
return false;
}
}

return true;
}
}
80 changes: 0 additions & 80 deletions setup/feature_removal/DryRemovalRuntimeEnvironment.php

This file was deleted.

40 changes: 0 additions & 40 deletions setup/feature_removal/InplaceSetupAudit.php

This file was deleted.

10 changes: 10 additions & 0 deletions setup/itopextension.class.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,14 @@ public function MarkAsChosen(bool $bMarkedAsChosen = true): void
{
$this->bMarkedAsChosen = $bMarkedAsChosen;
}

public function HasCode(): bool
{
return $this->sCode !== '';
}

public function HasLabel(): bool
{
return $this->sLabel !== '';
}
}
Loading