📄 class.tx_impexp.php
字号:
} $this->import_newId[$table.':'.$ID] = array('table' => $table, 'uid' => $uid); if ($table=='pages') $this->import_newId_pids[$uid] = $ID; // Set main record data: $this->import_data[$table][$ID] = $record; $this->import_data[$table][$ID]['tx_impexp_origuid'] = $this->import_data[$table][$ID]['uid']; // Reset permission data: if ($table==='pages') { // Have to reset the user/group IDs so pages are owned by importing user. Otherwise strange things may happen for non-admins! unset($this->import_data[$table][$ID]['perms_userid']); unset($this->import_data[$table][$ID]['perms_groupid']); // user/group/everybody settings is kept - but these might still conflict with possibilities for writing the content!" #unset($this->import_data[$table][$ID]['perms_user']); #unset($this->import_data[$table][$ID]['perms_group']); #unset($this->import_data[$table][$ID]['perms_everybody']); } // PID and UID: unset($this->import_data[$table][$ID]['uid']); if (t3lib_div::testInt($ID)) { // Updates: unset($this->import_data[$table][$ID]['pid']); } else { // Inserts: $this->import_data[$table][$ID]['pid'] = $pid; if ((($this->import_mode[$table.':'.$uid]==='force_uid' && $this->update) || $this->force_all_UIDS) && $GLOBALS['BE_USER']->isAdmin()) {#debug($this->import_mode[$table.':'.$uid],$table.':'.$uid); $this->import_data[$table][$ID]['uid'] = $uid; $this->suggestedInsertUids[$table.':'.$uid] = 'DELETE'; } } // Setting db/file blank: reset($this->dat['records'][$table.':'.$uid]['rels']); while(list($field,$config) = each($this->dat['records'][$table.':'.$uid]['rels'])) { switch((string)$config['type']) { case 'db': case 'file': // Fixed later in ->setRelations() [because we need to know ALL newly created IDs before we can map relations!] // In the meantime we set NO values for relations: $this->import_data[$table][$ID][$field] = ''; break; case 'flex': // Fixed later in setFlexFormRelations() // In the meantime we set NO value for flexforms - this is mainly because file references inside will not be processed properly; In fact references will point to no file or existing files (in which case there will be double-references which is a big problem of course!) $this->import_data[$table][$ID][$field] = ''; break; } } } elseif ($table.':'.$uid != 'pages:0') { // On root level we don't want this error message. $this->error('Error: no record was found in data array!',1); } } } /** * Registers the substNEWids in memory. * * @param array $substNEWwithIDs from tcemain to be merged into internal mapping variable in this object * @return void * @see writeRecords() */ function addToMapId($substNEWwithIDs) { reset($this->import_data); while(list($table,$recs)=each($this->import_data)) { reset($recs); while(list($id)=each($recs)) { $old_uid = $this->import_newId[$table.':'.$id]['uid']; if (isset($substNEWwithIDs[$id])) { $this->import_mapId[$table][$old_uid] = $substNEWwithIDs[$id]; } elseif ($this->update) { $this->import_mapId[$table][$old_uid] = $id; // Map same ID to same ID.... } else $this->error('Possible error: '.$table.':'.$old_uid.' had no new id assigned to it. This indicates that the record was not added to database during import. Please check changelog!',1); } } } /** * Returns a new $TCE object * * @return object $TCE object */ function getNewTCE() { $tce = t3lib_div::makeInstance('t3lib_TCEmain'); $tce->stripslashes_values = 0; $tce->dontProcessTransformations = 1; $tce->enableLogging = $this->enableLogging; $tce->alternativeFileName = $this->alternativeFileName; return $tce; } /** * Cleaning up all the temporary files stored in typo3temp/ folder * * @return void */ function unlinkTempFiles() { foreach($this->unlinkFiles as $fileName) { if (t3lib_div::isFirstPartOfStr($fileName, PATH_site.'typo3temp/')) { t3lib_div::unlink_tempfile($fileName); clearstatcache(); if (is_file($fileName)) { $this->error('Error: '.$fileName.' was NOT unlinked as it should have been!',1); } } else $this->error('Error: '.$fileName.' was not in temp-path. Not removed!',1); } $this->unlinkFiles = array(); } /*************************** * * Import / Relations setting * ***************************/ /** * At the end of the import process all file and DB relations should be set properly (that is relations to imported records are all re-created so imported records are correctly related again) * Relations in flexform fields are processed in setFlexFormRelations() after this function * * @return void * @see setFlexFormRelations() */ function setRelations() { global $TCA; $updateData = array(); // import_newId contains a register of all records that was in the import memorys "records" key reset($this->import_newId); while(list($nId,$dat) = each($this->import_newId)) { $table = $dat['table']; $uid = $dat['uid']; // original UID - NOT the new one! // If the record has been written and received a new id, then proceed: if (is_array($this->import_mapId[$table]) && isset($this->import_mapId[$table][$uid])) { $thisNewUid = t3lib_BEfunc::wsMapId($table,$this->import_mapId[$table][$uid]); if (is_array($this->dat['records'][$table.':'.$uid]['rels'])) { reset($this->dat['records'][$table.':'.$uid]['rels']); // Traverse relation fields of each record while(list($field,$config) = each($this->dat['records'][$table.':'.$uid]['rels'])) { switch((string)$config['type']) { case 'db': if (is_array($config['itemArray']) && count($config['itemArray'])) { $valArray = $this->setRelations_db($config['itemArray']); $updateData[$table][$thisNewUid][$field] = implode(',',$valArray); // List of [table]_[uid] } break; case 'file': if (is_array($config['newValueFiles']) && count($config['newValueFiles'])) { $valArr = array(); foreach($config['newValueFiles'] as $fI) { $valArr[] = $this->import_addFileNameToBeCopied($fI); } $updateData[$table][$thisNewUid][$field] = implode(',',$valArr); // List of absolute files } break; } } } else $this->error('Error: no record was found in data array!',1); } else $this->error('Error: this records is NOT created it seems! ('.$table.':'.$uid.')',1); } if (count($updateData)) { $tce = $this->getNewTCE(); $tce->start($updateData,Array()); $tce->process_datamap();#debug($updateData,'setRelations()'); } } /** * Maps relations for database * * @param array Array of item sets (table/uid) from a dbAnalysis object * @return array Array with values [table]_[uid]. These values have the regular tcemain-input group/select type which means they will automatically be processed into a uid-list or MM relations. */ function setRelations_db($itemArray) { $valArray = array(); foreach($itemArray as $relDat) { if (is_array($this->import_mapId[$relDat['table']]) && isset($this->import_mapId[$relDat['table']][$relDat['id']])) { #debug('FOUND: '.$relDat['table'].':'.$relDat['id'],1); $valArray[] = $relDat['table'].'_'.$this->import_mapId[$relDat['table']][$relDat['id']]; } elseif ($this->isTableStatic($relDat['table']) || $this->isExcluded($relDat['table'], $relDat['id']) || $relDat['id']<0) { // Checking for less than zero because some select types could contain negative values, eg. fe_groups (-1, -2) and sys_language (-1 = ALL languages). This must be handled on both export and import. #debug('STATIC: '.$relDat['table'].':'.$relDat['id'],1); $valArray[] = $relDat['table'].'_'.$relDat['id']; } else { $this->error('Lost relation: '.$relDat['table'].':'.$relDat['id'],1); } } return $valArray; } /** * Writes the file from import array to temp dir and returns the filename of it. * * @param array File information with three keys: "filename" = filename without path, "ID_absFile" = absolute filepath to the file (including the filename), "ID" = md5 hash of "ID_absFile" * @return string Absolute filename of the temporary filename of the file. In ->alternativeFileName the original name is set. */ function import_addFileNameToBeCopied($fI) { if (is_array($this->dat['files'][$fI['ID']])) { $tmpFile = t3lib_div::tempnam('import_temp_'); t3lib_div::writeFile($tmpFile,$this->dat['files'][$fI['ID']]['content']); clearstatcache(); if (@is_file($tmpFile)) { $this->unlinkFiles[] = $tmpFile; if (filesize($tmpFile)==$this->dat['files'][$fI['ID']]['filesize']) { $this->alternativeFileName[$tmpFile] = $fI['filename']; return $tmpFile; } else $this->error('Error: temporary file '.$tmpFile.' had a size ('.filesize($tmpFile).') different from the original ('.$this->dat['files'][$fI['ID']]['filesize'].')',1); } else $this->error('Error: temporary file '.$tmpFile.' was not written as it should have been!',1); } else $this->error('Error: No file found for ID '.$fI['ID'],1); } /** * After all DB relations has been set in the end of the import (see setRelations()) then it is time to correct all relations inside of FlexForm fields. * The reason for doing this after is that the setting of relations may affect (quite often!) which data structure is used for the flexforms field! * * @return void * @see setRelations() */ function setFlexFormRelations() { global $TCA; $updateData = array();#debug($this->import_newId); // import_newId contains a register of all records that was in the import memorys "records" key reset($this->import_newId); while(list($nId,$dat) = each($this->import_newId)) { $table = $dat['table']; $uid = $dat['uid']; // original UID - NOT the new one! // If the record has been written and received a new id, then proceed: if (is_array($this->import_mapId[$table]) && isset($this->import_mapId[$table][$uid])) { $thisNewUid = t3lib_BEfunc::wsMapId($table,$this->import_mapId[$table][$uid]);#debug($thisNewUid,'$thisNewUid');#debug($this->dat['records'][$table.':'.$uid]['rels']); if (is_array($this->dat['records'][$table.':'.$uid]['rels'])) { reset($this->dat['records'][$table.':'.$uid]['rels']); t3lib_div::loadTCA($table); // Traverse relation fields of each record while(list($field,$config) = each($this->dat['records'][$table.':'.$uid]['rels'])) { switch((string)$config['type']) { case 'flex': // Get XML content and set as default value (string, non-processed): $updateData[$table][$thisNewUid][$field] = $this->dat['records'][$table.':'.$uid]['data'][$field]; // If there has been registered relations inside the flex form field, run processing on the content: if (count($config['flexFormRels']['db']) || count($config['flexFormRels']['file'])) { $origRecordRow = t3lib_BEfunc::getRecord($table,$thisNewUid,'*'); // This will fetch the new row for the element (which should be updated with any references to data structures etc.)#debug(array($updateData[$table][$thisNewUid][$field]),'flexXML'); $conf = $TCA[$table]['columns'][$field]['config']; if (is_array($origRecordRow) && is_array($conf) && $conf['type']==='flex') {#debug($conf,'***'); // Get current data structure and value array: $dataStructArray = t3lib_BEfunc::getFlexFormDS($conf, $origRecordRow, $table); $currentValueArray = t3lib_div::xml2array($updateData[$table][$thisNewUid][$field]);# debug($dataStructArray);# debug($currentValueArray);# debug($origRecordRow);# debug($currentValueArray['data'],'BE'); // Do recursive processing of the XML data: $iteratorObj = t3lib_div::makeInstance('t3lib_TCEmain'); $iteratorObj->callBackObj = &$this; $currentValueArray['data'] = $iteratorObj->checkValue_flex_procInData( $currentValueArray['data'], array(), // Not used. array(), // Not used. $dataStructArray, array($table,$thisNewUid,$field,$config), // Parameters. 'remapListedDBRecords_flexFormCallBack' );#debug($currentValueArray['data'],'AF'); // The return value is set as an array which means it will be processed by tcemain for file and DB references! if (is_array($currentValueArray['data'])) { $updateData[$table][$thisNewUid][$field] = $currentValueArray; } } } break; } } } else $this->error('Error: no record was found in data array!',1); } else $this->error('Error: this records is NOT created it seems! ('.$table.':'.$uid.')',1); } if (count($updateData)) { $tce = $this->getNewTCE(); $tce->start($updateData,Array()); $tce->process_datamap();#debug($updateData,'setFlexFormRelations()'); } } /** * Callback function for traversing the FlexForm structure in relation to remapping database relations * * @param array Set of parameters in numeric array: table, uid, field * @param array TCA config for field (from Data Structure of course) * @param string Field value (from FlexForm XML) * @param string Not used * @param string Not used * @param string Path of where the data structure of the element is found * @return array Array where the "value" key carries the value. * @see setFlexFormRelations() */ function remapListedDBRecords_flexFormCallBack($pParams, $dsConf, $dataValue, $dataValue_ext1, $dataValue_ext2, $path) { // Extract parameters: list($table,$uid,$field,$config) = $pParams; // In case the $path is used as index without a trailing slash we will remove that if (!is_array($config['flexFormRels']['db'][$path]) && is_array($config['flexFormRels']['db'][ereg_replace('\/$','',$path)])) { $path = ereg_replace('\/$','',$path); } if (is_array($config['flexFormRels']['db'][$path])) { $valArray = $this->setRelations_db($config['flexFormRels']['db'][$path]); $dataValue = implode(',',$valArray);# debug(array('value' => $dataValue)); } if (is_array($config['flexFormRels']['file'][$path])) { foreach($config['flexFormRels']['file'][$path] as $fI) { $valArr[] =
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -