/**
  * Performes a "merging" of record data.
  * Data can be appended to existing data or replace it.
  *
  * @param	array		$rowSource The source record data. Needs uid and pid to be set.
  * @param	array		$replaceData Record data that should replace the original.
  * @param	array		$appendData Record data that should be appended to original.
  * @return	array Return an array of processed data which include the changed fields only
  */
 function getUpdateData($row, $replaceData, $appendData)
 {
     global $TCA, $TYPO3_CONF_VARS;
     $rowUpdate = array();
     if (is_array($replaceData)) {
         foreach ($replaceData as $field => $value) {
             $rowUpdate[$field] = $value;
         }
     }
     if (is_array($appendData)) {
         t3lib_div::loadTCA('tx_dam');
         foreach ($appendData as $field => $value) {
             $appended = false;
             if ($appendType = $TCA['tx_dam']['columns'][$field]['config']['appendType']) {
                 $appended = true;
                 switch ($appendType) {
                     case 'space':
                         $rowUpdate[$field] = trim($row[$field] . ' ' . $value);
                         break;
                     case 'newline':
                         $rowUpdate[$field] = $row[$field] . ($row[$field] ? "\n" : '') . $value;
                         break;
                     case 'comma':
                         $rowUpdate[$field] = $row[$field] . ($row[$field] ? ', ' : '') . $value;
                         break;
                     case 'charDef':
                     default:
                         list($type, $appendChar) = explode(':', $appendType);
                         $rowUpdate[$field] = $appendChar . $value;
                         break;
                     default:
                         $appended = false;
                         break;
                 }
             }
             if (!$appended) {
                 switch ($TCA['tx_dam']['columns'][$field]['config']['type']) {
                     case 'input':
                         $rowUpdate[$field] = trim($row[$field] . ' ' . $value);
                         break;
                     case 'text':
                         $rowUpdate[$field] = $row[$field] . ($row[$field] ? "\n" : '') . $value;
                         break;
                     case 'select':
                     case 'group':
                         $data = tx_dam_db::stripLabelFromGroupData($row[$field]);
                         $rowUpdate[$field] = $data . ',' . $value;
                         break;
                     case 'none':
                     case 'user':
                     case 'flex':
                     case 'check':
                     case 'radio':
                     default:
                         $rowUpdate[$field] = $value;
                         // replace anyway
                         break;
                 }
             }
         }
     }
     return $rowUpdate;
 }