Commit ec67a1c5d43548a6ceadac2046c92e4252c11eba

Authored by Benjamin Renard
1 parent 9cce1f21

Store template args in parsed expression saved in cache

src/InputOutput/IHMImpl/Tools/IHMParamManagerClass.php
... ... @@ -304,12 +304,7 @@ class IHMParamManagerClass
304 304 if (!$expressionInfo['success']) {
305 305 throw new Exception($expressionInfo['message']);
306 306 }
307   -
308   - $paramsList = array();
309   - foreach ($expressionInfo['params'] as $p) {
310   - $paramsList[] = $p["paramid"];
311   - }
312   - $this->userParameterMgr->saveDerivedParameterParsedExpression($res["param"]["id"], $expressionInfo["expression"], md5($res["param"]["expression"]), $paramsList);
  307 + $this->userParameterMgr->saveDerivedParameterParsedExpression($res["param"]["id"], $expressionInfo["expression"], md5($res["param"]["expression"]), $expressionInfo['params']);
313 308 }
314 309  
315 310 $paramId = $param;
... ...
src/InputOutput/IHMImpl/Tools/IHMUserParamManagerClass.php
... ... @@ -23,7 +23,10 @@ class IHMUserParamManagerClass
23 23 private static $infoDerivedParsedExpNode = 'parsedExp';
24 24 private static $infoDerivedParsedExpValAtt = 'exp';
25 25 private static $infoDerivedParsedExpHashAtt = 'hash';
26   - private static $infoDerivedParsedExpParamsAtt = 'params';
  26 + private static $infoDerivedParsedExpParamNode = 'param';
  27 + private static $infoDerivedParsedExpParamIdAtt = "paramid";
  28 + private static $infoDerivedParsedExpParamArgNode = 'arg';
  29 + private static $infoDerivedParsedExpParamArgNameAtt = 'name';
27 30 private static $infoDerivedSamplingModeNode = 'sampling_mode';
28 31 private static $infoDerivedTimeStepNode = 'timestep';
29 32 private static $infoDerivedRefParamNode = 'reference_param';
... ... @@ -330,18 +333,42 @@ class IHMUserParamManagerClass
330 333 $parsedExpNode = $parsedExpNodes->item(0);
331 334 $parsedExpVal = $parsedExpNode->getAttribute(self::$infoDerivedParsedExpValAtt);
332 335 $parsedExpHash = $parsedExpNode->getAttribute(self::$infoDerivedParsedExpHashAtt);
333   - $parsedExpParams = $parsedExpNode->getAttribute(self::$infoDerivedParsedExpParamsAtt);
334   - if (!empty($parsedExpVal) && !empty($parsedExpParams) && (md5($paramExpression) == $parsedExpHash)) {
  336 + $parsedExpParamNodes = $parsedExpNode->getElementsByTagName(self::$infoDerivedParsedExpParamNode);
  337 + if (!empty($parsedExpVal) && !empty($parsedExpParams) && !empty($parsedExpParamNodes) && (md5($paramExpression) == $parsedExpHash)) {
  338 + $error = FALSE;
335 339 $params = array();
336   - foreach (explode(',',$parsedExpParams) as $param) {
337   - $params[] = array(
338   - 'paramid' => $param,
  340 + foreach ($parsedExpParamNodes as $parsedExpParamNode) {
  341 + $parsedParamId = $parsedExpParamNode->getAttribute(self::$infoDerivedParsedExpParamIdAtt);
  342 + if (empty($parsedParamId)) {
  343 + $error = TRUE;
  344 + break;
  345 + }
  346 + $param_to_add = array(
  347 + 'paramid' => $parsedParamId,
  348 + );
  349 + $parsedExpParamArgNodes = $parsedExpParamNode->getElementsByTagName(self::$infoDerivedParsedExpParamArgNode);
  350 + if (!empty($parsedExpParamArgNodes)) {
  351 + $param_to_add['template_args'] = array();
  352 + foreach ($parsedExpParamArgNodes as $parsedExpParamArgNode) {
  353 + $attName = $parsedExpParamArgNode->getAttribute(self::$infoDerivedParsedExpParamArgNameAtt);
  354 + if (empty($attName)) {
  355 + $error = TRUE;
  356 + break;
  357 + }
  358 + $param_to_add['template_args'][$attName] = $parsedExpParamArgNode->nodeValue;
  359 + }
  360 + if ($error) {
  361 + break;
  362 + }
  363 + }
  364 + $params[] = $param_to_add;
  365 + }
  366 + if (!$error) {
  367 + $result['parsedExpression'] = array(
  368 + "expression" => $parsedExpVal,
  369 + "params" => $params,
339 370 );
340 371 }
341   - $result['parsedExpression'] = array(
342   - "expression" => $parsedExpVal,
343   - "params" => $params,
344   - );
345 372 }
346 373 }
347 374  
... ... @@ -462,11 +489,28 @@ class IHMUserParamManagerClass
462 489 }
463 490 else {
464 491 $parsedExpNode = $parsedExpNodes->item(0);
  492 + while ($parsedExpNode->hasChildNodes()) {
  493 + $parsedExpNode->removeChild($parsedExpNode->firstChild);
  494 + }
465 495 }
466 496  
  497 +
467 498 $parsedExpNode->setAttribute(self::$infoDerivedParsedExpValAtt, $expression);
468 499 $parsedExpNode->setAttribute(self::$infoDerivedParsedExpHashAtt, $hash);
469   - $parsedExpNode->setAttribute(self::$infoDerivedParsedExpParamsAtt, implode(',',$params));
  500 +
  501 + foreach ($params as $param) {
  502 + $paramNode = $dom->createElement(self::$infoDerivedParsedExpParamNode);
  503 + $paramNode->setAttribute(self::$infoDerivedParsedExpParamIdAtt, $param['paramid']);
  504 + $parsedExpNode->appendChild($paramNode);
  505 + if (!empty($param['template_args'])) {
  506 + foreach ($param['template_args'] as $arg_name => $arg_value) {
  507 + $argNode = $dom->createElement(self::$infoDerivedParsedExpParamArgNode);
  508 + $argNode->setAttribute(self::$infoDerivedParsedExpParamArgNameAtt, $arg_name);
  509 + $argNode->nodeValue = $arg_value;
  510 + $paramNode->appendChild($argNode);
  511 + }
  512 + }
  513 + }
470 514  
471 515 $dom->save($path);
472 516  
... ...