N°1823 - Fix tags not saved in case of error

This commit is contained in:
Eric
2019-02-19 10:16:45 +01:00
parent 5067c867b8
commit 7cf7e55454
3 changed files with 113 additions and 3 deletions

View File

@@ -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)

View File

@@ -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;

View File

@@ -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;
}
}