From d963fbd8cfc028e2131cbe4bc1311a6f2b60bdbb Mon Sep 17 00:00:00 2001 From: Molkobain Date: Tue, 21 Jan 2020 12:20:33 +0100 Subject: [PATCH] =?UTF-8?q?N=C2=B02314=20-=20Markup=20extensibility:=20Fix?= =?UTF-8?q?=20crash=20when=20no=20=20defined=20in=20datamodel?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- application/themehandler.class.inc.php | 40 +++++++------- setup/compiler.class.inc.php | 75 +++++++++++++++++++------- 2 files changed, 79 insertions(+), 36 deletions(-) diff --git a/application/themehandler.class.inc.php b/application/themehandler.class.inc.php index 375d86ef9..46d48ce6d 100644 --- a/application/themehandler.class.inc.php +++ b/application/themehandler.class.inc.php @@ -1,22 +1,20 @@ Get('backoffice_default_theme'); $sEnvPath = APPROOT.'env-' . utils::GetCurrentEnvironment() .'/'; $sThemePath = $sEnvPath.'/branding/themes/'.$sThemeId.'/'; - $aThemeParameters = json_decode(file_get_contents($sThemePath.'theme-parameters.json'), true); + $aThemeParameters = json_decode(@file_get_contents($sThemePath.'theme-parameters.json'), true); $sThemeCssPath = $sThemePath.'main.css'; - + + // Check that theme is compiled + if($aThemeParameters === null) + { + throw new CoreException('Could not load "'.$sThemeId.'" theme parameters from file, check that it has been compiled correctly'); + } + $sTheme = ''; $iStyleLastModified = 0; clearstatcache(); diff --git a/setup/compiler.class.inc.php b/setup/compiler.class.inc.php index f8a943f54..8207fbb7a 100644 --- a/setup/compiler.class.inc.php +++ b/setup/compiler.class.inc.php @@ -1,20 +1,21 @@ +/** + * Copyright (C) 2013-2020 Combodo SARL + * + * This file is part of iTop. + * + * iTop is free software; you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * iTop is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + */ use Combodo\iTop\DesignElement; @@ -2674,16 +2675,19 @@ EOF; */ protected function CompileThemes($oBrandingNode, $sTempTargetDir, $sFinalTargetDir) { - $oThemeNodes = $oBrandingNode->GetNodes('themes/theme'); + // Build compiled themes folder $sThemesDir = $sTempTargetDir.'/branding/themes/'; if(!is_dir($sThemesDir)) { SetupUtils::builddir($sThemesDir); } + + // Parsing themes + $oThemeNodes = $oBrandingNode->GetNodes('themes/theme'); foreach($oThemeNodes as $oTheme) { $sThemeId = $oTheme->getAttribute('id'); - $sThemeDir = $sTempTargetDir.'/branding/themes/'.$sThemeId; + $sThemeDir = $sThemesDir.$sThemeId; if(!is_dir($sThemesDir.$sThemeId)) { @@ -2720,6 +2724,41 @@ EOF; } file_put_contents($sThemeDir.'/theme-parameters.json', json_encode($aThemeParameters)); } + + if($oThemeNodes->count() === 0) + { + $aDefaultThemeInfo = $this->GetDefaultThemeInformation(); + $sThemeDir = $sThemesDir.$aDefaultThemeInfo['name']; + + if(!is_dir($sThemeDir)) + { + SetupUtils::builddir($sThemeDir); + } + file_put_contents($sThemeDir.'/theme-parameters.json', json_encode($aDefaultThemeInfo['parameters'])); + } + } + + /** + * Return default theme name and parameters + * + * @return array + * @since 2.7.0 + */ + protected function GetDefaultThemeInformation() + { + return array( + 'name' => 'light-grey', + 'parameters' => array( + 'variables' => array(), + 'imports' => array( + 'css-variables' => '../css/css-variables.scss', + ), + 'stylesheets' => array( + 'jqueryui' => '../css/ui-lightness/jqueryui.scss', + 'main' => '../css/light-grey.scss', + ), + ), + ); } /**