mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-19 07:12:26 +02:00
- enhancement: trap exceptions to keep a nice display in case of error
SVN:code[84]
This commit is contained in:
@@ -19,38 +19,51 @@ $oP = new iTopWebPage("iTop - Expression Evaluation", $currentOrganization);
|
|||||||
$sExpression = utils::ReadParam('expression', '');
|
$sExpression = utils::ReadParam('expression', '');
|
||||||
$sEncoding = utils::ReadParam('encoding', 'oql');
|
$sEncoding = utils::ReadParam('encoding', 'oql');
|
||||||
|
|
||||||
if ($sEncoding == 'crypted')
|
try
|
||||||
{
|
{
|
||||||
// Translate $sExpression into a oql expression
|
if ($sEncoding == 'crypted')
|
||||||
$sClearText = base64_decode($sExpression);
|
|
||||||
echo "<strong>FYI: '$sClearText'</strong><br/>\n";
|
|
||||||
$oFilter = DBObjectSearch::unserialize($sExpression);
|
|
||||||
$sExpression = $oFilter->ToOQL();
|
|
||||||
exit;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// leave $sExpression as is
|
|
||||||
}
|
|
||||||
|
|
||||||
$oP->add('<form method="get">'."\n");
|
|
||||||
$oP->add('Expression to evaluate:<br/>'."\n");
|
|
||||||
$oP->add('<textarea cols="50" rows="20" name="expression">'.$sExpression.'</textarea>'."<p> Example:<br/>SELECT bizPerson AS B WHERE B.name LIKE '%A%'</p>\n");
|
|
||||||
$oP->add('<input type="submit" value=" Evaluate ">'."\n");
|
|
||||||
$oP->add('</form>'."\n");
|
|
||||||
|
|
||||||
if (!empty($sExpression))
|
|
||||||
{
|
|
||||||
$oFilter = DBObjectSearch::FromOQL($sExpression);
|
|
||||||
if ($oFilter)
|
|
||||||
{
|
{
|
||||||
$oP->p('Query expression: '.$oFilter->ToOQL());
|
// Translate $sExpression into a oql expression
|
||||||
$oP->p('Serialized filter: '.$oFilter->serialize());
|
$sClearText = base64_decode($sExpression);
|
||||||
|
echo "<strong>FYI: '$sClearText'</strong><br/>\n";
|
||||||
$oSet = new CMDBObjectSet($oFilter);
|
$oFilter = DBObjectSearch::unserialize($sExpression);
|
||||||
$oP->p('The query returned '.$oSet->count().' results(s)');
|
$sExpression = $oFilter->ToOQL();
|
||||||
cmdbAbstractObject::DisplaySet($oP, $oSet);
|
exit;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// leave $sExpression as is
|
||||||
|
}
|
||||||
|
|
||||||
|
$oP->add('<form method="get">'."\n");
|
||||||
|
$oP->add('Expression to evaluate:<br/>'."\n");
|
||||||
|
$oP->add('<textarea cols="50" rows="20" name="expression">'.$sExpression.'</textarea>'."<p> Example:<br/>SELECT bizPerson AS B WHERE B.name LIKE '%A%'</p>\n");
|
||||||
|
$oP->add('<input type="submit" value=" Evaluate ">'."\n");
|
||||||
|
$oP->add('</form>'."\n");
|
||||||
|
|
||||||
|
if (!empty($sExpression))
|
||||||
|
{
|
||||||
|
$oFilter = DBObjectSearch::FromOQL($sExpression);
|
||||||
|
if ($oFilter)
|
||||||
|
{
|
||||||
|
$oP->p('Query expression: '.$oFilter->ToOQL());
|
||||||
|
$oP->p('Serialized filter: '.$oFilter->serialize());
|
||||||
|
|
||||||
|
$oSet = new CMDBObjectSet($oFilter);
|
||||||
|
$oP->p('The query returned '.$oSet->count().' results(s)');
|
||||||
|
cmdbAbstractObject::DisplaySet($oP, $oSet);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(CoreException $e)
|
||||||
|
{
|
||||||
|
$oP->p('<b>An error occured while running the query:</b>');
|
||||||
|
$oP->p($e->getHtmlDesc());
|
||||||
|
}
|
||||||
|
catch(Exception $e)
|
||||||
|
{
|
||||||
|
$oP->p('<b>An error occured while running the query:</b>');
|
||||||
|
$oP->p($e->getMessage());
|
||||||
}
|
}
|
||||||
|
|
||||||
$oP->output();
|
$oP->output();
|
||||||
|
|||||||
Reference in New Issue
Block a user