|
3 | 3 | /** |
4 | 4 | * This file is part of MetaModels/core. |
5 | 5 | * |
6 | | - * (c) 2012-2016 The MetaModels team. |
| 6 | + * (c) 2012-2017 The MetaModels team. |
7 | 7 | * |
8 | 8 | * For the full copyright and license information, please view the LICENSE |
9 | 9 | * file that was distributed with this source code. |
|
16 | 16 | * @author David Maack <david.maack@arcor.de> |
17 | 17 | * @author Stefan Heimes <stefan_heimes@hotmail.com> |
18 | 18 | * @author Ingolf Steinhardt <info@e-spin.de> |
19 | | - * @copyright 2012-2016 The MetaModels team. |
| 19 | + * @copyright 2012-2017 The MetaModels team. |
20 | 20 | * @license https://github.com/MetaModels/core/blob/master/LICENSE LGPL-3.0 |
21 | 21 | * @filesource |
22 | 22 | */ |
@@ -321,19 +321,30 @@ public function setTranslatedDataFor($arrValues, $strLangCode) |
321 | 321 | $arrExisting = array_keys($this->getTranslatedDataFor($arrIds, $strLangCode)); |
322 | 322 | $arrNewIds = array_diff($arrIds, $arrExisting); |
323 | 323 |
|
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 | + |
326 | 328 | foreach ($arrExisting as $intId) { |
327 | 329 | $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 | + } |
331 | 339 | } |
332 | 340 |
|
333 | 341 | // Insert the new values. |
334 | | - $strQuery = 'INSERT INTO ' . $this->getValueTable() . ' %s'; |
| 342 | + $strQueryInsert = 'INSERT INTO ' . $this->getValueTable() . ' %s'; |
335 | 343 | foreach ($arrNewIds as $intId) { |
336 | | - $objDB->prepare($strQuery) |
| 344 | + if ($arrValues[$intId]['value'] == '') { |
| 345 | + continue; |
| 346 | + } |
| 347 | + $objDB->prepare($strQueryInsert) |
337 | 348 | ->set($this->getSetValues($arrValues[$intId], $intId, $strLangCode)) |
338 | 349 | ->execute(); |
339 | 350 | } |
|
0 commit comments