mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-20 17:18:51 +02:00
N°1823 - Fix tags not saved in case of error
This commit is contained in:
@@ -4221,6 +4221,7 @@ EOF
|
||||
$oDummyObj->Set($sAttCode, $currValue);
|
||||
/** @var ormTagSet $oTagSet */
|
||||
$oTagSet = $oDummyObj->Get($sAttCode);
|
||||
$oTagSet->SetDisplayPartial(true);
|
||||
foreach($aKeys as $iIndex => $sValues)
|
||||
{
|
||||
if ($iIndex == 0)
|
||||
|
||||
@@ -9655,14 +9655,27 @@ class AttributeTagSet extends AttributeSet
|
||||
{
|
||||
$aJson['partial_values'] = array();
|
||||
$aJson['orig_value'] = array();
|
||||
$aJson['added'] = array();
|
||||
$aJson['removed'] = array();
|
||||
}
|
||||
else
|
||||
{
|
||||
$aJson['partial_values'] = $oValue->GetModified();
|
||||
$aJson['orig_value'] = array_merge($oValue->GetValues(), $oValue->GetModified());
|
||||
$aJson['added'] = $oValue->GetAdded();
|
||||
$aJson['removed'] = $oValue->GetRemoved();
|
||||
|
||||
if ($oValue->DisplayPartial())
|
||||
{
|
||||
// For bulk updates
|
||||
$aJson['partial_values'] = $oValue->GetModified();
|
||||
}
|
||||
else
|
||||
{
|
||||
// For simple updates
|
||||
$aJson['partial_values'] = array();
|
||||
}
|
||||
}
|
||||
$aJson['added'] = array();
|
||||
$aJson['removed'] = array();
|
||||
|
||||
|
||||
$iMaxTags = $this->GetMaxItems();
|
||||
$aJson['max_items_allowed'] = $iMaxTags;
|
||||
|
||||
@@ -26,6 +26,9 @@
|
||||
*/
|
||||
final class ormTagSet extends ormSet
|
||||
{
|
||||
private $m_bDisplayPartial = false;
|
||||
|
||||
|
||||
/**
|
||||
* ormTagSet constructor.
|
||||
*
|
||||
@@ -299,6 +302,82 @@ final class ormTagSet extends ormSet
|
||||
return $aModifiedTagCodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[] list of codes for added entries
|
||||
*/
|
||||
public function GetAdded()
|
||||
{
|
||||
$aAddedTagCodes = array_keys($this->aAdded);
|
||||
sort($aAddedTagCodes);
|
||||
|
||||
return $aAddedTagCodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[] list of codes for removed entries
|
||||
*/
|
||||
public function GetRemoved()
|
||||
{
|
||||
$aRemovedTagCodes = array_keys($this->aRemoved);
|
||||
sort($aRemovedTagCodes);
|
||||
|
||||
return $aRemovedTagCodes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply a delta to the current ItemSet
|
||||
* $aDelta['added] = array of added items
|
||||
* $aDelta['removed'] = array of removed items
|
||||
*
|
||||
* @param $aDelta
|
||||
*
|
||||
* @throws \CoreException
|
||||
*/
|
||||
public function ApplyDelta($aDelta)
|
||||
{
|
||||
if (isset($aDelta['removed']))
|
||||
{
|
||||
foreach($aDelta['removed'] as $oItem)
|
||||
{
|
||||
$this->Remove($oItem);
|
||||
}
|
||||
}
|
||||
if (isset($aDelta['added']))
|
||||
{
|
||||
foreach($aDelta['added'] as $oItem)
|
||||
{
|
||||
$this->Add($oItem);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Populates the added and removed arrays for bulk edit
|
||||
*
|
||||
* @param string[] $aItems
|
||||
*
|
||||
* @throws \CoreException
|
||||
*/
|
||||
public function GenerateDiffFromArray($aItems)
|
||||
{
|
||||
foreach($this->GetValues() as $oCurrentItem)
|
||||
{
|
||||
if (!in_array($oCurrentItem, $aItems))
|
||||
{
|
||||
$this->Remove($oCurrentItem);
|
||||
}
|
||||
}
|
||||
|
||||
foreach($aItems as $oNewItem)
|
||||
{
|
||||
$this->Add($oNewItem);
|
||||
}
|
||||
|
||||
// Keep only the aModified list
|
||||
$this->aRemoved = array();
|
||||
$this->aAdded = array();
|
||||
}
|
||||
|
||||
/**
|
||||
* Check whether a tag code is valid or not for this TagSet
|
||||
*
|
||||
@@ -479,4 +558,21 @@ final class ormTagSet extends ormSet
|
||||
return TagSetFieldData::GetTagDataClassName($this->sClass, $this->sAttCode);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function DisplayPartial()
|
||||
{
|
||||
return $this->m_bDisplayPartial;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param bool $m_bDisplayPartial
|
||||
*/
|
||||
public function SetDisplayPartial($m_bDisplayPartial)
|
||||
{
|
||||
$this->m_bDisplayPartial = $m_bDisplayPartial;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user