0008817-copyL10nOverlays_v2.patch

Administrator Admin, 2009-10-20 22:10

Download (10.8 KB)

View differences:

t3lib/class.t3lib_tcemain.php (Arbeitskopie)
2733 2733
				// Now, the $uid is the actual record we will copy while $origUid is the record we asked to get copied - but that could be a live version.
2734 2734
*/
2735 2735
			if ($this->doesRecordExist($table,$uid,'show'))	{		// This checks if the record can be selected which is all that a copy action requires.
2736
				$data = Array();
2736
				if ($this->BE_USER->recordEditAccessInternals($table,$uid, false, false, true)) { //Used to check language and general editing rights
2737
					$data = Array();
2737
				$nonFields = array_unique(t3lib_div::trimExplode(',','uid,perms_userid,perms_groupid,perms_user,perms_group,perms_everybody,t3ver_oid,t3ver_wsid,t3ver_id,t3ver_label,t3ver_state,t3ver_swapmode,t3ver_count,t3ver_stage,t3ver_tstamp,'.$excludeFields,1));
2738
					$nonFields = array_unique(t3lib_div::trimExplode(',','uid,perms_userid,perms_groupid,perms_user,perms_group,perms_everybody,t3ver_oid,t3ver_wsid,t3ver_id,t3ver_label,t3ver_state,t3ver_swapmode,t3ver_count,t3ver_stage,t3ver_tstamp,'.$excludeFields,1));
2738
				// $row = $this->recordInfo($table,$uid,'*');
2739
				$row = t3lib_BEfunc::getRecordWSOL($table,$uid);	// So it copies (and localized) content from workspace...
2740
				if (is_array($row))	{
2739
					// $row = $this->recordInfo($table,$uid,'*');
2740
					$row = t3lib_BEfunc::getRecordWSOL($table,$uid);	// So it copies (and localized) content from workspace...
2741
					if (is_array($row))	{
2741
						// Initializing:
2742
					$theNewID = uniqid('NEW');
2743
					$enableField = isset($TCA[$table]['ctrl']['enablecolumns']) ? $TCA[$table]['ctrl']['enablecolumns']['disabled'] : '';
2744
					$headerField = $TCA[$table]['ctrl']['label'];
2742
							// Initializing:
2743
						$theNewID = uniqid('NEW');
2744
						$enableField = isset($TCA[$table]['ctrl']['enablecolumns']) ? $TCA[$table]['ctrl']['enablecolumns']['disabled'] : '';
2745
						$headerField = $TCA[$table]['ctrl']['label'];
2745
						// Getting default data:
2746
					$defaultData = $this->newFieldArray($table);
2746
							// Getting default data:
2747
						$defaultData = $this->newFieldArray($table);
2747
						// Getting "copy-after" fields if applicable:
2748
					$copyAfterFields = $destPid<0 ? $this->fixCopyAfterDuplFields($table,$uid,abs($destPid),0) : array();
2748
							// Getting "copy-after" fields if applicable:
2749
						$copyAfterFields = $destPid<0 ? $this->fixCopyAfterDuplFields($table,$uid,abs($destPid),0) : array();
2749
						// Page TSconfig related:
2750
					$tscPID = t3lib_BEfunc::getTSconfig_pidValue($table,$uid,$destPid);	// NOT using t3lib_BEfunc::getTSCpid() because we need the real pid - not the ID of a page, if the input is a page...
2751
					$TSConfig = $this->getTCEMAIN_TSconfig($tscPID);
2752
					$tE = $this->getTableEntries($table,$TSConfig);
2750
							// Page TSconfig related:
2751
						$tscPID = t3lib_BEfunc::getTSconfig_pidValue($table,$uid,$destPid);	// NOT using t3lib_BEfunc::getTSCpid() because we need the real pid - not the ID of a page, if the input is a page...
2752
						$TSConfig = $this->getTCEMAIN_TSconfig($tscPID);
2753
						$tE = $this->getTableEntries($table,$TSConfig);
2753
						// Traverse ALL fields of the selected record:
2754
					foreach($row as $field => $value)	{
2755
						if (!in_array($field,$nonFields))	{
2754
							// Traverse ALL fields of the selected record:
2755
						foreach($row as $field => $value)	{
2756
							if (!in_array($field,$nonFields))	{
2756
								// Get TCA configuration for the field:
2757
							$conf = $TCA[$table]['columns'][$field]['config'];
2757
									// Get TCA configuration for the field:
2758
								$conf = $TCA[$table]['columns'][$field]['config'];
2758
								// Preparation/Processing of the value:
2759
							if ($field=='pid')	{	// "pid" is hardcoded of course:
2760
								$value = $destPid;
2761
							} elseif (isset($overrideValues[$field]))	{	// Override value...
2762
								$value = $overrideValues[$field];
2763
							} elseif (isset($copyAfterFields[$field]))	{	// Copy-after value if available:
2764
								$value = $copyAfterFields[$field];
2765
							} elseif ($TCA[$table]['ctrl']['setToDefaultOnCopy'] && t3lib_div::inList($TCA[$table]['ctrl']['setToDefaultOnCopy'],$field))	{	// Revert to default for some fields:
2766
								$value = $defaultData[$field];
2767
							} else {
2768
									// Hide at copy may override:
2769
								if ($first && $field==$enableField && $TCA[$table]['ctrl']['hideAtCopy'] && !$this->neverHideAtCopy && !$tE['disableHideAtCopy'])	{
2770
									$value=1;
2759
									// Preparation/Processing of the value:
2760
								if ($field=='pid')	{	// "pid" is hardcoded of course:
2761
									$value = $destPid;
2762
								} elseif (isset($overrideValues[$field]))	{	// Override value...
2763
									$value = $overrideValues[$field];
2764
								} elseif (isset($copyAfterFields[$field]))	{	// Copy-after value if available:
2765
									$value = $copyAfterFields[$field];
2766
								} elseif ($TCA[$table]['ctrl']['setToDefaultOnCopy'] && t3lib_div::inList($TCA[$table]['ctrl']['setToDefaultOnCopy'],$field))	{	// Revert to default for some fields:
2767
									$value = $defaultData[$field];
2768
								} else {
2769
										// Hide at copy may override:
2770
									if ($first && $field == $enableField && $TCA[$table]['ctrl']['hideAtCopy'] && !$this->neverHideAtCopy && !$tE['disableHideAtCopy']) {
2771
										$value = 1;
2772
									}
2773
										// Prepend label on copy:
2774
									if ($first && $field == $headerField && $TCA[$table]['ctrl']['prependAtCopy'] && !$tE['disablePrependAtCopy']) {
2775
										$value = $this->getCopyHeader($table,$this->resolvePid($table,$destPid),$field,$this->clearPrefixFromValue($table,$value),0);
2776
									}
2777
										// Processing based on the TCA config field type (files, references, flexforms...)
2778
									$value = $this->copyRecord_procBasedOnFieldType($table, $uid, $field, $value, $row, $conf, $tscPID, $language);
2771 2779
								}
2772
									// Prepend label on copy:
2773
								if ($first && $field==$headerField && $TCA[$table]['ctrl']['prependAtCopy'] && !$tE['disablePrependAtCopy'])	{
2774
									$value = $this->getCopyHeader($table,$this->resolvePid($table,$destPid),$field,$this->clearPrefixFromValue($table,$value),0);
2775
								}
2776
									// Processing based on the TCA config field type (files, references, flexforms...)
2777
								$value = $this->copyRecord_procBasedOnFieldType($table, $uid, $field, $value, $row, $conf, $tscPID, $language);
2780

  
2781
									// Add value to array.
2782
								$data[$table][$theNewID][$field] = $value;
2778 2783
							}
2784
						}
2785
							// Overriding values:
2786
						if ($TCA[$table]['ctrl']['editlock']) {
2787
							$data[$table][$theNewID][$TCA[$table]['ctrl']['editlock']] = 0;
2788
						}
2779
								// Add value to array.
2780
							$data[$table][$theNewID][$field] = $value;
2789
							// Setting original UID:
2790
						if ($TCA[$table]['ctrl']['origUid']) {
2791
							$data[$table][$theNewID][$TCA[$table]['ctrl']['origUid']] = $uid;
2781 2792
						}
2782
					}
2783
						// Overriding values:
2784
					if ($TCA[$table]['ctrl']['editlock'])	{
2785
						$data[$table][$theNewID][$TCA[$table]['ctrl']['editlock']] = 0;
2786
					}
2793
							// Do the copy by simply submitting the array through TCEmain:
2794
						$copyTCE = t3lib_div::makeInstance('t3lib_TCEmain');
2795
						/* @var $copyTCE t3lib_TCEmain  */
2796
						$copyTCE->stripslashes_values = 0;
2797
						$copyTCE->copyTree = $this->copyTree;
2798
						$copyTCE->cachedTSconfig = $this->cachedTSconfig;	// Copy forth the cached TSconfig
2799
						$copyTCE->dontProcessTransformations=1;		// Transformations should NOT be carried out during copy
2787
						// Setting original UID:
2788
					if ($TCA[$table]['ctrl']['origUid'])	{
2789
						$data[$table][$theNewID][$TCA[$table]['ctrl']['origUid']] = $uid;
2790
					}
2800
						$copyTCE->start($data,'',$this->BE_USER);
2801
						$copyTCE->process_datamap();
2791
						// Do the copy by simply submitting the array through TCEmain:
2792
					$copyTCE = t3lib_div::makeInstance('t3lib_TCEmain');
2793
					/* @var $copyTCE t3lib_TCEmain  */
2794
					$copyTCE->stripslashes_values = 0;
2795
					$copyTCE->copyTree = $this->copyTree;
2796
					$copyTCE->cachedTSconfig = $this->cachedTSconfig;	// Copy forth the cached TSconfig
2797
					$copyTCE->dontProcessTransformations=1;		// Transformations should NOT be carried out during copy
2802
							// Getting the new UID:
2803
						$theNewSQLID = $copyTCE->substNEWwithIDs[$theNewID];
2804
						if ($theNewSQLID) {
2805
							$this->copyRecord_fixRTEmagicImages($table, t3lib_BEfunc::wsMapId($table, $theNewSQLID));
2806
							$this->copyMappingArray[$table][$origUid] = $theNewSQLID;
2807
						}
2798
					$copyTCE->start($data,'',$this->BE_USER);
2799
					$copyTCE->process_datamap();
2808
							// Copy back the cached TSconfig
2809
						$this->cachedTSconfig = $copyTCE->cachedTSconfig;
2810
						$this->errorLog = array_merge($this->errorLog, $copyTCE->errorLog);
2811
						unset($copyTCE);
2800
						// Getting the new UID:
2801
					$theNewSQLID = $copyTCE->substNEWwithIDs[$theNewID];
2802
					if ($theNewSQLID)	{
2803
						$this->copyRecord_fixRTEmagicImages($table,t3lib_BEfunc::wsMapId($table,$theNewSQLID));
2804
						$this->copyMappingArray[$table][$origUid] = $theNewSQLID;
2805
					}
2812
						if($language == 0) {
2813
								//repointing the new translation records to the parent record we just created
2814
							$overrideValues[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']] = $theNewSQLID;
2815
							$this->copyL10nOverlayRecords($table, $uid, $destPid, $first, $overrideValues, $excludeFields);
2816
						}
2806
						// Copy back the cached TSconfig
2807
					$this->cachedTSconfig = $copyTCE->cachedTSconfig;
2808
					$this->errorLog = array_merge($this->errorLog,$copyTCE->errorLog);
2809
					unset($copyTCE);
2810

  
2811
					return $theNewSQLID;
2812
				} else $this->log($table,$uid,3,0,1,'Attempt to copy record that did not exist!');
2817
						return $theNewSQLID;
2818
					} else $this->log($table,$uid,3,0,1,'Attempt to copy record that did not exist!');
2819
				}  else $this->log($table,$uid,3,0,1,'Attempt to copy record without having permissions to do so. ['.$this->BE_USER->errorMsg.'].');
2813 2820
			} else $this->log($table,$uid,3,0,1,'Attempt to copy record without permission');
2814 2821
		}
2815 2822
	}
......
3375
	/**
3376
	 * Find l10n-overlay records and perform the requested move action for these records.
3377
	 *
3378
	 * @param	string		$table: Record Table
3379
	 * @param	string		$uid: Record UID
3380
	 * @param	string		$destPid: Position to move to
3381
	 * @return	void
3382
	 */
3383
	function copyL10nOverlayRecords($table, $uid, $destPid, $first=0, $overrideValues=array(), $excludeFields='') {
3384
			//there's no need to perform this for page-records
3385
		if ($table == 'pages') return;
3386
		t3lib_div::loadTCA($table);
3387
		$l10nRecords = t3lib_BEfunc::getRecordsByField($table, $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'], $uid);
3388
		if (is_array($l10nRecords)) {
3389
			foreach ($l10nRecords as $record) {
3390
				$this->copyRecord($table, $record['uid'], $destPid, $first, $overrideValues, $excludeFields, $record[$GLOBALS['TCA'][$table]['ctrl']['languageField']]);
3391
			}
3392
		}
3393
	}