Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion application/cmdbabstract.class.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -3240,7 +3240,13 @@ public function DisplayStimulusForm(WebPage $oPage, $sStimulus, $aPrefillFormPar
$aAllowedValues = MetaModel::GetAllowedValues_att($sClass, $sAttCode, $aArgs);
if (is_array($aAllowedValues) && count($aAllowedValues) == 1) {
$aValues = array_keys($aAllowedValues);
$this->Set($sAttCode, $aValues[0]);
if ($oAttDef->IsLinkSet()) {
$oObjectSet = $this->Get($sAttCode);
$oObjectSet->AddItem(MetaModel::GetObject($oAttDef->GetLinkedClass(), $aValues[0]));

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there any way $aValues contains more than one single value?

can you add a test that cover DisplayStimulusForm with this new fixed usecase (linkset), pls.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if GetObject throws an exception when object does not exist? if it could happen, it could be nice for support team to catch the exception, log it and return false (i guess?).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the attribute is a LinkSet, GetAllowedValues_att returns an ObjectSet from an OQL query. Therefore, I believe this object must exist.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And to answer the first question, it is impossible for $Values ​​to contain more than one value, because the test count($allowedValues) == 1 was performed just before.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok technically it is not possible. you are right (count==1).

so functionally this PR fixes stimulus form display of current object, by adding first found allowed value to the linkset, right? no all possible allowed values. one is enough...
if there is one value to add, cant it be default one if it exists? maybe it does not make sense?

$this->Set($sAttCode, $oObjectSet);
Comment on lines +3243 to +3246

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 Indirect linksets misload objects

For an AttributeLinkedSetIndirect, GetAllowedValues_att() returns ids from the remote target class, because AttributeLinkedSet::GetValuesDef() uses LinkSetModel::GetTargetClass(). This branch then loads that id from $oAttDef->GetLinkedClass(), which is the link/intermediate class. When a lifecycle transition has exactly one allowed remote object, the form can throw because no link row has that id, or it can add an unrelated existing link row with the same numeric id. The indirect case needs to create a link object and set its remote external key instead of loading the link class by the remote id.

} else {
$this->Set($sAttCode, $aValues[0]);
}
}
}
}
Expand Down