From 3c87cdb38839f755e66af8ad46b72b77cc242545 Mon Sep 17 00:00:00 2001 From: Ingmar Schlecht Date: Thu, 2 Nov 2006 16:27:18 +0000 Subject: [PATCH] Fixed bug with bidirectional mm-relations: "group" fields with more than one table allowed didn't work properly any more. git-svn-id: https://svn.typo3.org/TYPO3v4/Core/trunk@1781 709f56b5-9817-0410-a4d7-c38de5d9e867 --- ChangeLog | 4 +++ t3lib/class.t3lib_loaddbgroup.php | 45 ++++++++++++++++++++++--------- 2 files changed, 36 insertions(+), 13 deletions(-) diff --git a/ChangeLog b/ChangeLog index 11b9cf223f76..b965f75d1a81 100755 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2006-11-02 Ingmar Schlecht + + * Fixed bug with bidirectional mm-relations: "group" fields with more than one table allowed didn't work properly any more + 2006-11-02 Michael Stucki * Fixed bug #1655: t3lib_div::substUrlsInPlainText() did not support HTTPS links diff --git a/t3lib/class.t3lib_loaddbgroup.php b/t3lib/class.t3lib_loaddbgroup.php index 391d9c984e99..9f7e9aa1ebd5 100755 --- a/t3lib/class.t3lib_loaddbgroup.php +++ b/t3lib/class.t3lib_loaddbgroup.php @@ -275,7 +275,7 @@ class t3lib_loadDBGroup { $uidLocal_field = 'uid_local'; $uidForeign_field = 'uid_foreign'; $sorting_field = 'sorting'; - } // TODO: SORTING! + } // If there are tables... $tableC = count($this->tableArray); @@ -287,16 +287,21 @@ class t3lib_loadDBGroup { if ($this->MM_is_foreign && $prep) { $additionalWhere_tablenames = ' AND tablenames="'.$this->currentTable.'"'; } - $existingMMs = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows($uidForeign_field, $tableName, $uidLocal_field.'='.$uid.$additionalWhere_tablenames, '', '', '', $uidForeign_field); + $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($uidForeign_field.($prep?', tablenames':''), $tableName, $uidLocal_field.'='.$uid.$additionalWhere_tablenames); + $oldMMs = array(); + while($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) { + if (!$this->MM_is_foreign && $prep) { + $oldMMs[] = array($row['tablenames'], $row[$uidForeign_field]); + } else { + $oldMMs[] = $row[$uidForeign_field]; + } + } // For each item, insert it: - $uidList = array(); foreach($this->itemArray as $val) { $c++; - $uidList[] = $val['id']; - if ($prep || $val['table']=='_NO_TABLE') { if ($this->MM_is_foreign) { // insert current table if needed $tablename = $this->currentTable; @@ -307,10 +312,19 @@ class t3lib_loadDBGroup { $tablename = ''; } - if (isset($existingMMs[$val['id']])) { + if(!$this->MM_is_foreign && $prep) { + $item = array($val['table'], $val['id']); + } else { + $item = $val['id']; + } + + if (in_array($item, $oldMMs)) { + unset($oldMMs[array_search($item, $oldMMs)]); // remove the item from the $oldMMs array so after this foreach loop only the ones that need to be deleted are in there. + $whereClause = $uidLocal_field.'='.$uid.' AND '.$uidForeign_field.'='.$val['id']; - if ($tablename) + if ($tablename) { $whereClause .= ' AND tablenames="'.$tablename.'"'; + } $GLOBALS['TYPO3_DB']->exec_UPDATEquery($tableName, $whereClause, array($sorting_field => $c)); } else { $GLOBALS['TYPO3_DB']->exec_INSERTquery($tableName, array( @@ -323,13 +337,18 @@ class t3lib_loadDBGroup { } // Delete all not-used relations: - $additionalWhere = ''; - if (count($uidList)) { - $additionalWhere = ' AND '.$uidForeign_field.' NOT IN ( '.implode(',', $uidList).' ) '; + if(is_array($oldMMs) && count($oldMMs) > 0) { + $removeClauses = array(); + foreach($oldMMs as $mmItem) { + if(is_array($mmItem)) { + $removeClauses[] = 'tablenames="'.$mmItem[0].'" AND '.$uidForeign_field.'='.$mmItem[1]; + } else { + $removeClauses[] = $uidForeign_field.'='.$mmItem; + } + } + $additionalWhere = ' AND ('.implode(' OR ', $removeClauses).')'; + $GLOBALS['TYPO3_DB']->exec_DELETEquery($tableName, $uidLocal_field.'='.intval($uid).$additionalWhere.$additionalWhere_tablenames); } - - $GLOBALS['TYPO3_DB']->exec_DELETEquery($tableName, $uidLocal_field.'='.intval($uid).$additionalWhere.$additionalWhere_tablenames); - } } -- 2.20.1