0008817-copyL10nOverlays.patch

Administrator Admin, 2009-10-19 16:32

Download (10.8 KB)

View differences:

t3lib/class.t3lib_tcemain.php (working copy)
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 2738

  
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));
2739
					$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));
2739 2740

  
2740
				// $row = $this->recordInfo($table,$uid,'*');
2741
				$row = t3lib_BEfunc::getRecordWSOL($table,$uid);	// So it copies (and localized) content from workspace...
2742
				if (is_array($row))	{
2741
					// $row = $this->recordInfo($table,$uid,'*');
2742
					$row = t3lib_BEfunc::getRecordWSOL($table,$uid);	// So it copies (and localized) content from workspace...
2743
					if (is_array($row))	{
2743 2744

  
2744
						// Initializing:
2745
					$theNewID = uniqid('NEW');
2746
					$enableField = isset($TCA[$table]['ctrl']['enablecolumns']) ? $TCA[$table]['ctrl']['enablecolumns']['disabled'] : '';
2747
					$headerField = $TCA[$table]['ctrl']['label'];
2745
							// Initializing:
2746
						$theNewID = uniqid('NEW');
2747
						$enableField = isset($TCA[$table]['ctrl']['enablecolumns']) ? $TCA[$table]['ctrl']['enablecolumns']['disabled'] : '';
2748
						$headerField = $TCA[$table]['ctrl']['label'];
2748 2749

  
2749
						// Getting default data:
2750
					$defaultData = $this->newFieldArray($table);
2750
							// Getting default data:
2751
						$defaultData = $this->newFieldArray($table);
2751 2752

  
2752
						// Getting "copy-after" fields if applicable:
2753
					$copyAfterFields = $destPid<0 ? $this->fixCopyAfterDuplFields($table,$uid,abs($destPid),0) : array();
2753
							// Getting "copy-after" fields if applicable:
2754
						$copyAfterFields = $destPid<0 ? $this->fixCopyAfterDuplFields($table,$uid,abs($destPid),0) : array();
2754 2755

  
2755
						// Page TSconfig related:
2756
					$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...
2757
					$TSConfig = $this->getTCEMAIN_TSconfig($tscPID);
2758
					$tE = $this->getTableEntries($table,$TSConfig);
2756
							// Page TSconfig related:
2757
						$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...
2758
						$TSConfig = $this->getTCEMAIN_TSconfig($tscPID);
2759
						$tE = $this->getTableEntries($table,$TSConfig);
2759 2760

  
2760
						// Traverse ALL fields of the selected record:
2761
					foreach($row as $field => $value)	{
2762
						if (!in_array($field,$nonFields))	{
2761
							// Traverse ALL fields of the selected record:
2762
						foreach($row as $field => $value)	{
2763
							if (!in_array($field,$nonFields))	{
2763 2764

  
2764
								// Get TCA configuration for the field:
2765
							$conf = $TCA[$table]['columns'][$field]['config'];
2765
									// Get TCA configuration for the field:
2766
								$conf = $TCA[$table]['columns'][$field]['config'];
2766 2767

  
2767
								// Preparation/Processing of the value:
2768
							if ($field=='pid')	{	// "pid" is hardcoded of course:
2769
								$value = $destPid;
2770
							} elseif (isset($overrideValues[$field]))	{	// Override value...
2771
								$value = $overrideValues[$field];
2772
							} elseif (isset($copyAfterFields[$field]))	{	// Copy-after value if available:
2773
								$value = $copyAfterFields[$field];
2774
							} elseif ($TCA[$table]['ctrl']['setToDefaultOnCopy'] && t3lib_div::inList($TCA[$table]['ctrl']['setToDefaultOnCopy'],$field))	{	// Revert to default for some fields:
2775
								$value = $defaultData[$field];
2776
							} else {
2777
									// Hide at copy may override:
2778
								if ($first && $field==$enableField && $TCA[$table]['ctrl']['hideAtCopy'] && !$this->neverHideAtCopy && !$tE['disableHideAtCopy'])	{
2779
									$value=1;
2768
									// Preparation/Processing of the value:
2769
								if ($field=='pid')	{	// "pid" is hardcoded of course:
2770
									$value = $destPid;
2771
								} elseif (isset($overrideValues[$field]))	{	// Override value...
2772
									$value = $overrideValues[$field];
2773
								} elseif (isset($copyAfterFields[$field]))	{	// Copy-after value if available:
2774
									$value = $copyAfterFields[$field];
2775
								} elseif ($TCA[$table]['ctrl']['setToDefaultOnCopy'] && t3lib_div::inList($TCA[$table]['ctrl']['setToDefaultOnCopy'],$field))	{	// Revert to default for some fields:
2776
									$value = $defaultData[$field];
2777
								} else {
2778
										// Hide at copy may override:
2779
									if ($first && $field==$enableField && $TCA[$table]['ctrl']['hideAtCopy'] && !$this->neverHideAtCopy && !$tE['disableHideAtCopy'])	{
2780
										$value=1;
2781
									}
2782
										// Prepend label on copy:
2783
									if ($first && $field==$headerField && $TCA[$table]['ctrl']['prependAtCopy'] && !$tE['disablePrependAtCopy'])	{
2784
										$value = $this->getCopyHeader($table,$this->resolvePid($table,$destPid),$field,$this->clearPrefixFromValue($table,$value),0);
2785
									}
2786
										// Processing based on the TCA config field type (files, references, flexforms...)
2787
									$value = $this->copyRecord_procBasedOnFieldType($table, $uid, $field, $value, $row, $conf, $tscPID, $language);
2780 2788
								}
2781
									// Prepend label on copy:
2782
								if ($first && $field==$headerField && $TCA[$table]['ctrl']['prependAtCopy'] && !$tE['disablePrependAtCopy'])	{
2783
									$value = $this->getCopyHeader($table,$this->resolvePid($table,$destPid),$field,$this->clearPrefixFromValue($table,$value),0);
2784
								}
2785
									// Processing based on the TCA config field type (files, references, flexforms...)
2786
								$value = $this->copyRecord_procBasedOnFieldType($table, $uid, $field, $value, $row, $conf, $tscPID, $language);
2789

  
2790
									// Add value to array.
2791
								$data[$table][$theNewID][$field] = $value;
2787 2792
							}
2793
						}
2794
							// Overriding values:
2795
						if ($TCA[$table]['ctrl']['editlock'])	{
2796
							$data[$table][$theNewID][$TCA[$table]['ctrl']['editlock']] = 0;
2797
						}
2788 2798

  
2789
								// Add value to array.
2790
							$data[$table][$theNewID][$field] = $value;
2799
							// Setting original UID:
2800
						if ($TCA[$table]['ctrl']['origUid'])	{
2801
							$data[$table][$theNewID][$TCA[$table]['ctrl']['origUid']] = $uid;
2791 2802
						}
2792
					}
2793 2803

  
2794
						// Overriding values:
2795
					if ($TCA[$table]['ctrl']['editlock'])	{
2796
						$data[$table][$theNewID][$TCA[$table]['ctrl']['editlock']] = 0;
2797
					}
2804
							// Do the copy by simply submitting the array through TCEmain:
2805
						$copyTCE = t3lib_div::makeInstance('t3lib_TCEmain');
2806
						/* @var $copyTCE t3lib_TCEmain  */
2807
						$copyTCE->stripslashes_values = 0;
2808
						$copyTCE->copyTree = $this->copyTree;
2809
						$copyTCE->cachedTSconfig = $this->cachedTSconfig;	// Copy forth the cached TSconfig
2810
						$copyTCE->dontProcessTransformations=1;		// Transformations should NOT be carried out during copy
2798 2811

  
2799
						// Setting original UID:
2800
					if ($TCA[$table]['ctrl']['origUid'])	{
2801
						$data[$table][$theNewID][$TCA[$table]['ctrl']['origUid']] = $uid;
2802
					}
2812
						$copyTCE->start($data,'',$this->BE_USER);
2813
						$copyTCE->process_datamap();
2803 2814

  
2804
						// Do the copy by simply submitting the array through TCEmain:
2805
					$copyTCE = t3lib_div::makeInstance('t3lib_TCEmain');
2806
					/* @var $copyTCE t3lib_TCEmain  */
2807
					$copyTCE->stripslashes_values = 0;
2808
					$copyTCE->copyTree = $this->copyTree;
2809
					$copyTCE->cachedTSconfig = $this->cachedTSconfig;	// Copy forth the cached TSconfig
2810
					$copyTCE->dontProcessTransformations=1;		// Transformations should NOT be carried out during copy
2815
							// Getting the new UID:
2816
						$theNewSQLID = $copyTCE->substNEWwithIDs[$theNewID];
2817
						if ($theNewSQLID)	{
2818
							$this->copyRecord_fixRTEmagicImages($table,t3lib_BEfunc::wsMapId($table,$theNewSQLID));
2819
							$this->copyMappingArray[$table][$origUid] = $theNewSQLID;
2820
						}
2811 2821

  
2812
					$copyTCE->start($data,'',$this->BE_USER);
2813
					$copyTCE->process_datamap();
2822
							// Copy back the cached TSconfig
2823
						$this->cachedTSconfig = $copyTCE->cachedTSconfig;
2824
						$this->errorLog = array_merge($this->errorLog,$copyTCE->errorLog);
2825
						unset($copyTCE);
2814 2826

  
2815
						// Getting the new UID:
2816
					$theNewSQLID = $copyTCE->substNEWwithIDs[$theNewID];
2817
					if ($theNewSQLID)	{
2818
						$this->copyRecord_fixRTEmagicImages($table,t3lib_BEfunc::wsMapId($table,$theNewSQLID));
2819
						$this->copyMappingArray[$table][$origUid] = $theNewSQLID;
2820
					}
2827
						if($language == 0) {
2828
								//repointing the new translation records to the parent record we just created
2829
							$overrideValues[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']] = $theNewSQLID;
2830
							$this->copyL10nOverlayRecords($table, $uid, $destPid, $first, $overrideValues, $excludeFields='');
2831
						}
2821 2832

  
2822
						// Copy back the cached TSconfig
2823
					$this->cachedTSconfig = $copyTCE->cachedTSconfig;
2824
					$this->errorLog = array_merge($this->errorLog,$copyTCE->errorLog);
2825
					unset($copyTCE);
2826

  
2827
					return $theNewSQLID;
2828
				} else $this->log($table,$uid,3,0,1,'Attempt to copy record that did not exist!');
2833
						return $theNewSQLID;
2834
					} else $this->log($table,$uid,3,0,1,'Attempt to copy record that did not exist!');
2835
				}  else $this->log($table,$uid,3,0,1,'Attempt to copy record without having permissions to do so. ['.$this->BE_USER->errorMsg.'].');
2829 2836
			} else $this->log($table,$uid,3,0,1,'Attempt to copy record without permission');
2830 2837
		}
2831 2838
	}
......
3368 3375

  
3369 3376

  
3370 3377

  
3378
	/**
3379
	 * Find l10n-overlay records and perform the requested move action for these records.
3380
	 *
3381
	 * @param	string		$table: Record Table
3382
	 * @param	string		$uid: Record UID
3383
	 * @param	string		$destPid: Position to move to
3384
	 * @return	void
3385
	 */
3386
	function copyL10nOverlayRecords($table, $uid, $destPid, $first=0, $overrideValues=array(), $excludeFields='') {
3387
			//there's no need to perform this for page-records
3388
		if( $table == 'pages' ) return;
3389
		t3lib_div::loadTCA( $table );
3371 3390

  
3391
		$l10nRecords = t3lib_BEfunc::getRecordsByField( $table, $GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField'], $uid );
3392
		if( is_array($l10nRecords) ) {
3393
			foreach( $l10nRecords as $record ) {
3394
				$this->copyRecord($table, $record['uid'], $destPid, $first, $overrideValues, $excludeFields, $record[$GLOBALS['TCA'][$table]['ctrl']['languageField']]);
3395
			}
3396
		}
3397
	}
3372 3398

  
3373 3399

  
3374 3400