Skip to content

Commit e1e6cab

Browse files
committed
Hotfix #1005 delete empty items
1 parent f21ba95 commit e1e6cab

File tree

1 file changed

+20
-9
lines changed

1 file changed

+20
-9
lines changed

src/MetaModels/Attribute/TranslatedReference.php

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/**
44
* This file is part of MetaModels/core.
55
*
6-
* (c) 2012-2016 The MetaModels team.
6+
* (c) 2012-2017 The MetaModels team.
77
*
88
* For the full copyright and license information, please view the LICENSE
99
* file that was distributed with this source code.
@@ -16,7 +16,7 @@
1616
* @author David Maack <david.maack@arcor.de>
1717
* @author Stefan Heimes <stefan_heimes@hotmail.com>
1818
* @author Ingolf Steinhardt <info@e-spin.de>
19-
* @copyright 2012-2016 The MetaModels team.
19+
* @copyright 2012-2017 The MetaModels team.
2020
* @license https://github.com/MetaModels/core/blob/master/LICENSE LGPL-3.0
2121
* @filesource
2222
*/
@@ -321,19 +321,30 @@ public function setTranslatedDataFor($arrValues, $strLangCode)
321321
$arrExisting = array_keys($this->getTranslatedDataFor($arrIds, $strLangCode));
322322
$arrNewIds = array_diff($arrIds, $arrExisting);
323323

324-
// Update existing values.
325-
$strQuery = 'UPDATE ' . $this->getValueTable() . ' %s';
324+
// Update existing values - delete if empty.
325+
$strQueryUpdate = 'UPDATE ' . $this->getValueTable() . ' %s';
326+
$strQueryDelete = 'DELETE FROM ' . $this->getValueTable();
327+
326328
foreach ($arrExisting as $intId) {
327329
$arrWhere = $this->getWhere($intId, $strLangCode);
328-
$objDB->prepare($strQuery . ($arrWhere ? ' WHERE ' . $arrWhere['procedure'] : ''))
329-
->set($this->getSetValues($arrValues[$intId], $intId, $strLangCode))
330-
->execute(($arrWhere ? $arrWhere['params'] : null));
330+
331+
if ($arrValues[$intId]['value'] != '') {
332+
$objDB->prepare($strQueryUpdate . ($arrWhere ? ' WHERE ' . $arrWhere['procedure'] : ''))
333+
->set($this->getSetValues($arrValues[$intId], $intId, $strLangCode))
334+
->execute(($arrWhere ? $arrWhere['params'] : null));
335+
} else {
336+
$objDB->prepare($strQueryDelete . ($arrWhere ? ' WHERE ' . $arrWhere['procedure'] : ''))
337+
->execute(($arrWhere ? $arrWhere['params'] : null));
338+
}
331339
}
332340

333341
// Insert the new values.
334-
$strQuery = 'INSERT INTO ' . $this->getValueTable() . ' %s';
342+
$strQueryInsert = 'INSERT INTO ' . $this->getValueTable() . ' %s';
335343
foreach ($arrNewIds as $intId) {
336-
$objDB->prepare($strQuery)
344+
if ($arrValues[$intId]['value'] == '') {
345+
continue;
346+
}
347+
$objDB->prepare($strQueryInsert)
337348
->set($this->getSetValues($arrValues[$intId], $intId, $strLangCode))
338349
->execute();
339350
}

0 commit comments

Comments
 (0)