mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-23 02:28:44 +02:00
N°2982 - fix delta xml variables not used in themes
This commit is contained in:
@@ -53,6 +53,8 @@ class MFCompiler
|
||||
{
|
||||
const DATA_PRECOMPILED_FOLDER = 'data' . DIRECTORY_SEPARATOR . 'precompiled_styles' . DIRECTORY_SEPARATOR;
|
||||
|
||||
private static $oThemeHandlerService;
|
||||
|
||||
/** @var \ModelFactory */
|
||||
protected $oFactory;
|
||||
|
||||
@@ -2792,11 +2794,10 @@ EOF;
|
||||
/**
|
||||
* @param \MFElement $oBrandingNode
|
||||
* @param string $sTempTargetDir
|
||||
* @param string $sFinalTargetDir
|
||||
*
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected function CompileThemes($oBrandingNode, $sTempTargetDir, $sFinalTargetDir)
|
||||
protected function CompileThemes($oBrandingNode, $sTempTargetDir)
|
||||
{
|
||||
// Make sure temp. target dir. ends with a '/'
|
||||
$sTempTargetDir .= '/';
|
||||
@@ -2830,7 +2831,6 @@ EOF;
|
||||
'imports_variable' => array(),
|
||||
'imports_utility' => array(),
|
||||
'stylesheets' => array(),
|
||||
'precompiled_stylesheet' => '',
|
||||
);
|
||||
|
||||
/** @var \DOMNodeList $oVariables */
|
||||
@@ -2846,11 +2846,11 @@ EOF;
|
||||
foreach($oImports as $oImport)
|
||||
{
|
||||
$sImportId = $oImport->getAttribute('id');
|
||||
if($oImport->getAttribute('xsi:type') === 'variable')
|
||||
if($oImport->getAttribute('xsi:type') === 'variables')
|
||||
{
|
||||
$aThemeParameters['imports_variable'][$sImportId] = $oImport->GetText();
|
||||
}
|
||||
else if($oImport->getAttribute('xsi:type') === 'utility')
|
||||
else
|
||||
{
|
||||
$aThemeParameters['imports_utility'][$sImportId] = $oImport->GetText();
|
||||
}
|
||||
@@ -2863,8 +2863,11 @@ EOF;
|
||||
$sStylesheetId = $oStylesheet->getAttribute('id');
|
||||
$aThemeParameters['stylesheets'][$sStylesheetId] = $oStylesheet->GetText();
|
||||
}
|
||||
$aThemeParameters['precompiled_stylesheet'] = $oTheme->GetChildText('precompiled_stylesheet', '');
|
||||
$aThemes[$sThemeId] = $aThemeParameters;
|
||||
|
||||
$aThemes[$sThemeId] = [
|
||||
'theme_parameters' => $aThemeParameters,
|
||||
'precompiled_stylesheet' => $oTheme->GetChildText('precompiled_stylesheet', '')
|
||||
];
|
||||
}
|
||||
|
||||
// Force to have a default theme if none in the DM
|
||||
@@ -2881,8 +2884,11 @@ EOF;
|
||||
|
||||
// Compile themes
|
||||
$fStart = microtime(true);
|
||||
foreach($aThemes as $sThemeId => $aThemeParameters)
|
||||
foreach($aThemes as $sThemeId => $aThemeInfos)
|
||||
{
|
||||
$aThemeParameters = $aThemeInfos['theme_parameters'];
|
||||
$sPrecompiledStylesheet = $aThemeInfos['precompiled_stylesheet'];
|
||||
|
||||
$sThemeDir = $sThemesDir.$sThemeId;
|
||||
if(!is_dir($sThemeDir))
|
||||
{
|
||||
@@ -2892,16 +2898,19 @@ EOF;
|
||||
// Check if a precompiled version of the theme is supplied
|
||||
$sPostCompilationLatestPrecompiledFile = $sPostCompilationPrecompiledThemeFolder . $sThemeId . ".css";
|
||||
|
||||
$sPrecompiledFileToUse = $this->UseLatestPrecompiledFile($sTempTargetDir, $aThemeParameters['precompiled_stylesheet'], $sPostCompilationLatestPrecompiledFile, $sThemeId);
|
||||
$sPrecompiledFileToUse = $this->UseLatestPrecompiledFile($sTempTargetDir, $sPrecompiledStylesheet, $sPostCompilationLatestPrecompiledFile, $sThemeId);
|
||||
if ($sPrecompiledFileToUse != null){
|
||||
copy($sPrecompiledFileToUse, $sThemeDir.'/main.css');
|
||||
// Make sure that the copy of the precompiled file is older than any other files to force a validation of the signature
|
||||
touch($sThemeDir.'/main.css', 1577836800 /* 2020-01-01 00:00:00 */);
|
||||
}
|
||||
|
||||
$bHasCompiled = ThemeHandler::CompileTheme($sThemeId, true, $this->sCompilationTimeStamp, $aThemeParameters, $aImportsPaths, $sTempTargetDir);
|
||||
if ($bHasCompiled)
|
||||
{
|
||||
if (!static::$oThemeHandlerService) {
|
||||
static::$oThemeHandlerService = new ThemeHandlerService();
|
||||
}
|
||||
$bHasCompiled = static::$oThemeHandlerService->CompileTheme($sThemeId, true, $this->sCompilationTimeStamp, $aThemeParameters, $aImportsPaths, $sTempTargetDir);
|
||||
|
||||
if ($bHasCompiled) {
|
||||
SetupLog::Info("Replacing theme '$sThemeId' precompiled file in file $sPostCompilationLatestPrecompiledFile for next setup.");
|
||||
copy($sThemeDir.'/main.css', $sPostCompilationLatestPrecompiledFile);
|
||||
}else {
|
||||
@@ -2911,6 +2920,10 @@ EOF;
|
||||
$this->Log(sprintf('Themes compilation took: %.3f ms for %d themes.', (microtime(true) - $fStart)*1000.0, count($aThemes)));
|
||||
}
|
||||
|
||||
public static function setThemeHandlerService(ThemeHandlerService $oThemeHandlerService): void {
|
||||
self::$oThemeHandlerService = $oThemeHandlerService;
|
||||
}
|
||||
|
||||
/**
|
||||
* Choose between precompiled files declared in datamodel XMLs or latest precompiled files generated after latest setup.
|
||||
*
|
||||
@@ -3003,7 +3016,7 @@ EOF;
|
||||
}
|
||||
|
||||
// Compile themes
|
||||
$this->CompileThemes($oBrandingNode, $sTempTargetDir, $sFinalTargetDir);
|
||||
$this->CompileThemes($oBrandingNode, $sTempTargetDir);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user