‪TYPO3CMS  ‪main
RecyclerUtility.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
18 use TYPO3\CMS\Backend\Utility\BackendUtility;
25 
31 {
32  /************************************************************
33  * USER ACCESS
34  *
35  *
36  ************************************************************/
45  public static function ‪checkAccess($table, $row)
46  {
47  $backendUser = static::getBackendUser();
48 
49  if ($backendUser->isAdmin()) {
50  return true;
51  }
52 
53  if (!$backendUser->check('tables_modify', $table)) {
54  return false;
55  }
56 
57  // Checking if the user has permissions? (Only working as a precaution, because the final permission check is always down in TCE. But it's good to notify the user on beforehand...)
58  // First, resetting flags.
59  $hasAccess = false;
60  $calcPRec = $row;
61  BackendUtility::workspaceOL($table, $calcPRec, $backendUser->workspace);
62  if (is_array($calcPRec)) {
63  if ($table === 'pages') {
64  $calculatedPermissions = new ‪Permission($backendUser->calcPerms($calcPRec));
65  $hasAccess = $calculatedPermissions->editPagePermissionIsGranted();
66  } else {
67  $calculatedPermissions = new ‪Permission($backendUser->calcPerms(BackendUtility::getRecord('pages', $calcPRec['pid'])));
68  // Fetching pid-record first.
69  $hasAccess = $calculatedPermissions->editContentPermissionIsGranted();
70  }
71  // Check internals regarding access:
72  if ($hasAccess) {
73  $hasAccess = $backendUser->recordEditAccessInternals($table, $calcPRec);
74  }
75  }
76  return $hasAccess;
77  }
78 
85  public static function ‪getDeletedField($tableName): string
86  {
87  $tcaForTable = ‪self::getTableTCA((string)$tableName);
88  if ($tcaForTable && isset($tcaForTable['ctrl']['delete']) && !empty($tcaForTable['ctrl']['delete'])) {
89  return $tcaForTable['ctrl']['delete'];
90  }
91  return '';
92  }
93 
101  public static function ‪getPidOfUid(‪$uid, $table)
102  {
103  $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable($table);
104  $queryBuilder->getRestrictions()->removeAll();
105 
106  $pid = $queryBuilder
107  ->select('pid')
108  ->from($table)
109  ->where($queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter(‪$uid, ‪Connection::PARAM_INT)))
110  ->executeQuery()
111  ->fetchOne();
112 
113  return (int)$pid;
114  }
115 
122  protected static function ‪getTableTCA(string $tableName): array|false
123  {
124  $TCA = false;
125  if (isset(‪$GLOBALS['TCA'][$tableName])) {
126  $TCA = ‪$GLOBALS['TCA'][$tableName];
127  }
128  return $TCA;
129  }
130 
131  protected static function ‪getBackendUser(): ‪BackendUserAuthentication
132  {
133  return ‪$GLOBALS['BE_USER'];
134  }
135 
136  protected static function ‪getLanguageService(): ‪LanguageService
137  {
138  return ‪$GLOBALS['LANG'];
139  }
140 
144  public static function ‪getModifyableTables(): array
145  {
146  if (self::getBackendUser()->isAdmin()) {
147  $tables = array_keys(‪$GLOBALS['TCA']);
148  } else {
149  $tables = explode(',', ‪$GLOBALS['BE_USER']->groupData['tables_modify']);
150  }
151  return $tables;
152  }
153 }
‪TYPO3\CMS\Core\Database\Connection\PARAM_INT
‪const PARAM_INT
Definition: Connection.php:52
‪TYPO3\CMS\Core\Type\Bitmask\Permission
Definition: Permission.php:26
‪TYPO3\CMS\Recycler\Utility\RecyclerUtility\getDeletedField
‪static string getDeletedField($tableName)
Definition: RecyclerUtility.php:85
‪TYPO3\CMS\Recycler\Utility\RecyclerUtility\getModifyableTables
‪static getModifyableTables()
Definition: RecyclerUtility.php:144
‪TYPO3\CMS\Recycler\Utility\RecyclerUtility\getPidOfUid
‪static int getPidOfUid($uid, $table)
Definition: RecyclerUtility.php:101
‪TYPO3\CMS\Core\Authentication\BackendUserAuthentication
Definition: BackendUserAuthentication.php:61
‪TYPO3\CMS\Core\Database\Connection
Definition: Connection.php:41
‪TYPO3\CMS\Recycler\Utility\RecyclerUtility\checkAccess
‪static bool checkAccess($table, $row)
Definition: RecyclerUtility.php:45
‪TYPO3\CMS\Webhooks\Message\$uid
‪identifier readonly int $uid
Definition: PageModificationMessage.php:35
‪TYPO3\CMS\Recycler\Utility\RecyclerUtility\getBackendUser
‪static getBackendUser()
Definition: RecyclerUtility.php:131
‪TYPO3\CMS\Recycler\Utility\RecyclerUtility\getTableTCA
‪static array false getTableTCA(string $tableName)
Definition: RecyclerUtility.php:122
‪TYPO3\CMS\Recycler\Utility\RecyclerUtility
Definition: RecyclerUtility.php:31
‪$GLOBALS
‪$GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['adminpanel']['modules']
Definition: ext_localconf.php:25
‪TYPO3\CMS\Core\Localization\LanguageService
Definition: LanguageService.php:46
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Recycler\Utility
Definition: RecyclerUtility.php:16
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Recycler\Utility\RecyclerUtility\getLanguageService
‪static getLanguageService()
Definition: RecyclerUtility.php:136