📄 class.tx_impexp.php
字号:
'/pid_lookup/page_contents' => array( 'disableTypeAttrib' => TRUE, 'parentTagMap' => array( 'page_contents' => 'table' ), 'grandParentTagMap' => array( 'page_contents/table' => 'item' ) ) ) ), '/records' => array( 'disableTypeAttrib' => TRUE, 'parentTagMap' => array( 'records' => 'tablerow', 'tablerow:data' => 'fieldlist', 'tablerow:rels' => 'related', 'related' => 'field', 'field:itemArray' => 'relations', 'field:newValueFiles' => 'filerefs', 'field:flexFormRels' => 'flexform', 'relations' => 'element', 'filerefs' => 'file', 'flexform:db' => 'db_relations', 'flexform:file' => 'file_relations', 'flexform:softrefs' => 'softref_relations', 'softref_relations' => 'structurePath', 'db_relations' => 'path', 'file_relations' => 'path', 'path' => 'element', 'keys' => 'softref_key', 'softref_key' => 'softref_element', ), 'alt_options' => array( '/records/tablerow/fieldlist' => array( 'useIndexTagForAssoc' => 'field', ) ) ), '/files' => array( 'disableTypeAttrib' => TRUE, 'parentTagMap' => array( 'files' => 'file', ), ), ) ); // Creating XML file from $outputArray: $charset = $this->dat['header']['charset'] ? $this->dat['header']['charset'] : 'iso-8859-1'; $XML = '<?xml version="1.0" encoding="'.$charset.'" standalone="yes" ?>'.chr(10); $XML.= t3lib_div::array2xml($this->dat,'',0,'T3RecordDocument',0,$options); return $XML; } /** * Returns true if the output should be compressed. * * @return boolean True if compression is possible AND requested. */ function doOutputCompress() { return $this->compress && !$this->dontCompress; } /** * Returns a content part for a filename being build. * * @param array Data to store in part * @param boolean Compress file? * @return string Content stream. */ function addFilePart($data, $compress=FALSE) { if ($compress) $data = gzcompress($data); return md5($data).':'. ($compress?'1':'0').':'. str_pad(strlen($data),10,'0',STR_PAD_LEFT).':'. $data.':'; } /*********************** * * Import * ***********************/ /** * Imports the internal data array to $pid. * * @param integer Page ID in which to import the content * @return void ... */ function importData($pid) { // Set this flag to indicate that an import is being/has been done. $this->doesImport = 1; // Initialize: // These vars MUST last for the whole section not being cleared. They are used by the method setRelations() which are called at the end of the import session. $this->import_mapId = array(); $this->import_newId = array(); $this->import_newId_pids = array(); // Temporary files stack initialized: $this->unlinkFiles = array(); $this->alternativeFileName = array(); // Write records, first pages, then the rest // Fields with "hard" relations to database, files and flexform fields are kept empty during this run $this->writeRecords_pages($pid); $this->writeRecords_records($pid); // Finally all the file and DB record references must be fixed. This is done after all records have supposedly been written to database: // $this->import_mapId will indicate two things: 1) that a record WAS written to db and 2) that it has got a new id-number. $this->setRelations(); // And when all DB relations are in place, we can fix file and DB relations in flexform fields (since data structures often depends on relations to a DS record): $this->setFlexFormRelations(); // Unlink temporary files: $this->unlinkTempFiles(); // Finally, traverse all records and process softreferences with substitution attributes. $this->processSoftReferences(); } /** * Writing pagetree/pages to database: * * @param integer PID in which to import. If the operation is an update operation, the root of the page tree inside will be moved to this PID unless it is the same as the root page from the import * @return void * @see writeRecords_records() */ function writeRecords_pages($pid) { // First, write page structure if any: if (is_array($this->dat['header']['records']['pages'])) { // $pageRecords is a copy of the pages array in the imported file. Records here are unset one by one when the addSingle function is called. $pageRecords = $this->dat['header']['records']['pages']; $this->import_data = array();#debug($pageRecords); // First add page tree if any if (is_array($this->dat['header']['pagetree'])) { $pagesFromTree = $this->flatInversePageTree($this->dat['header']['pagetree']); foreach($pagesFromTree as $uid) { $thisRec = $this->dat['header']['records']['pages'][$uid]; // PID: Set the main $pid, unless a NEW-id is found $setPid = isset($this->import_newId_pids[$thisRec['pid']]) ? $this->import_newId_pids[$thisRec['pid']] : $pid; $this->addSingle('pages',$uid,$setPid); unset($pageRecords[$uid]); } }#debug($pageRecords); // Then add all remaining pages not in tree on root level: if (count($pageRecords)) { $remainingPageUids = array_keys($pageRecords); foreach($remainingPageUids as $pUid) { $this->addSingle('pages',$pUid,$pid); } } // Now write to database: $tce = $this->getNewTCE(); $tce->suggestedInsertUids = $this->suggestedInsertUids; $tce->start($this->import_data,Array()); $tce->process_datamap();#debug($this->import_data,'PAGES'); // post-processing: Registering new ids (end all tcemain sessions with this) $this->addToMapId($tce->substNEWwithIDs); // In case of an update, order pages from the page tree correctly: if ($this->update && is_array($this->dat['header']['pagetree'])) { $this->writeRecords_pages_order($pid); } } } /** * Organize all updated pages in page tree so they are related like in the import file * Only used for updates and when $this->dat['header']['pagetree'] is an array. * * @param integer Page id in which to import * @return void * @access private * @see writeRecords_pages(), writeRecords_records_order() */ function writeRecords_pages_order($pid) { $cmd_data = array(); // Get uid-pid relations and traverse them in order to map to possible new IDs $pidsFromTree = $this->flatInversePageTree_pid($this->dat['header']['pagetree']);#debug($this->dat['header']['pagetree'],'pagetree');#debug($pidsFromTree,'$pidsFromTree');#debug($this->import_newId_pids,'import_newId_pids'); foreach($pidsFromTree as $origPid => $newPid) { if ($newPid>=0 && $this->dontIgnorePid('pages', $origPid)) { if (substr($this->import_newId_pids[$origPid],0,3)==='NEW') { // If the page had a new id (because it was created) use that instead! if ($this->import_mapId['pages'][$origPid]) { $mappedPid = $this->import_mapId['pages'][$origPid]; $cmd_data['pages'][$mappedPid]['move'] = $newPid; } } else { $cmd_data['pages'][$origPid]['move'] = $newPid; } } } // Execute the move commands if any: if (count($cmd_data)) { $tce = $this->getNewTCE(); $tce->start(Array(),$cmd_data); $tce->process_cmdmap(); }#debug($cmd_data,'$cmd_data'); } /** * Write all database records except pages (writtein in writeRecords_pages()) * * @param integer Page id in which to import * @return void * @see writeRecords_pages() */ function writeRecords_records($pid) { global $TCA; // Write the rest of the records $this->import_data = array(); if (is_array($this->dat['header']['records'])) { reset($this->dat['header']['records']); while(list($table,$recs) = each($this->dat['header']['records'])) { if ($table!='pages') { reset($recs); while(list($uid,$thisRec)=each($recs)) { // PID: Set the main $pid, unless a NEW-id is found $setPid = isset($this->import_mapId['pages'][$thisRec['pid']]) ? $this->import_mapId['pages'][$thisRec['pid']] : $pid; if (is_array($TCA[$table]) && $TCA[$table]['ctrl']['rootLevel']) { $setPid = 0; } // Add record: $this->addSingle($table,$uid,$setPid); } } } } else $this->error('Error: No records defined in internal data array.'); // Now write to database: $tce = $this->getNewTCE(); $tce->suggestedInsertUids = $this->suggestedInsertUids; $tce->reverseOrder=1; // Because all records are being submitted in their correct order with positive pid numbers - and so we should reverse submission order internally. $tce->start($this->import_data,Array()); $tce->process_datamap();#debug($this->import_data,'RECORDS'); // post-processing: Removing files and registering new ids (end all tcemain sessions with this) $this->addToMapId($tce->substNEWwithIDs); // In case of an update, order pages from the page tree correctly: if ($this->update) { $this->writeRecords_records_order($pid); } } /** * Organize all updated record to their new positions. * Only used for updates * * @param integer Main PID into which we import. * @return void * @access private * @see writeRecords_records(), writeRecords_pages_order() */ function writeRecords_records_order($mainPid) { $cmd_data = array(); if (is_array($this->dat['header']['pagetree'])) { $pagesFromTree = $this->flatInversePageTree($this->dat['header']['pagetree']); } else $pagesFromTree = array();#debug($this->dat['header']['pid_lookup'],'pid_lookup'); if (is_array($this->dat['header']['pid_lookup'])) { foreach($this->dat['header']['pid_lookup'] as $pid => $recList) { $newPid = isset($this->import_mapId['pages'][$pid]) ? $this->import_mapId['pages'][$pid] : $mainPid;#debug(array($pid,$newPid),'$pid / $newPid'); if (t3lib_div::testInt($newPid)) { foreach($recList as $tableName => $uidList) { if (($tableName!='pages' || !$pagesFromTree[$pid]) && is_array($uidList)) { // If $mainPid===$newPid then we are on root level and we can consider to move pages as well! (they will not be in the page tree!) $uidList = array_reverse(array_keys($uidList)); foreach($uidList as $uid) { if ($this->dontIgnorePid($tableName, $uid)) { $cmd_data[$tableName][$uid]['move'] = $newPid; } else {#debug($tableName.':'.$uid,'removed'); } } } } } } } // Execute the move commands if any: if (count($cmd_data)) { $tce = $this->getNewTCE(); $tce->start(Array(),$cmd_data); $tce->process_cmdmap(); }#debug($cmd_data,'$cmd_data'); } /** * Adds a single record to the $importData array. Also copies files to tempfolder. * However all File/DB-references and flexform field contents are set to blank for now! That is done with setRelations() later * * @param string Table name (from import memory) * @param integer Record UID (from import memory) * @param integer Page id * @return void * @see writeRecords() */ function addSingle($table,$uid,$pid) { if ($this->import_mode[$table.':'.$uid]!=='exclude') { $record = $this->dat['records'][$table.':'.$uid]['data']; if (is_array($record)) { if ($this->update && $this->doesRecordExist($table,$uid) && $this->import_mode[$table.':'.$uid]!=='as_new') { $ID = $uid; } else {#debug($this->import_mode[$table.':'.$uid],$table.':'.$uid); $ID = uniqid('NEW');
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -