mirror of
https://github.com/Combodo/iTop.git
synced 2026-02-13 07:24:13 +01:00
PR#39 Fix support of expressions (friendlyname) in different language contexts
This commit is contained in:
@@ -1595,7 +1595,7 @@ class DBObjectSearch extends DBSearch
|
||||
}
|
||||
$aContextData['sModifierProperties'] = $sModifierProperties;
|
||||
|
||||
$sRawId = $sOqlQuery.$sModifierProperties;
|
||||
$sRawId = Dict::GetUserLanguage().'-'.$sOqlQuery.$sModifierProperties;
|
||||
if (!is_null($aAttToLoad))
|
||||
{
|
||||
$sRawId .= json_encode($aAttToLoad);
|
||||
|
||||
@@ -19,7 +19,6 @@
|
||||
|
||||
class ExpressionCache
|
||||
{
|
||||
static private $aCache = array();
|
||||
|
||||
static public function GetCachedExpression($sClass, $sAttCode)
|
||||
{
|
||||
@@ -28,20 +27,12 @@ class ExpressionCache
|
||||
|
||||
$oExpr = null;
|
||||
$sKey = static::GetKey($sClass, $sAttCode);
|
||||
if (array_key_exists($sKey, static::$aCache))
|
||||
if (class_exists('ExpressionCacheData'))
|
||||
{
|
||||
$oExpr = static::$aCache[$sKey];
|
||||
}
|
||||
else
|
||||
{
|
||||
if (class_exists('ExpressionCacheData'))
|
||||
if (array_key_exists($sKey, ExpressionCacheData::$aCache))
|
||||
{
|
||||
if (array_key_exists($sKey, ExpressionCacheData::$aCache))
|
||||
{
|
||||
$sVal = ExpressionCacheData::$aCache[$sKey];
|
||||
$oExpr = unserialize($sVal);
|
||||
static::$aCache[$sKey] = $oExpr;
|
||||
}
|
||||
$sVal = ExpressionCacheData::$aCache[$sKey];
|
||||
$oExpr = unserialize($sVal);
|
||||
}
|
||||
}
|
||||
return $oExpr;
|
||||
@@ -50,36 +41,45 @@ class ExpressionCache
|
||||
|
||||
static public function Warmup()
|
||||
{
|
||||
$sFilePath = static::GetCacheFileName();
|
||||
|
||||
if (!is_file($sFilePath))
|
||||
// Store current language
|
||||
$sUserLang = Dict::GetUserLanguage();
|
||||
$aLanguages = Dict::GetLanguages();
|
||||
foreach($aLanguages as $sLang => $aLang)
|
||||
{
|
||||
$content = <<<EOF
|
||||
Dict::SetUserLanguage($sLang);
|
||||
$sFilePath = static::GetCacheFileName();
|
||||
|
||||
if (!is_file($sFilePath))
|
||||
{
|
||||
$content = <<<EOF
|
||||
<?php
|
||||
// Copyright (c) 2010-2017 Combodo SARL
|
||||
// Generated Expression Cache file
|
||||
// Copyright (c) 2010-2019 Combodo SARL
|
||||
// Generated Expression Cache file for $sLang
|
||||
|
||||
class ExpressionCacheData
|
||||
{
|
||||
static \$aCache = array(
|
||||
EOF;
|
||||
|
||||
foreach(MetaModel::GetClasses() as $sClass)
|
||||
{
|
||||
$content .= static::GetSerializedExpression($sClass, 'friendlyname');
|
||||
if (MetaModel::IsObsoletable($sClass))
|
||||
foreach (MetaModel::GetClasses() as $sClass)
|
||||
{
|
||||
$content .= static::GetSerializedExpression($sClass, 'obsolescence_flag');
|
||||
$content .= static::GetSerializedExpression($sClass, 'friendlyname');
|
||||
if (MetaModel::IsObsoletable($sClass))
|
||||
{
|
||||
$content .= static::GetSerializedExpression($sClass, 'obsolescence_flag');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$content .= <<<EOF
|
||||
$content .= <<<EOF
|
||||
);
|
||||
}
|
||||
EOF;
|
||||
|
||||
file_put_contents($sFilePath, $content);
|
||||
file_put_contents($sFilePath, $content);
|
||||
}
|
||||
}
|
||||
// Restore original user language
|
||||
Dict::SetUserLanguage($sUserLang);
|
||||
}
|
||||
|
||||
static private function GetSerializedExpression($sClass, $sAttCode)
|
||||
@@ -101,9 +101,10 @@ EOF;
|
||||
|
||||
public static function GetCacheFileName()
|
||||
{
|
||||
return utils::GetCachePath().'expressioncache.php';
|
||||
$sLang = Dict::GetUserLanguage();
|
||||
$sLang = str_replace(" ", "", $sLang);
|
||||
return utils::GetCachePath().'expressioncache-' . $sLang . '.php';
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user