N°2555 action_rule : fix add_to_list regression

Loop was removed in 5c483efd but we need it !
Sample rule that needs such a loop :
				<action_rule id="N2555_multiple_results_addtolist" _delta="define">
					<source_oql>SELECT Person WHERE id > 0</source_oql>
					<presets>
						<preset id="1">add_to_list(id, contacts_list)</preset>
					</presets>
				</action_rule>
This commit is contained in:
Pierre Goiffon
2019-11-07 14:26:45 +01:00
parent 2ee3d27ba8
commit fd77554cb7

View File

@@ -24,9 +24,9 @@ namespace Combodo\iTop\Portal\Helper;
use BinaryExpression;
use Combodo\iTop\Portal\Brick\BrickCollection;
use CoreOqlMultipleResultsForbiddenException;
use CorePortalInvalidActionRuleException;
use DBObject;
use DBObjectSet;
use DBSearch;
use DOMFormatException;
use DOMNodeList;
@@ -400,30 +400,19 @@ class ContextManipulatorHelper
}
// Retrieving source object(s) and applying rules
try
$oSet = new DBObjectSet($oSearch, array(), $aSearchParams);
while ($oSourceObject = $oSet->Fetch()) // we need a loop for certain preset verbs like add_to_list, see N°2555
{
$oSourceObject = $oSearch->GetFirstResult(true, array(), $aSearchParams);
}
catch (CoreOqlMultipleResultsForbiddenException $e)
{
// N°2555 : disallow searches returning more than 1 result
$sErrMsg = "Portal query was stopped: action_rule '$sRuleId' gives more than 1 '$sSearchClass' result";
IssueLog::Error($sErrMsg);
throw new CorePortalInvalidActionRuleException($sErrMsg);
}
if ($oSourceObject === null)
{
return;
}
// Presets
if (isset($aRule['preset']) && !empty($aRule['preset']))
{
$oDestinationObject->ExecActions($aRule['preset'], array('source' => $oSourceObject));
}
// Retrofits
if (isset($aRule['retrofit']) && !empty($aRule['retrofit']))
{
$oSourceObject->ExecActions($aRule['retrofit'], array('source' => $oDestinationObject));
// Presets
if (isset($aRule['preset']) && !empty($aRule['preset']))
{
$oDestinationObject->ExecActions($aRule['preset'], array('source' => $oSourceObject));
}
// Retrofits
if (isset($aRule['retrofit']) && !empty($aRule['retrofit']))
{
$oSourceObject->ExecActions($aRule['retrofit'], array('source' => $oDestinationObject));
}
}
}
else