‪TYPO3CMS  9.5
MigratePagesLanguageOverlayBeGroupsAccessRights.php
Go to the documentation of this file.
1 <?php
2 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 
21 
28 {
29  public function ‪getIdentifier(): string
30  {
31  return 'pagesLanguageOverlayBeGroupsAccessRights';
32  }
33 
34  public function ‪getTitle(): string
35  {
36  return 'Merge be_groups access rights from pages_language_overlay to pages';
37  }
38 
39  public function ‪executeUpdate(): bool
40  {
41  $beGroupsQueryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable(
42  'be_groups'
43  );
44  $beGroupsQueryBuilder->getRestrictions()->removeAll();
45  $beGroupsRows = $beGroupsQueryBuilder
46  ->select('uid', 'non_exclude_fields', 'tables_modify')
47  ->from('be_groups')
48  ->execute();
49  while ($beGroupsRow = $beGroupsRows->fetch()) {
50  $updateNeeded = false;
51  if (!empty($beGroupsRow['tables_modify'])) {
52  // If 'pages_language_overlay' is allowed as table-modify, remove it and add
53  // 'pages' if it is not in there, yet.
54  $tablesArray = GeneralUtility::trimExplode(',', $beGroupsRow['tables_modify'], true);
55  $newTablesArray = $tablesArray;
56  if (in_array('pages_language_overlay', $tablesArray, true)) {
57  $updateNeeded = true;
58  $newTablesArray = array_diff($tablesArray, ['pages_language_overlay']);
59  if (!in_array('pages', $newTablesArray, true)) {
60  $newTablesArray[] = 'pages';
61  }
62  }
63  } else {
64  $newTablesArray = [];
65  }
66  if (!empty($beGroupsRow['non_exclude_fields'])) {
67  // Exclude fields on 'pages_language_overlay' are removed and added as
68  // exclude fields on 'pages'
69  $excludeFields = GeneralUtility::trimExplode(',', $beGroupsRow['non_exclude_fields'], true);
70  $newExcludeFields = [];
71  foreach ($excludeFields as $tableFieldCombo) {
72  if (strpos($tableFieldCombo, 'pages_language_overlay:') === 0) {
73  $updateNeeded = true;
74  $field = substr($tableFieldCombo, strlen('pages_language_overlay:'));
75  $newExcludeFields[] = 'pages:' . $field;
76  } else {
77  $newExcludeFields[] = $tableFieldCombo;
78  }
79  }
80  array_unique($newExcludeFields);
81  } else {
82  $newExcludeFields = [];
83  }
84  if ($updateNeeded) {
85  $updateBeGroupsQueryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)
86  ->getQueryBuilderForTable('be_groups');
87  $updateBeGroupsQueryBuilder
88  ->update('be_groups')
89  ->set('tables_modify', implode(',', $newTablesArray))
90  ->set('non_exclude_fields', implode(',', $newExcludeFields))
91  ->where(
92  $updateBeGroupsQueryBuilder->expr()->eq(
93  'uid',
94  $updateBeGroupsQueryBuilder->createNamedParameter($beGroupsRow['uid'], \PDO::PARAM_INT)
95  )
96  )
97  ->execute();
98  }
99  }
100  return true;
101  }
102 
106  public function ‪updateNecessary(): bool
107  {
108  return !(new ‪UpgradeWizardsService())->isWizardDone($this->‪getIdentifier());
109  }
110 
114  public function ‪getPrerequisites(): array
115  {
116  return [
117  DatabaseUpdatedPrerequisite::class
118  ];
119  }
120 
121  public function ‪getDescription(): string
122  {
123  return 'The table pages_language_overlay will be removed to align the translation ' .
124  'handling for pages with the rest of the core. This wizard transfers all be_groups with ' .
125  'access restrictions to pages_language_overlay into pages.';
126  }
127 
132  {
133  return GeneralUtility::makeInstance(
134  Confirmation::class,
135  'Are you sure?',
136  'Do you want to continue?',
137  false
138  );
139  }
140 }
‪TYPO3\CMS\Install\Updates\MigratePagesLanguageOverlayBeGroupsAccessRights\executeUpdate
‪executeUpdate()
Definition: MigratePagesLanguageOverlayBeGroupsAccessRights.php:39
‪TYPO3\CMS\Install\Updates\MigratePagesLanguageOverlayBeGroupsAccessRights
Definition: MigratePagesLanguageOverlayBeGroupsAccessRights.php:28
‪TYPO3\CMS\Install\Updates\MigratePagesLanguageOverlayBeGroupsAccessRights\getIdentifier
‪getIdentifier()
Definition: MigratePagesLanguageOverlayBeGroupsAccessRights.php:29
‪TYPO3\CMS\Install\Service\UpgradeWizardsService
Definition: UpgradeWizardsService.php:42
‪TYPO3\CMS\Install\Updates
Definition: AbstractDownloadExtensionUpdate.php:3
‪TYPO3\CMS\Install\Updates\MigratePagesLanguageOverlayBeGroupsAccessRights\getTitle
‪getTitle()
Definition: MigratePagesLanguageOverlayBeGroupsAccessRights.php:34
‪TYPO3\CMS\Install\Updates\MigratePagesLanguageOverlayBeGroupsAccessRights\getPrerequisites
‪string[] getPrerequisites()
Definition: MigratePagesLanguageOverlayBeGroupsAccessRights.php:114
‪TYPO3\CMS\Install\Updates\Confirmation
Definition: Confirmation.php:20
‪TYPO3\CMS\Install\Updates\UpgradeWizardInterface
Definition: UpgradeWizardInterface.php:22
‪TYPO3\CMS\Install\Updates\MigratePagesLanguageOverlayBeGroupsAccessRights\updateNecessary
‪bool updateNecessary()
Definition: MigratePagesLanguageOverlayBeGroupsAccessRights.php:106
‪TYPO3\CMS\Install\Updates\MigratePagesLanguageOverlayBeGroupsAccessRights\getConfirmation
‪Confirmation getConfirmation()
Definition: MigratePagesLanguageOverlayBeGroupsAccessRights.php:131
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Install\Updates\ConfirmableInterface
Definition: ConfirmableInterface.php:23
‪TYPO3\CMS\Install\Updates\MigratePagesLanguageOverlayBeGroupsAccessRights\getDescription
‪getDescription()
Definition: MigratePagesLanguageOverlayBeGroupsAccessRights.php:121