mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
N°2982 - add theme_precompilation_enabled to be able to deactivate precompilation from conf + update provided precompiled files when IsDevelopmentEnvironment
This commit is contained in:
@@ -1399,6 +1399,14 @@ class Config
|
||||
'source_of_value' => '',
|
||||
'show_in_conf_sample' => true,
|
||||
],
|
||||
'theme_precompilation_enabled' => [
|
||||
'type' => 'bool',
|
||||
'description' => 'If false, theme compilation will not use any precompiled file setup optimization.)',
|
||||
'default' => true,
|
||||
'value' => true,
|
||||
'source_of_value' => '',
|
||||
'show_in_conf_sample' => false,
|
||||
],
|
||||
];
|
||||
|
||||
public function IsProperty($sPropCode)
|
||||
|
||||
@@ -2911,9 +2911,31 @@ EOF;
|
||||
$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 {
|
||||
if (utils::GetConfig()->Get('theme_precompilation_enabled')){
|
||||
if (utils::IsDevelopmentEnvironment() && ! empty(trim($sPrecompiledStylesheet)))
|
||||
{ //help developers to detect & push theme precompilation changes
|
||||
$sInitialPrecompiledFilePath = null;
|
||||
$aRootDirs = $this->oFactory->getRootDirs();
|
||||
if (is_array($aRootDirs) && count($aRootDirs) !== 0) {
|
||||
foreach ($this->oFactory->getRootDirs() as $sRootDir) {
|
||||
$sCurrentFile = $sRootDir. DIRECTORY_SEPARATOR . $sPrecompiledStylesheet;
|
||||
if (is_file($sCurrentFile) && is_writable($sCurrentFile)) {
|
||||
$sInitialPrecompiledFilePath = $sCurrentFile;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if ($sInitialPrecompiledFilePath != null){
|
||||
SetupLog::Info("Replacing theme '$sThemeId' precompiled file in file $sInitialPrecompiledFilePath for next setup.");
|
||||
copy($sThemeDir.'/main.css', $sInitialPrecompiledFilePath);
|
||||
}
|
||||
}
|
||||
|
||||
SetupLog::Info("Replacing theme '$sThemeId' precompiled file in file $sPostCompilationLatestPrecompiledFile for next setup.");
|
||||
copy($sThemeDir.'/main.css', $sPostCompilationLatestPrecompiledFile);
|
||||
}
|
||||
} else {
|
||||
SetupLog::Info("No theme '$sThemeId' compilation was required during setup.");
|
||||
}
|
||||
}
|
||||
@@ -2935,6 +2957,10 @@ EOF;
|
||||
* @return string : file path of latest precompiled file to use for setup
|
||||
*/
|
||||
public function UseLatestPrecompiledFile(string $sTempTargetDir, string $sPrecompiledFileUri, $sPostCompilationLatestPrecompiledFile, $sThemeId) : ?string {
|
||||
if (! utils::GetConfig()->Get('theme_precompilation_enabled')) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$bDataXmlPrecompiledFileExists = false;
|
||||
clearstatcache();
|
||||
if (!empty($sPrecompiledFileUri)){
|
||||
|
||||
@@ -1834,6 +1834,13 @@ EOF;
|
||||
{
|
||||
return $this->oDOMDocument->GetNodes($sXPath, $oContextNode, $bSafe);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return mixed
|
||||
*/
|
||||
public function getRootDirs() {
|
||||
return $this->aRootDirs;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -113,7 +113,10 @@ class MFCompilerTest extends ItopTestCase {
|
||||
* @param string $sThemeDir
|
||||
* @param ?string $sExpectedReturn
|
||||
*/
|
||||
public function testUseLatestPrecompiledFile(string $sTempTargetDir, string $sPrecompiledFileUri, string $sPostCompilationLatestPrecompiledFile, string $sThemeDir, ?string $sExpectedReturn){
|
||||
public function testUseLatestPrecompiledFile(string $sTempTargetDir, string $sPrecompiledFileUri, string $sPostCompilationLatestPrecompiledFile, string $sThemeDir, ?string $sExpectedReturn, bool $bDisableThemePrecompilationViaConf = false){
|
||||
if ($bDisableThemePrecompilationViaConf){
|
||||
utils::GetConfig()->Set('theme_precompilation_enabled', false);
|
||||
}
|
||||
$sRes = $this->oMFCompiler->UseLatestPrecompiledFile($sTempTargetDir, $sPrecompiledFileUri, $sPostCompilationLatestPrecompiledFile, $sThemeDir);
|
||||
$this->assertEquals($sExpectedReturn, $sRes);
|
||||
}
|
||||
@@ -122,6 +125,7 @@ class MFCompilerTest extends ItopTestCase {
|
||||
self::init();
|
||||
return [
|
||||
'no precompiled file at all' => $this->BuildProviderUseCaseArray('', self::$aRessources['sMissingFile'], null),
|
||||
'deactivate precompilation via conf' => $this->BuildProviderUseCaseArray('', self::$aRessources['sPostCompilation1'], null, true),
|
||||
'no precompiled file configured in precompiled_stylesheet XM section' => $this->BuildProviderUseCaseArray('', self::$aRessources['sPostCompilation1'], self::$aRessources['sPostCompilation1']),
|
||||
'missing precompiled file in precompiled_stylesheet section' => $this->BuildProviderUseCaseArray(self::$aRessources['sMissingFile'], self::$aRessources['sPostCompilation1'], self::$aRessources['sPostCompilation1'] ),
|
||||
'no precompiled file generated in previous setup in /data/precompiled_styles' => $this->BuildProviderUseCaseArray(self::$aRessources['sPrecompiledInExtensionFileUri1'], self::$aRessources['sMissingFile'], self::$aRessources['sCopiedExtensionFile1'] ),
|
||||
@@ -132,13 +136,14 @@ class MFCompilerTest extends ItopTestCase {
|
||||
];
|
||||
}
|
||||
|
||||
private function BuildProviderUseCaseArray(string $sPrecompiledFileUri, string $sPostCompilationLatestPrecompiledFile, $sExpectedReturn) : array{
|
||||
private function BuildProviderUseCaseArray(string $sPrecompiledFileUri, string $sPostCompilationLatestPrecompiledFile, $sExpectedReturn, $bDisableThemePrecompilationViaConf = false) : array{
|
||||
return [
|
||||
"sTempTargetDir" => sys_get_temp_dir(),
|
||||
"sPrecompiledFileUri" => $sPrecompiledFileUri,
|
||||
"sPostCompilationLatestPrecompiledFile" => $sPostCompilationLatestPrecompiledFile,
|
||||
"sThemeDir" => "test",
|
||||
"sExpectedReturn" => $sExpectedReturn
|
||||
"sExpectedReturn" => $sExpectedReturn,
|
||||
"bDisableThemePrecompilationViaConf" => $bDisableThemePrecompilationViaConf
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user