TYPO3 CMS  TYPO3_8-7
DataHandlerHook.php
Go to the documentation of this file.
1 <?php
3 
4 /*
5  * This file is part of the TYPO3 CMS project.
6  *
7  * It is free software; you can redistribute it and/or modify it under
8  * the terms of the GNU General Public License, either version 2
9  * of the License, or any later version.
10  *
11  * For the full copyright and license information, please read the
12  * LICENSE.txt file that was distributed with this source code.
13  *
14  * The TYPO3 project - inspiring people to share!
15  */
16 
23 
28 {
40  public function processCmdmap_postProcess($command, $table, $id, $value, \TYPO3\CMS\Core\DataHandling\DataHandler $dataHandler)
41  {
42  if ($command === 'delete') {
43  if ($table === StagesService::TABLE_STAGE) {
44  $this->resetStageOfElements($id);
45  } elseif ($table === \TYPO3\CMS\Workspaces\Service\WorkspaceService::TABLE_WORKSPACE) {
46  $this->flushWorkspaceElements($id);
47  }
48  }
49  }
50 
57  public function processCmdmap_afterFinish(\TYPO3\CMS\Core\DataHandling\DataHandler $dataHandler)
58  {
59  $this->flushWorkspaceCacheEntriesByWorkspaceId($dataHandler->BE_USER->workspace);
60  }
61 
69  protected function resetStageOfElements($stageId)
70  {
71  foreach ($this->getTcaTables() as $tcaTable) {
73  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
74  ->getQueryBuilderForTable($tcaTable);
75 
76  $queryBuilder
77  ->update($tcaTable)
78  ->set('t3ver_stage', StagesService::STAGE_EDIT_ID)
79  ->where(
80  $queryBuilder->expr()->eq(
81  't3ver_stage',
82  $queryBuilder->createNamedParameter($stageId, \PDO::PARAM_INT)
83  ),
84  $queryBuilder->expr()->eq(
85  'pid',
86  $queryBuilder->createNamedParameter(-1, \PDO::PARAM_INT)
87  ),
88  $queryBuilder->expr()->gt(
89  't3ver_wsid',
90  $queryBuilder->createNamedParameter(0, \PDO::PARAM_INT)
91  )
92  )
93  ->execute();
94  }
95  }
96  }
97 
103  protected function flushWorkspaceElements($workspaceId)
104  {
105  $command = [];
106  foreach ($this->getTcaTables() as $tcaTable) {
108  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
109  ->getQueryBuilderForTable($tcaTable);
110  $queryBuilder->getRestrictions()
111  ->removeAll()
112  ->add(GeneralUtility::makeInstance(DeletedRestriction::class))
113  ->add(GeneralUtility::makeInstance(BackendWorkspaceRestriction::class, $workspaceId, false));
114 
115  $result = $queryBuilder
116  ->select('uid')
117  ->from($tcaTable)
118  ->orderBy('uid')
119  ->execute();
120 
121  while (($recordId = $result->fetchColumn()) !== false) {
122  $command[$tcaTable][$recordId]['version']['action'] = 'flush';
123  }
124  }
125  }
126  if (!empty($command)) {
127  $dataHandler = $this->getDataHandler();
128  $dataHandler->start([], $command);
129  $dataHandler->process_cmdmap();
130  }
131  }
132 
138  protected function getTcaTables()
139  {
140  return array_keys($GLOBALS['TCA']);
141  }
142 
146  protected function getDataHandler()
147  {
148  return \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\DataHandling\DataHandler::class);
149  }
150 
156  protected function flushWorkspaceCacheEntriesByWorkspaceId($workspaceId)
157  {
158  $workspacesCache = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance(\TYPO3\CMS\Core\Cache\CacheManager::class)->getCache('workspaces_cache');
159  $workspacesCache->flushByTag($workspaceId);
160  $workspacesCache->flushByTag(\TYPO3\CMS\Workspaces\Service\WorkspaceService::SELECT_ALL_WORKSPACES);
161  }
162 }
processCmdmap_afterFinish(\TYPO3\CMS\Core\DataHandling\DataHandler $dataHandler)
static makeInstance($className,... $constructorArguments)
processCmdmap_postProcess($command, $table, $id, $value, \TYPO3\CMS\Core\DataHandling\DataHandler $dataHandler)
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']