Esempio n. 1
0
 /**
  * Creates a move placeholder for workspaces.
  * USE ONLY INTERNALLY
  * Moving placeholder: Can be done because the system sees it as a placeholder for NEW elements like t3ver_state=VersionState::NEW_PLACEHOLDER
  * Moving original: Will either create the placeholder if it doesn't exist or move existing placeholder in workspace.
  *
  * @param string $table Table name to move
  * @param int $uid Record uid to move (online record)
  * @param int $destPid Position to move to: $destPid: >=0 then it points to a page-id on which to insert the record (as the first element). <0 then it points to a uid from its own table after which to insert it (works if
  * @param int $wsUid UID of offline version of online record
  * @param DataHandler $tcemainObj TCEmain object
  * @return void
  * @see moveRecord()
  */
 protected function moveRecord_wsPlaceholders($table, $uid, $destPid, $wsUid, DataHandler $tcemainObj)
 {
     // If a record gets moved after a record that already has a placeholder record
     // then the new placeholder record needs to be after the existing one
     $originalRecordDestinationPid = $destPid;
     if ($destPid < 0) {
         $movePlaceHolder = BackendUtility::getMovePlaceholder($table, abs($destPid), 'uid');
         if ($movePlaceHolder !== FALSE) {
             $destPid = -$movePlaceHolder['uid'];
         }
     }
     if ($plh = BackendUtility::getMovePlaceholder($table, $uid, 'uid')) {
         // If already a placeholder exists, move it:
         $tcemainObj->moveRecord_raw($table, $plh['uid'], $destPid);
     } else {
         // First, we create a placeholder record in the Live workspace that
         // represents the position to where the record is eventually moved to.
         $newVersion_placeholderFieldArray = array();
         // Use property for move placeholders if set (since TYPO3 CMS 6.2)
         if (isset($GLOBALS['TCA'][$table]['ctrl']['shadowColumnsForMovePlaceholders'])) {
             $shadowColumnsForMovePlaceholder = $GLOBALS['TCA'][$table]['ctrl']['shadowColumnsForMovePlaceholders'];
             // Fallback to property for new placeholder (existed long time before TYPO3 CMS 6.2)
         } elseif (isset($GLOBALS['TCA'][$table]['ctrl']['shadowColumnsForNewPlaceholders'])) {
             $shadowColumnsForMovePlaceholder = $GLOBALS['TCA'][$table]['ctrl']['shadowColumnsForNewPlaceholders'];
         }
         // Set values from the versioned record to the move placeholder
         if (!empty($shadowColumnsForMovePlaceholder)) {
             $versionedRecord = BackendUtility::getRecord($table, $wsUid);
             $shadowColumns = GeneralUtility::trimExplode(',', $shadowColumnsForMovePlaceholder, TRUE);
             foreach ($shadowColumns as $shadowColumn) {
                 if (isset($versionedRecord[$shadowColumn])) {
                     $newVersion_placeholderFieldArray[$shadowColumn] = $versionedRecord[$shadowColumn];
                 }
             }
         }
         if ($GLOBALS['TCA'][$table]['ctrl']['crdate']) {
             $newVersion_placeholderFieldArray[$GLOBALS['TCA'][$table]['ctrl']['crdate']] = $GLOBALS['EXEC_TIME'];
         }
         if ($GLOBALS['TCA'][$table]['ctrl']['cruser_id']) {
             $newVersion_placeholderFieldArray[$GLOBALS['TCA'][$table]['ctrl']['cruser_id']] = $tcemainObj->userid;
         }
         if ($GLOBALS['TCA'][$table]['ctrl']['tstamp']) {
             $newVersion_placeholderFieldArray[$GLOBALS['TCA'][$table]['ctrl']['tstamp']] = $GLOBALS['EXEC_TIME'];
         }
         if ($table == 'pages') {
             // Copy page access settings from original page to placeholder
             $perms_clause = $tcemainObj->BE_USER->getPagePermsClause(1);
             $access = BackendUtility::readPageAccess($uid, $perms_clause);
             $newVersion_placeholderFieldArray['perms_userid'] = $access['perms_userid'];
             $newVersion_placeholderFieldArray['perms_groupid'] = $access['perms_groupid'];
             $newVersion_placeholderFieldArray['perms_user'] = $access['perms_user'];
             $newVersion_placeholderFieldArray['perms_group'] = $access['perms_group'];
             $newVersion_placeholderFieldArray['perms_everybody'] = $access['perms_everybody'];
         }
         $newVersion_placeholderFieldArray['t3ver_label'] = 'MovePlaceholder #' . $uid;
         $newVersion_placeholderFieldArray['t3ver_move_id'] = $uid;
         // Setting placeholder state value for temporary record
         $newVersion_placeholderFieldArray['t3ver_state'] = (string) new VersionState(VersionState::MOVE_PLACEHOLDER);
         // Setting workspace - only so display of place holders can filter out those from other workspaces.
         $newVersion_placeholderFieldArray['t3ver_wsid'] = $tcemainObj->BE_USER->workspace;
         $newVersion_placeholderFieldArray[$GLOBALS['TCA'][$table]['ctrl']['label']] = '[MOVE-TO PLACEHOLDER for #' . $uid . ', WS#' . $tcemainObj->BE_USER->workspace . ']';
         // moving localized records requires to keep localization-settings for the placeholder too
         if (array_key_exists('languageField', $GLOBALS['TCA'][$table]['ctrl']) && array_key_exists('transOrigPointerField', $GLOBALS['TCA'][$table]['ctrl'])) {
             $l10nParentRec = BackendUtility::getRecord($table, $uid);
             $newVersion_placeholderFieldArray[$GLOBALS['TCA'][$table]['ctrl']['languageField']] = $l10nParentRec[$GLOBALS['TCA'][$table]['ctrl']['languageField']];
             $newVersion_placeholderFieldArray[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']] = $l10nParentRec[$GLOBALS['TCA'][$table]['ctrl']['transOrigPointerField']];
             unset($l10nParentRec);
         }
         // Initially, create at root level.
         $newVersion_placeholderFieldArray['pid'] = 0;
         $id = 'NEW_MOVE_PLH';
         // Saving placeholder as 'original'
         $tcemainObj->insertDB($table, $id, $newVersion_placeholderFieldArray, FALSE);
         // Move the new placeholder from temporary root-level to location:
         $tcemainObj->moveRecord_raw($table, $tcemainObj->substNEWwithIDs[$id], $destPid);
         // Move the workspace-version of the original to be the version of the move-to-placeholder:
         // Setting placeholder state value for version (so it can know it is currently a new version...)
         $updateFields = array('t3ver_state' => (string) new VersionState(VersionState::MOVE_POINTER));
         $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, 'uid=' . (int) $wsUid, $updateFields);
     }
     // Check for the localizations of that element and move them as well
     $tcemainObj->moveL10nOverlayRecords($table, $uid, $destPid, $originalRecordDestinationPid);
 }