‪TYPO3CMS  10.4
MigratePagesLanguageOverlayBeGroupsAccessRights.php
Go to the documentation of this file.
1 <?php
2 
3 declare(strict_types=1);
4 
5 /*
6  * This file is part of the TYPO3 CMS project.
7  *
8  * It is free software; you can redistribute it and/or modify it under
9  * the terms of the GNU General Public License, either version 2
10  * of the License, or any later version.
11  *
12  * For the full copyright and license information, please read the
13  * LICENSE.txt file that was distributed with this source code.
14  *
15  * The TYPO3 project - inspiring people to share!
16  */
17 
19 
23 
30 {
31  public function ‪getIdentifier(): string
32  {
33  return 'pagesLanguageOverlayBeGroupsAccessRights';
34  }
35 
36  public function ‪getTitle(): string
37  {
38  return 'Merge be_groups access rights from pages_language_overlay to pages';
39  }
40 
41  public function ‪executeUpdate(): bool
42  {
43  $beGroupsQueryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable(
44  'be_groups'
45  );
46  $beGroupsQueryBuilder->getRestrictions()->removeAll();
47  $beGroupsRows = $beGroupsQueryBuilder
48  ->select('uid', 'non_exclude_fields', 'tables_modify')
49  ->from('be_groups')
50  ->execute();
51  while ($beGroupsRow = $beGroupsRows->fetch()) {
52  $updateNeeded = false;
53  if (!empty($beGroupsRow['tables_modify'])) {
54  // If 'pages_language_overlay' is allowed as table-modify, remove it and add
55  // 'pages' if it is not in there, yet.
56  $tablesArray = ‪GeneralUtility::trimExplode(',', $beGroupsRow['tables_modify'], true);
57  $newTablesArray = $tablesArray;
58  if (in_array('pages_language_overlay', $tablesArray, true)) {
59  $updateNeeded = true;
60  $newTablesArray = array_diff($tablesArray, ['pages_language_overlay']);
61  if (!in_array('pages', $newTablesArray, true)) {
62  $newTablesArray[] = 'pages';
63  }
64  }
65  } else {
66  $newTablesArray = [];
67  }
68  if (!empty($beGroupsRow['non_exclude_fields'])) {
69  // Exclude fields on 'pages_language_overlay' are removed and added as
70  // exclude fields on 'pages'
71  $excludeFields = ‪GeneralUtility::trimExplode(',', $beGroupsRow['non_exclude_fields'], true);
72  $newExcludeFields = [];
73  foreach ($excludeFields as $tableFieldCombo) {
74  if (strpos($tableFieldCombo, 'pages_language_overlay:') === 0) {
75  $updateNeeded = true;
76  $field = substr($tableFieldCombo, strlen('pages_language_overlay:'));
77  $newExcludeFields[] = 'pages:' . $field;
78  } else {
79  $newExcludeFields[] = $tableFieldCombo;
80  }
81  }
82  array_unique($newExcludeFields);
83  } else {
84  $newExcludeFields = [];
85  }
86  if ($updateNeeded) {
87  $updateBeGroupsQueryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
88  ->getQueryBuilderForTable('be_groups');
89  $updateBeGroupsQueryBuilder
90  ->update('be_groups')
91  ->set('tables_modify', implode(',', $newTablesArray))
92  ->set('non_exclude_fields', implode(',', $newExcludeFields))
93  ->where(
94  $updateBeGroupsQueryBuilder->expr()->eq(
95  'uid',
96  $updateBeGroupsQueryBuilder->createNamedParameter($beGroupsRow['uid'], \PDO::PARAM_INT)
97  )
98  )
99  ->execute();
100  }
101  }
102  return true;
103  }
104 
108  public function ‪updateNecessary(): bool
109  {
110  return !(new ‪UpgradeWizardsService())->isWizardDone($this->‪getIdentifier());
111  }
112 
116  public function ‪getPrerequisites(): array
117  {
118  return [
119  DatabaseUpdatedPrerequisite::class
120  ];
121  }
122 
123  public function ‪getDescription(): string
124  {
125  return 'The table pages_language_overlay will be removed to align the translation ' .
126  'handling for pages with the rest of the core. This wizard transfers all be_groups with ' .
127  'access restrictions to pages_language_overlay into pages.';
128  }
129 
134  {
135  return GeneralUtility::makeInstance(
136  Confirmation::class,
137  'Are you sure?',
138  'Do you want to continue?',
139  false
140  );
141  }
142 }
‪TYPO3\CMS\Install\Updates\MigratePagesLanguageOverlayBeGroupsAccessRights\executeUpdate
‪executeUpdate()
Definition: MigratePagesLanguageOverlayBeGroupsAccessRights.php:41
‪TYPO3\CMS\Install\Updates\MigratePagesLanguageOverlayBeGroupsAccessRights
Definition: MigratePagesLanguageOverlayBeGroupsAccessRights.php:30
‪TYPO3\CMS\Install\Updates\MigratePagesLanguageOverlayBeGroupsAccessRights\getIdentifier
‪getIdentifier()
Definition: MigratePagesLanguageOverlayBeGroupsAccessRights.php:31
‪TYPO3\CMS\Install\Service\UpgradeWizardsService
Definition: UpgradeWizardsService.php:43
‪TYPO3\CMS\Install\Updates
Definition: AbstractDownloadExtensionUpdate.php:16
‪TYPO3\CMS\Install\Updates\MigratePagesLanguageOverlayBeGroupsAccessRights\getTitle
‪getTitle()
Definition: MigratePagesLanguageOverlayBeGroupsAccessRights.php:36
‪TYPO3\CMS\Install\Updates\MigratePagesLanguageOverlayBeGroupsAccessRights\getPrerequisites
‪string[] getPrerequisites()
Definition: MigratePagesLanguageOverlayBeGroupsAccessRights.php:116
‪TYPO3\CMS\Install\Updates\Confirmation
Definition: Confirmation.php:21
‪TYPO3\CMS\Core\Utility\GeneralUtility\trimExplode
‪static string[] trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
Definition: GeneralUtility.php:1059
‪TYPO3\CMS\Install\Updates\UpgradeWizardInterface
Definition: UpgradeWizardInterface.php:24
‪TYPO3\CMS\Install\Updates\MigratePagesLanguageOverlayBeGroupsAccessRights\updateNecessary
‪bool updateNecessary()
Definition: MigratePagesLanguageOverlayBeGroupsAccessRights.php:108
‪TYPO3\CMS\Install\Updates\MigratePagesLanguageOverlayBeGroupsAccessRights\getConfirmation
‪Confirmation getConfirmation()
Definition: MigratePagesLanguageOverlayBeGroupsAccessRights.php:133
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Install\Updates\ConfirmableInterface
Definition: ConfirmableInterface.php:24
‪TYPO3\CMS\Install\Updates\MigratePagesLanguageOverlayBeGroupsAccessRights\getDescription
‪getDescription()
Definition: MigratePagesLanguageOverlayBeGroupsAccessRights.php:123