Пример #1
0
 /**
  * hook that is called when an element shall get deleted
  *
  * @param string $table the table of the record
  * @param int $id the ID of the record
  * @param array $record The accordant database record
  * @param bool $recordWasDeleted can be set so that other hooks or
  * @param DataHandler $tcemainObj reference to the main tcemain object
  * @return void
  */
 public function processCmdmap_deleteAction($table, $id, array $record, &$recordWasDeleted, DataHandler $tcemainObj)
 {
     // only process the hook if it wasn't processed
     // by someone else before
     if ($recordWasDeleted) {
         return;
     }
     $recordWasDeleted = TRUE;
     // For Live version, try if there is a workspace version because if so, rather "delete" that instead
     // Look, if record is an offline version, then delete directly:
     if ($record['pid'] != -1) {
         if ($wsVersion = BackendUtility::getWorkspaceVersionOfRecord($tcemainObj->BE_USER->workspace, $table, $id)) {
             $record = $wsVersion;
             $id = $record['uid'];
         }
     }
     $recordVersionState = VersionState::cast($record['t3ver_state']);
     // Look, if record is an offline version, then delete directly:
     if ($record['pid'] == -1) {
         if ($GLOBALS['TCA'][$table]['ctrl']['versioningWS']) {
             // In Live workspace, delete any. In other workspaces there must be match.
             if ($tcemainObj->BE_USER->workspace == 0 || (int) $record['t3ver_wsid'] == $tcemainObj->BE_USER->workspace) {
                 $liveRec = BackendUtility::getLiveVersionOfRecord($table, $id, 'uid,t3ver_state');
                 // Processing can be skipped if a delete placeholder shall be swapped/published
                 // during the current request. Thus it will be deleted later on...
                 $liveRecordVersionState = VersionState::cast($liveRec['t3ver_state']);
                 if ($recordVersionState->equals(VersionState::DELETE_PLACEHOLDER) && !empty($liveRec['uid']) && !empty($tcemainObj->cmdmap[$table][$liveRec['uid']]['version']['action']) && !empty($tcemainObj->cmdmap[$table][$liveRec['uid']]['version']['swapWith']) && $tcemainObj->cmdmap[$table][$liveRec['uid']]['version']['action'] === 'swap' && $tcemainObj->cmdmap[$table][$liveRec['uid']]['version']['swapWith'] == $id) {
                     return NULL;
                 }
                 if ($record['t3ver_wsid'] > 0 && $recordVersionState->equals(VersionState::DEFAULT_STATE)) {
                     // Change normal versioned record to delete placeholder
                     // Happens when an edited record is deleted
                     $updateFields = array('t3ver_label' => 'DELETED!', 't3ver_state' => 2);
                     $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, 'uid=' . $id, $updateFields);
                     // Delete localization overlays:
                     $tcemainObj->deleteL10nOverlayRecords($table, $id);
                 } elseif ($record['t3ver_wsid'] == 0 || !$liveRecordVersionState->indicatesPlaceholder()) {
                     // Delete those in WS 0 + if their live records state was not "Placeholder".
                     $tcemainObj->deleteEl($table, $id);
                 } else {
                     // If live record was placeholder (new/deleted), rather clear
                     // it from workspace (because it clears both version and placeholder).
                     $this->version_clearWSID($table, $id, FALSE, $tcemainObj);
                 }
             } else {
                 $tcemainObj->newlog('Tried to delete record from another workspace', 1);
             }
         } else {
             $tcemainObj->newlog('Versioning not enabled for record with PID = -1!', 2);
         }
     } elseif ($res = $tcemainObj->BE_USER->workspaceAllowLiveRecordsInPID($record['pid'], $table)) {
         // Look, if record is "online" or in a versionized branch, then delete directly.
         if ($res > 0) {
             $tcemainObj->deleteEl($table, $id);
         } else {
             $tcemainObj->newlog('Stage of root point did not allow for deletion', 1);
         }
     } elseif ($recordVersionState->equals(VersionState::MOVE_PLACEHOLDER)) {
         // Placeholders for moving operations are deletable directly.
         // Get record which its a placeholder for and reset the t3ver_state of that:
         if ($wsRec = BackendUtility::getWorkspaceVersionOfRecord($record['t3ver_wsid'], $table, $record['t3ver_move_id'], 'uid')) {
             // Clear the state flag of the workspace version of the record
             // Setting placeholder state value for version (so it can know it is currently a new version...)
             $updateFields = array('t3ver_state' => (string) new VersionState(VersionState::DEFAULT_STATE));
             $GLOBALS['TYPO3_DB']->exec_UPDATEquery($table, 'uid=' . (int) $wsRec['uid'], $updateFields);
         }
         $tcemainObj->deleteEl($table, $id);
     } else {
         // Otherwise, try to delete by versioning:
         $copyMappingArray = $tcemainObj->copyMappingArray;
         $tcemainObj->versionizeRecord($table, $id, 'DELETED!', TRUE);
         // Determine newly created versions:
         // (remove placeholders are copied and modified, thus they appear in the copyMappingArray)
         $versionizedElements = ArrayUtility::arrayDiffAssocRecursive($tcemainObj->copyMappingArray, $copyMappingArray);
         // Delete localization overlays:
         foreach ($versionizedElements as $versionizedTableName => $versionizedOriginalIds) {
             foreach ($versionizedOriginalIds as $versionizedOriginalId => $_) {
                 $tcemainObj->deleteL10nOverlayRecords($versionizedTableName, $versionizedOriginalId);
             }
         }
     }
 }