示例#1
0
 /**
  * Creates a new version of a page including content and possible subpages.
  *
  * @param int $uid Page uid to create new version of.
  * @param string $label Version label
  * @param int $versionizeTree Indicating "treeLevel" - "page" (0) or "branch" (>=1) ["element" type must call versionizeRecord() directly]
  * @param DataHandler $tcemainObj TCEmain object
  * @return void
  * @see copyPages()
  */
 protected function versionizePages($uid, $label, $versionizeTree, DataHandler $tcemainObj)
 {
     $uid = (int) $uid;
     // returns the branch
     $brExist = $tcemainObj->doesBranchExist('', $uid, $tcemainObj->pMap['show'], 1);
     // Checks if we had permissions
     if ((int) $brExist === -1) {
         $tcemainObj->newlog('Could not read all subpages to versionize.', 1);
         return;
     }
     // Make list of tables that should come along with a new version of the page:
     $verTablesArray = array();
     $allTables = array_keys($GLOBALS['TCA']);
     foreach ($allTables as $tableName) {
         if ($tableName != 'pages' && ($versionizeTree > 0 || $GLOBALS['TCA'][$tableName]['ctrl']['versioning_followPages'])) {
             $verTablesArray[] = $tableName;
         }
     }
     // Remove the possible inline child tables from the tables to be versioniozed automatically:
     $verTablesArray = array_diff($verTablesArray, $this->getPossibleInlineChildTablesOfParentTable('pages'));
     // Begin to copy pages if we're allowed to:
     if ($versionizeTree !== -1) {
         $tcemainObj->newlog('Versioning type "' . $versionizeTree . '" was not allowed in workspace', 1);
         return;
     }
     // Versionize this page:
     $theNewRootID = $tcemainObj->versionizeRecord('pages', $uid, $label, FALSE, $versionizeTree);
     if (!$theNewRootID) {
         $tcemainObj->newlog('The root version could not be created!', 1);
         return;
     }
     $this->rawCopyPageContent($uid, $theNewRootID, $verTablesArray, $tcemainObj);
     // If we're going to copy recursively...:
     if ($versionizeTree > 0) {
         // Get ALL subpages to copy (read permissions respected - they should NOT be...):
         $CPtable = $tcemainObj->int_pageTreeInfo(array(), $uid, (int) $versionizeTree, $theNewRootID);
         // Now copying the subpages
         foreach ($CPtable as $thePageUid => $thePagePid) {
             $newPid = $tcemainObj->copyMappingArray['pages'][$thePagePid];
             if (isset($newPid)) {
                 $theNewRootID = $tcemainObj->copyRecord_raw('pages', $thePageUid, $newPid);
                 $this->rawCopyPageContent($thePageUid, $theNewRootID, $verTablesArray, $tcemainObj);
             } else {
                 $tcemainObj->newlog('Something went wrong during copying branch (for versioning)', 1);
                 break;
             }
         }
     }
 }