Skip to content

Commit

Permalink
Merge branch 'hotfix_#1005_delete_empty_items' into hotfix/2.0.0-alpha16
Browse files Browse the repository at this point in the history
* hotfix_#1005_delete_empty_items:
  Hotfix #1005 delete empty items

# Conflicts:
#	src/MetaModels/Attribute/TranslatedReference.php
  • Loading branch information
baumannsven committed Aug 24, 2017
2 parents 8553915 + 56e3623 commit 76e6216
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions src/MetaModels/Attribute/TranslatedReference.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,19 +322,30 @@ public function setTranslatedDataFor($arrValues, $strLangCode)
$arrExisting = array_keys($this->getTranslatedDataFor($arrIds, $strLangCode));
$arrNewIds = array_diff($arrIds, $arrExisting);

// Update existing values.
$strQuery = 'UPDATE ' . $this->getValueTable() . ' %s';
// Update existing values - delete if empty.
$strQueryUpdate = 'UPDATE ' . $this->getValueTable() . ' %s';
$strQueryDelete = 'DELETE FROM ' . $this->getValueTable();

foreach ($arrExisting as $intId) {
$arrWhere = $this->getWhere($intId, $strLangCode);
$objDB->prepare($strQuery . ($arrWhere ? ' WHERE ' . $arrWhere['procedure'] : ''))
->set($this->getSetValues($arrValues[$intId], $intId, $strLangCode))
->execute(($arrWhere ? $arrWhere['params'] : null));

if ($arrValues[$intId]['value'] != '') {
$objDB->prepare($strQueryUpdate . ($arrWhere ? ' WHERE ' . $arrWhere['procedure'] : ''))
->set($this->getSetValues($arrValues[$intId], $intId, $strLangCode))
->execute(($arrWhere ? $arrWhere['params'] : null));
} else {
$objDB->prepare($strQueryDelete . ($arrWhere ? ' WHERE ' . $arrWhere['procedure'] : ''))
->execute(($arrWhere ? $arrWhere['params'] : null));
}
}

// Insert the new values.
$strQuery = 'INSERT INTO ' . $this->getValueTable() . ' %s';
$strQueryInsert = 'INSERT INTO ' . $this->getValueTable() . ' %s';
foreach ($arrNewIds as $intId) {
$objDB->prepare($strQuery)
if ($arrValues[$intId]['value'] == '') {
continue;
}
$objDB->prepare($strQueryInsert)
->set($this->getSetValues($arrValues[$intId], $intId, $strLangCode))
->execute();
}
Expand Down

0 comments on commit 76e6216

Please sign in to comment.