TYPO3 CMS  TYPO3_8-7
MigrateShortcutUrlsAgainUpdate.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 
19 
24 {
28  protected $title = 'Migrate backend shortcut urls';
29 
36  public function checkForUpdate(&$description)
37  {
38  if ($this->isWizardDone()) {
39  return false;
40  }
41  $shortcutsCount = GeneralUtility::makeInstance(ConnectionPool::class)
42  ->getConnectionForTable('sys_be_shortcuts')
43  ->count('uid', 'sys_be_shortcuts', []);
44  if ($shortcutsCount > 0) {
45  $description = 'Migrate old shortcut urls to the new module urls.';
46  }
47  return (bool)$shortcutsCount;
48  }
49 
57  public function performUpdate(array &$databaseQueries, &$customMessage)
58  {
59  $connection = GeneralUtility::makeInstance(ConnectionPool::class)->getConnectionForTable('sys_be_shortcuts');
60  $statement = $connection->select(['uid', 'url'], 'sys_be_shortcuts', []);
61  while ($shortcut = $statement->fetch()) {
62  $decodedUrl = urldecode($shortcut['url']);
63  $encodedUrl = str_replace(
64  [
65  '/typo3/sysext/cms/layout/db_layout.php?&',
66  '/typo3/sysext/cms/layout/db_layout.php?',
67  '/typo3/file_edit.php?&',
68  // From 7.2 to 7.4
69  'mod.php',
70  ],
71  [
72  '/typo3/index.php?&M=web_layout&',
73  urlencode('/typo3/index.php?&M=web_layout&'),
74  '/typo3/index.php?&M=file_edit&',
75  // From 7.2 to 7.4
76  'index.php',
77  ],
78  $decodedUrl
79  );
80  $queryBuilder = $connection->createQueryBuilder();
81  $queryBuilder->update('sys_be_shortcuts')
82  ->set('url', $encodedUrl)
83  ->where(
84  $queryBuilder->expr()->eq(
85  'uid',
86  $queryBuilder->createNamedParameter($shortcut['uid'], \PDO::PARAM_INT)
87  )
88  );
89  $databaseQueries[] = $queryBuilder->getSQL();
90  $queryBuilder->execute();
91  }
92  $this->markWizardAsDone();
93  return true;
94  }
95 }
static makeInstance($className,... $constructorArguments)