‪TYPO3CMS  ‪main
PagesRecyclerDoktypeMigration.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 
22 use TYPO3\CMS\Core\Database\Query\QueryBuilder;
26 
31 #[UpgradeWizard('pagesRecyclerDoktypeMigration')]
33 {
34  protected const ‪TABLE_NAME = 'pages';
35 
36  public function ‪getTitle(): string
37  {
38  return 'Migrate pages of doktype 255 ("Recycler") to a Backend User Section doktype.';
39  }
40 
41  public function ‪getDescription(): string
42  {
43  return 'The Recycler doktype of the "pages" table is removed from TYPO3. This update migrates records of this type to a Backend User Section.';
44  }
45 
46  public function ‪getPrerequisites(): array
47  {
48  return [
49  DatabaseUpdatedPrerequisite::class,
50  ];
51  }
52 
53  public function ‪updateNecessary(): bool
54  {
55  return $this->‪hasRecordsToUpdate();
56  }
57 
58  public function ‪executeUpdate(): bool
59  {
60  $connection = $this->‪getConnectionPool()->getConnectionForTable(self::TABLE_NAME);
61 
62  foreach ($this->‪getRecordsToUpdate() as ‪$record) {
63  $connection->update(
64  self::TABLE_NAME,
65  [
66  'title' => '[RECYCLER] ' . ‪$record['title'],
68  ],
69  ['uid' => (int)‪$record['uid']]
70  );
71  }
72 
73  return true;
74  }
75 
76  protected function ‪hasRecordsToUpdate(): bool
77  {
78  return (bool)$this->‪getPreparedQueryBuilder()->count('uid')->executeQuery()->fetchOne();
79  }
80 
81  protected function ‪getRecordsToUpdate(): array
82  {
83  return $this->‪getPreparedQueryBuilder()->select('uid', 'title', 'doktype')->executeQuery()->fetchAllAssociative();
84  }
85 
86  protected function ‪getPreparedQueryBuilder(): QueryBuilder
87  {
88  $queryBuilder = $this->‪getConnectionPool()->getQueryBuilderForTable(self::TABLE_NAME);
89  $queryBuilder->getRestrictions()->removeAll();
90  $queryBuilder
91  ->from(self::TABLE_NAME)
92  ->where(
93  $queryBuilder->expr()->eq('doktype', $queryBuilder->createNamedParameter(255, ‪Connection::PARAM_INT))
94  );
95 
96  return $queryBuilder;
97  }
98 
100  {
101  return GeneralUtility::makeInstance(ConnectionPool::class);
102  }
103 }
‪TYPO3\CMS\Install\Updates\PagesRecyclerDoktypeMigration
Definition: PagesRecyclerDoktypeMigration.php:33
‪TYPO3\CMS\Core\Database\Connection\PARAM_INT
‪const PARAM_INT
Definition: Connection.php:52
‪TYPO3\CMS\Install\Updates\PagesRecyclerDoktypeMigration\getTitle
‪getTitle()
Definition: PagesRecyclerDoktypeMigration.php:36
‪TYPO3\CMS\Install\Updates\PagesRecyclerDoktypeMigration\executeUpdate
‪executeUpdate()
Definition: PagesRecyclerDoktypeMigration.php:58
‪TYPO3\CMS\Install\Updates\PagesRecyclerDoktypeMigration\getPrerequisites
‪getPrerequisites()
Definition: PagesRecyclerDoktypeMigration.php:46
‪TYPO3\CMS\Install\Attribute\UpgradeWizard
Definition: UpgradeWizard.php:25
‪TYPO3\CMS\Install\Updates\PagesRecyclerDoktypeMigration\getRecordsToUpdate
‪getRecordsToUpdate()
Definition: PagesRecyclerDoktypeMigration.php:81
‪TYPO3\CMS\Install\Updates\PagesRecyclerDoktypeMigration\TABLE_NAME
‪const TABLE_NAME
Definition: PagesRecyclerDoktypeMigration.php:34
‪TYPO3\CMS\Install\Updates\PagesRecyclerDoktypeMigration\updateNecessary
‪updateNecessary()
Definition: PagesRecyclerDoktypeMigration.php:53
‪TYPO3\CMS\Install\Updates
Definition: LegacyClassesForIde.php:22
‪TYPO3\CMS\Install\Updates\PagesRecyclerDoktypeMigration\hasRecordsToUpdate
‪hasRecordsToUpdate()
Definition: PagesRecyclerDoktypeMigration.php:76
‪TYPO3\CMS\Install\Updates\PagesRecyclerDoktypeMigration\getConnectionPool
‪getConnectionPool()
Definition: PagesRecyclerDoktypeMigration.php:99
‪TYPO3\CMS\Install\Updates\PagesRecyclerDoktypeMigration\getDescription
‪getDescription()
Definition: PagesRecyclerDoktypeMigration.php:41
‪TYPO3\CMS\Webhooks\Message\$record
‪identifier readonly int readonly array $record
Definition: PageModificationMessage.php:36
‪TYPO3\CMS\Core\Domain\Repository\PageRepository\DOKTYPE_BE_USER_SECTION
‪const DOKTYPE_BE_USER_SECTION
Definition: PageRepository.php:101
‪TYPO3\CMS\Core\Database\Connection
Definition: Connection.php:41
‪TYPO3\CMS\Install\Updates\UpgradeWizardInterface
Definition: UpgradeWizardInterface.php:24
‪TYPO3\CMS\Install\Updates\PagesRecyclerDoktypeMigration\getPreparedQueryBuilder
‪getPreparedQueryBuilder()
Definition: PagesRecyclerDoktypeMigration.php:86
‪TYPO3\CMS\Core\Domain\Repository\PageRepository
Definition: PageRepository.php:69
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52