N°3335 - Notifications on threshold don't work when trigger is created on iTop 2.7.1 - nicer fix

This commit is contained in:
acognet
2020-09-29 10:27:05 +02:00
parent 80b3212a19
commit 05a0d61244
5 changed files with 25 additions and 22 deletions

View File

@@ -839,12 +839,15 @@ class MatchExpression extends BinaryExpression
* MatchExpression constructor. * MatchExpression constructor.
* *
* @param \FieldExpression $oLeftExpr * @param \FieldExpression $oLeftExpr
* @param \ScalarExpression $oRightExpr * @param \Expression $oRightExpr
* *
* @throws \CoreException * @throws \CoreException
*/ */
public function __construct(FieldExpression $oLeftExpr, ScalarExpression $oRightExpr) public function __construct(FieldExpression $oLeftExpr, Expression $oRightExpr)
{ {
if (!$oRightExpr instanceof ScalarExpression && !$oRightExpr instanceof VariableExpression) {
throw new CoreException('Only instance of ScalarExpression or VariableExpression are allowed in MATCHES '.get_class( $oRightExpr).' found', $oRightExpr);
}
parent::__construct($oLeftExpr, 'MATCHES', $oRightExpr); parent::__construct($oLeftExpr, 'MATCHES', $oRightExpr);
} }

View File

@@ -1600,38 +1600,38 @@ static public $yy_action = array(
$this->_retvalue = new ListOqlExpression($this->yystack[$this->yyidx + -1]->minor); $this->_retvalue = new ListOqlExpression($this->yystack[$this->yyidx + -1]->minor);
} }
#line 1606 "..\oql-parser.php" #line 1606 "..\oql-parser.php"
#line 132 "..\oql-parser.y" #line 131 "..\oql-parser.y"
function yy_r43(){ function yy_r43(){
$this->_retvalue = new NestedQueryOqlExpression($this->yystack[$this->yyidx + -1]->minor); $this->_retvalue = new NestedQueryOqlExpression($this->yystack[$this->yyidx + -1]->minor);
} }
#line 1611 "..\oql-parser.php" #line 1611 "..\oql-parser.php"
#line 147 "..\oql-parser.y" #line 146 "..\oql-parser.y"
function yy_r47(){ function yy_r47(){
$this->_retvalue = array(); $this->_retvalue = array();
} }
#line 1616 "..\oql-parser.php" #line 1616 "..\oql-parser.php"
#line 158 "..\oql-parser.y" #line 157 "..\oql-parser.y"
function yy_r51(){ $this->_retvalue = new IntervalOqlExpression($this->yystack[$this->yyidx + -1]->minor, $this->yystack[$this->yyidx + 0]->minor); } function yy_r51(){ $this->_retvalue = new IntervalOqlExpression($this->yystack[$this->yyidx + -1]->minor, $this->yystack[$this->yyidx + 0]->minor); }
#line 1619 "..\oql-parser.php" #line 1619 "..\oql-parser.php"
#line 171 "..\oql-parser.y" #line 170 "..\oql-parser.y"
function yy_r61(){ $this->_retvalue = new ScalarOqlExpression($this->yystack[$this->yyidx + 0]->minor); } function yy_r61(){ $this->_retvalue = new ScalarOqlExpression($this->yystack[$this->yyidx + 0]->minor); }
#line 1622 "..\oql-parser.php" #line 1622 "..\oql-parser.php"
#line 173 "..\oql-parser.y" #line 172 "..\oql-parser.y"
function yy_r63(){ $this->_retvalue = new ScalarOqlExpression(null); } function yy_r63(){ $this->_retvalue = new ScalarOqlExpression(null); }
#line 1625 "..\oql-parser.php" #line 1625 "..\oql-parser.php"
#line 175 "..\oql-parser.y" #line 174 "..\oql-parser.y"
function yy_r64(){ $this->_retvalue = new FieldOqlExpression($this->yystack[$this->yyidx + 0]->minor); } function yy_r64(){ $this->_retvalue = new FieldOqlExpression($this->yystack[$this->yyidx + 0]->minor); }
#line 1628 "..\oql-parser.php" #line 1628 "..\oql-parser.php"
#line 176 "..\oql-parser.y" #line 175 "..\oql-parser.y"
function yy_r65(){ $this->_retvalue = new FieldOqlExpression($this->yystack[$this->yyidx + 0]->minor, $this->yystack[$this->yyidx + -2]->minor); } function yy_r65(){ $this->_retvalue = new FieldOqlExpression($this->yystack[$this->yyidx + 0]->minor, $this->yystack[$this->yyidx + -2]->minor); }
#line 1631 "..\oql-parser.php" #line 1631 "..\oql-parser.php"
#line 177 "..\oql-parser.y" #line 176 "..\oql-parser.y"
function yy_r66(){ $this->_retvalue=$this->yystack[$this->yyidx + 0]->minor; } function yy_r66(){ $this->_retvalue=$this->yystack[$this->yyidx + 0]->minor; }
#line 1634 "..\oql-parser.php" #line 1634 "..\oql-parser.php"
#line 180 "..\oql-parser.y" #line 179 "..\oql-parser.y"
function yy_r67(){ $this->_retvalue = new VariableOqlExpression(substr($this->yystack[$this->yyidx + 0]->minor, 1)); } function yy_r67(){ $this->_retvalue = new VariableOqlExpression(substr($this->yystack[$this->yyidx + 0]->minor, 1)); }
#line 1637 "..\oql-parser.php" #line 1637 "..\oql-parser.php"
#line 182 "..\oql-parser.y" #line 181 "..\oql-parser.y"
function yy_r68(){ function yy_r68(){
if ($this->yystack[$this->yyidx + 0]->minor[0] == '`') if ($this->yystack[$this->yyidx + 0]->minor[0] == '`')
{ {
@@ -1644,19 +1644,19 @@ static public $yy_action = array(
$this->_retvalue = new OqlName($name, $this->m_iColPrev); $this->_retvalue = new OqlName($name, $this->m_iColPrev);
} }
#line 1650 "..\oql-parser.php" #line 1650 "..\oql-parser.php"
#line 193 "..\oql-parser.y" #line 192 "..\oql-parser.y"
function yy_r69(){$this->_retvalue=(int)$this->yystack[$this->yyidx + 0]->minor; } function yy_r69(){$this->_retvalue=(int)$this->yystack[$this->yyidx + 0]->minor; }
#line 1653 "..\oql-parser.php" #line 1653 "..\oql-parser.php"
#line 194 "..\oql-parser.y" #line 193 "..\oql-parser.y"
function yy_r70(){$this->_retvalue=(int)-$this->yystack[$this->yyidx + 0]->minor; } function yy_r70(){$this->_retvalue=(int)-$this->yystack[$this->yyidx + 0]->minor; }
#line 1656 "..\oql-parser.php" #line 1656 "..\oql-parser.php"
#line 195 "..\oql-parser.y" #line 194 "..\oql-parser.y"
function yy_r71(){$this->_retvalue=new OqlHexValue($this->yystack[$this->yyidx + 0]->minor); } function yy_r71(){$this->_retvalue=new OqlHexValue($this->yystack[$this->yyidx + 0]->minor); }
#line 1659 "..\oql-parser.php" #line 1659 "..\oql-parser.php"
#line 196 "..\oql-parser.y" #line 195 "..\oql-parser.y"
function yy_r72(){$this->_retvalue=stripslashes(substr($this->yystack[$this->yyidx + 0]->minor, 1, strlen($this->yystack[$this->yyidx + 0]->minor) - 2)); } function yy_r72(){$this->_retvalue=stripslashes(substr($this->yystack[$this->yyidx + 0]->minor, 1, strlen($this->yystack[$this->yyidx + 0]->minor) - 2)); }
#line 1662 "..\oql-parser.php" #line 1662 "..\oql-parser.php"
#line 199 "..\oql-parser.y" #line 198 "..\oql-parser.y"
function yy_r73(){$this->_retvalue=$this->yystack[$this->yyidx + 0]->minor; } function yy_r73(){$this->_retvalue=$this->yystack[$this->yyidx + 0]->minor; }
#line 1665 "..\oql-parser.php" #line 1665 "..\oql-parser.php"
@@ -1940,7 +1940,7 @@ throw new OQLParserException($this->m_sSourceQuery, $this->m_iLine, $this->m_iCo
} while ($yymajor != self::YYNOCODE && $this->yyidx >= 0); } while ($yymajor != self::YYNOCODE && $this->yyidx >= 0);
} }
} }
#line 264 "..\oql-parser.y" #line 263 "..\oql-parser.y"
class OQLParserException extends OQLException class OQLParserException extends OQLException

