/**
  * Hook for updating translation index when records are edited (hooks into TCEmain)
  *
  * @param   [type]    $status: ...
  * @param   [type]    $table: ...
  * @param   [type]    $id: ...
  * @param   [type]    $fieldArray: ...
  * @param   [type]    $pObj: ...
  * @return  [type]    ...
  */
 function processDatamap_afterDatabaseOperations($status, $table, $id, $fieldArray, &$pObj)
 {
     global $TCA;
     // Check if
     #		debug(array($status, $table, $id));
     // Map id for new records:
     if ($status == "new") {
         $id = $pObj->substNEWwithIDs[$id];
         #			echo "New fixed<br>";
     }
     // Find live record if any:
     if (!($liveRecord = t3lib_BEfunc::getLiveVersionOfRecord($table, $id))) {
         // If it was a version we find live...
         $liveRecord = t3lib_BEfunc::getRecord($table, $id);
         // Otherwise we load live record.
         #			echo "Live version<br>";
     }
     if (is_array($liveRecord)) {
         // Now, see if this record is a translation of another one:
         $t8ToolsObj = t3lib_div::makeInstance('t3lib_transl8tools');
         if ($t8ToolsObj->isTranslationInOwnTable($table) && $liveRecord[$TCA[$table]['ctrl']['transOrigPointerField']]) {
             // So it had a translation pointer - lets look for the root record then:
             $liveRecord = t3lib_BEfunc::getRecord($table, $liveRecord[$TCA[$table]['ctrl']['transOrigPointerField']], 'uid');
             #				echo "Finding root version<br>";
         } elseif ($TCA[$table]['ctrl']['transOrigPointerTable'] && $liveRecord[$TCA[$table]['ctrl']['transOrigPointerField']]) {
             $fld = $TCA[$table]['ctrl']['transOrigPointerField'];
             $table = $TCA[$table]['ctrl']['transOrigPointerTable'];
             // Changeing table value here on purpose!
             $liveRecord = t3lib_BEfunc::getRecord($table, $liveRecord[$fld], 'uid');
         }
         $languageID = tx_l10nmgr_l10nBaseService::getTargetLanguageID();
         if (is_array($liveRecord)) {
             #				echo "indexing id ".$liveRecord['uid'];
             // Finally, we have found the "root record" and will check it:
             $t8Tools = t3lib_div::makeInstance('tx_l10nmgr_tools');
             $t8Tools->verbose = FALSE;
             // Otherwise it will show records which has fields but none editable.
             #				debug($t8Tools->indexDetailsRecord($table,$liveRecord['uid']));
             $t8Tools->updateIndexTableFromDetailsArray($t8Tools->indexDetailsRecord($table, $liveRecord['uid'], $languageID));
         }
     }
 }
 /**
  * Submit incoming content as translated language to database. Must match what is available in $accum.
  *
  * @param array $accum Translation configuration
  * @param array $inputArray Array with incoming translation. Must match what is found in $accum
  * @return mixed False if error - else flexFormDiffArray (if $inputArray was an array and processing was performed.)
  */
 function _submitContentAsTranslatedLanguageAndGetFlexFormDiff($accum, $inputArray)
 {
     if (is_array($inputArray)) {
         // Initialize:
         /** @var $flexToolObj t3lib_flexformtools */
         $flexToolObj = t3lib_div::makeInstance('t3lib_flexformtools');
         $TCEmain_data = array();
         $TCEmain_cmd = array();
         $_flexFormDiffArray = array();
         // Traverse:
         foreach ($accum as $pId => $page) {
             foreach ($accum[$pId]['items'] as $table => $elements) {
                 foreach ($elements as $elementUid => $data) {
                     if (is_array($data['fields'])) {
                         foreach ($data['fields'] as $key => $tData) {
                             if (is_array($tData) && isset($inputArray[$table][$elementUid][$key])) {
                                 list($Ttable, $TuidString, $Tfield, $Tpath) = explode(':', $key);
                                 list($Tuid, $Tlang, $TdefRecord) = explode('/', $TuidString);
                                 if (!$this->createTranslationAlsoIfEmpty && $inputArray[$table][$elementUid][$key] == '' && $Tuid == 'NEW') {
                                     //if data is empty do not save it
                                     unset($inputArray[$table][$elementUid][$key]);
                                     continue;
                                 }
                                 // If new element is required, we prepare for localization
                                 if ($Tuid === 'NEW') {
                                     //print "\nNEW\n";
                                     $TCEmain_cmd[$table][$elementUid]['localize'] = $Tlang;
                                 }
                                 // If FlexForm, we set value in special way:
                                 if ($Tpath) {
                                     if (!is_array($TCEmain_data[$Ttable][$TuidString][$Tfield])) {
                                         $TCEmain_data[$Ttable][$TuidString][$Tfield] = array();
                                     }
                                     //TCEMAINDATA is passed as reference here:
                                     $flexToolObj->setArrayValueByPath($Tpath, $TCEmain_data[$Ttable][$TuidString][$Tfield], $inputArray[$table][$elementUid][$key]);
                                     $_flexFormDiffArray[$key] = array('translated' => $inputArray[$table][$elementUid][$key], 'default' => $tData['defaultValue']);
                                 } else {
                                     $TCEmain_data[$Ttable][$TuidString][$Tfield] = $inputArray[$table][$elementUid][$key];
                                 }
                                 unset($inputArray[$table][$elementUid][$key]);
                                 // Unsetting so in the end we can see if $inputArray was fully processed.
                             } else {
                                 //debug($tData,'fields not set for: '.$elementUid.'-'.$key);
                                 //debug($inputArray[$table],'inputarray');
                             }
                         }
                         if (is_array($inputArray[$table][$elementUid]) && !count($inputArray[$table][$elementUid])) {
                             unset($inputArray[$table][$elementUid]);
                             // Unsetting so in the end we can see if $inputArray was fully processed.
                         }
                     }
                 }
                 if (is_array($inputArray[$table]) && !count($inputArray[$table])) {
                     unset($inputArray[$table]);
                     // Unsetting so in the end we can see if $inputArray was fully processed.
                 }
             }
         }
         //debug($TCEmain_cmd,'$TCEmain_cmd');
         //debug($TCEmain_data,'$TCEmain_data');
         self::$targetLanguageID = $Tlang;
         // Execute CMD array: Localizing records:
         /** @var $tce t3lib_TCEmain */
         $tce = t3lib_div::makeInstance('t3lib_TCEmain');
         if ($this->extensionConfiguration['enable_neverHideAtCopy'] == 1) {
             $tce->neverHideAtCopy = TRUE;
         }
         $tce->stripslashes_values = FALSE;
         if (count($TCEmain_cmd)) {
             $tce->start(array(), $TCEmain_cmd);
             $tce->process_cmdmap();
             if (count($tce->errorLog)) {
                 debug($tce->errorLog, 'TCEmain localization errors:');
             }
         }
         // Before remapping
         if (TYPO3_DLOG) {
             t3lib_div::sysLog(__FILE__ . ': ' . __LINE__ . ': TCEmain_data before remapping: ' . t3lib_div::arrayToLogString($TCEmain_data), 'l10nmgr');
         }
         // Remapping those elements which are new:
         $this->lastTCEMAINCommandsCount = 0;
         foreach ($TCEmain_data as $table => $items) {
             foreach ($TCEmain_data[$table] as $TuidString => $fields) {
                 list($Tuid, $Tlang, $TdefRecord) = explode('/', $TuidString);
                 $this->lastTCEMAINCommandsCount++;
                 if ($Tuid === 'NEW') {
                     if ($tce->copyMappingArray_merged[$table][$TdefRecord]) {
                         $TCEmain_data[$table][t3lib_BEfunc::wsMapId($table, $tce->copyMappingArray_merged[$table][$TdefRecord])] = $fields;
                     } else {
                         t3lib_div::sysLog(__FILE__ . ': ' . __LINE__ . ': Record "' . $table . ':' . $TdefRecord . '" was NOT localized as it should have been!', 'l10nmgr');
                     }
                     unset($TCEmain_data[$table][$TuidString]);
                 }
             }
         }
         // After remapping
         if (TYPO3_DLOG) {
             t3lib_div::sysLog(__FILE__ . ': ' . __LINE__ . ': TCEmain_data after remapping: ' . t3lib_div::arrayToLogString($TCEmain_data), 'l10nmgr');
         }
         // Now, submitting translation data:
         /** @var $tce t3lib_TCEmain */
         $tce = t3lib_div::makeInstance('t3lib_TCEmain');
         if ($this->extensionConfiguration['enable_neverHideAtCopy'] == 1) {
             $tce->neverHideAtCopy = TRUE;
         }
         $tce->stripslashes_values = FALSE;
         $tce->dontProcessTransformations = TRUE;
         //print_r($TCEmain_data);
         $tce->start($TCEmain_data, array());
         // check has been done previously that there is a backend user which is Admin and also in live workspace
         $tce->process_datamap();
         self::$targetLanguageID = NULL;
         if (count($tce->errorLog)) {
             t3lib_div::sysLog(__FILE__ . ': ' . __LINE__ . ': TCEmain update errors: ' . t3lib_div::arrayToLogString($tce->errorLog), 'l10nmgr');
         }
         if (count($tce->autoVersionIdMap) && count($_flexFormDiffArray)) {
             if (TYPO3_DLOG) {
                 t3lib_div::sysLog(__FILE__ . ': ' . __LINE__ . ': flexFormDiffArry: ' . t3lib_div::arrayToLogString($this->flexFormDiffArray), 'l10nmgr');
             }
             foreach ($_flexFormDiffArray as $key => $value) {
                 list($Ttable, $Tuid, $Trest) = explode(':', $key, 3);
                 if ($tce->autoVersionIdMap[$Ttable][$Tuid]) {
                     $_flexFormDiffArray[$Ttable . ':' . $tce->autoVersionIdMap[$Ttable][$Tuid] . ':' . $Trest] = $_flexFormDiffArray[$key];
                     unset($_flexFormDiffArray[$key]);
                 }
             }
             if (TYPO3_DLOG) {
                 t3lib_div::sysLog(__FILE__ . ': ' . __LINE__ . ': autoVersionIdMap: ' . $tce->autoVersionIdMap, 'l10nmgr');
                 t3lib_div::sysLog(__FILE__ . ': ' . __LINE__ . ': _flexFormDiffArray: ' . t3lib_div::arrayToLogString($_flexFormDiffArray), 'l10nmgr');
             }
         }
         // Should be empty now - or there were more information in the incoming array than there should be!
         if (count($inputArray)) {
             debug($inputArray, 'These fields were ignored since they were not in the configuration:');
         }
         return $_flexFormDiffArray;
     } else {
         return FALSE;
     }
 }