Extbase:
[Packages/TYPO3.CMS.git] / typo3 / sysext / extbase / Classes / Persistence / Hook / TCEMainValueObjectUpdater.php
1 <?php
2 /* WE NEED TO DO IT STRTOLOWER */
3 class tx_ExtBase_Persistence_Hook_TCEMainValueObjectUpdater {
4 public function processDatamap_preProcessFieldArray(&$incomingFieldArray, $table, &$id, $tcemain) {
5 global $TCA;
6 if (isset($TCA[$table]['ctrl']['objectType']) && $TCA[$table]['ctrl']['objectType'] === 'ValueObject') {
7 $isNewRecord = !t3lib_div::testInt($id);
8
9 $uid = $this->findUid($incomingFieldArray, $table);
10 if ($uid !== NULL) {
11 // FOUND a UID.
12
13 var_dump($uid, $id);
14 var_dump($incomingFieldArray);
15 if ($isNewRecord) {
16 // re-map the insertion to an update!
17 $tcemain->substNEWwitIDs[$id] = (int)$uid;
18 $id = (int)$uid;
19 unset($incomingFieldArray['pid']);
20 }
21 //var_dump($incomingFieldArray, $table, $id, $uid);
22 //
23 //$incomingFieldArray['uid'] = $uid;
24 } else {
25 // We did not find an already existing entry with the same values in the DB
26 // Thus, the entry can safely be created if $isNewRecord.
27 // if record is not new, and we did not find any of these values in the DB, we can just leave the record as is.
28 if (!$isNewRecord) {
29
30 }
31 }
32
33 }
34 }
35
36 protected function findUid($incomingFieldArray, $table) {
37 $whereClauseArray = array();
38 unset($incomingFieldArray['uid']);
39 foreach ($incomingFieldArray as $key => $value) {
40 $whereClauseArray[] = $key . '=' . $GLOBALS['TYPO3_DB']->fullQuoteStr($value, 'dummy');
41 }
42 $resultArray = $GLOBALS['TYPO3_DB']->exec_SELECTgetRows('uid', $table, implode(' AND ', $whereClauseArray));
43
44 if (count($resultArray)) {
45 return $resultArray[0];
46 }
47 return NULL;
48 }
49 }
50 ?>