View File

@@ -173,7 +173,7 @@ class MatchOqlExpression extends MatchExpression implements CheckableExpression
throw new OqlNormalizeException('Only "field MATCHES string" syntax is allowed', $sSourceQuery, new OqlName($this->m_oLeftExpr->RenderExpression(true), 0)); throw new OqlNormalizeException('Only "field MATCHES string" syntax is allowed', $sSourceQuery, new OqlName($this->m_oLeftExpr->RenderExpression(true), 0));
} }
// Only field MATCHES scalar is allowed // Only field MATCHES scalar is allowed
if (!$this->m_oRightExpr instanceof ScalarExpression) if (!$this->m_oRightExpr instanceof ScalarExpression && !$this->m_oRightExpr instanceof VariableOqlExpression)
{ {
throw new OqlNormalizeException('Only "field MATCHES string" syntax is allowed', $sSourceQuery, new OqlName($this->m_oRightExpr->RenderExpression(true), 0)); throw new OqlNormalizeException('Only "field MATCHES string" syntax is allowed', $sSourceQuery, new OqlName($this->m_oRightExpr->RenderExpression(true), 0));
} }

View File

@@ -1 +1 @@
2019-12-03 2020-09-29

View File

@@ -609,9 +609,9 @@ class CheckStopWatchThresholds implements iBackgroundProcess
$sClassList = implode("', '", MetaModel::EnumParentClasses($sClass, ENUM_PARENT_CLASSES_ALL)); $sClassList = implode("', '", MetaModel::EnumParentClasses($sClass, ENUM_PARENT_CLASSES_ALL));
$oTriggerSet = new DBObjectSet( $oTriggerSet = new DBObjectSet(
DBObjectSearch::FromOQL("SELECT TriggerOnThresholdReached AS t WHERE t.target_class IN ('$sClassList') AND stop_watch_code MATCHES '$sAttCode' AND threshold_index = :threshold_index"), DBObjectSearch::FromOQL("SELECT TriggerOnThresholdReached AS t WHERE t.target_class IN ('$sClassList') AND stop_watch_code MATCHES :stop_watch_code AND threshold_index = :threshold_index"),
array(), // order by array(), // order by
array('threshold_index' => $iThreshold) array('stop_watch_code' => $sAttCode, 'threshold_index' => $iThreshold)
); );
while ($oTrigger = $oTriggerSet->Fetch()) while ($oTrigger = $oTriggerSet->Fetch())
{ {