‪TYPO3CMS  ‪main
SysFileMountIdentifierMigration.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;
25 
30 #[UpgradeWizard('sysFileMountIdentifierMigration')]
32 {
33  protected const ‪TABLE_NAME = 'sys_filemounts';
34 
35  public function ‪getTitle(): string
36  {
37  return 'Migrate base and path to the new identifier property of the "sys_filemounts" table.';
38  }
39 
40  public function ‪getDescription(): string
41  {
42  return 'The "sys_filemounts" table has a new identifier property which is used to identify the mount point. This update migrates the properties "base" and "path" to the new "identifier" property.';
43  }
44 
45  public function ‪getPrerequisites(): array
46  {
47  return [
48  DatabaseUpdatedPrerequisite::class,
49  ];
50  }
51 
52  public function ‪updateNecessary(): bool
53  {
54  return $this->‪columnsExistInTable() && $this->‪hasRecordsToUpdate();
55  }
56 
57  public function ‪executeUpdate(): bool
58  {
59  $connection = $this->‪getConnectionPool()->getConnectionForTable(self::TABLE_NAME);
60 
61  foreach ($this->‪getRecordsToUpdate() as ‪$record) {
62  $connection->update(
63  self::TABLE_NAME,
64  ['identifier' => ‪$record['base'] . ':' . ‪$record['path']],
65  ['uid' => (int)‪$record['uid']]
66  );
67  }
68 
69  return true;
70  }
71 
72  protected function ‪columnsExistInTable(): bool
73  {
74  $schemaManager = $this->‪getConnectionPool()->getConnectionForTable(self::TABLE_NAME)->createSchemaManager();
75 
76  $tableColumns = $schemaManager->listTableColumns(self::TABLE_NAME);
77 
78  foreach (['path', 'base', 'identifier'] as $column) {
79  if (!isset($tableColumns[$column])) {
80  return false;
81  }
82  }
83 
84  return true;
85  }
86 
87  protected function ‪hasRecordsToUpdate(): bool
88  {
89  return (bool)$this->‪getPreparedQueryBuilder()->count('uid')->executeQuery()->fetchOne();
90  }
91 
92  protected function ‪getRecordsToUpdate(): array
93  {
94  return $this->‪getPreparedQueryBuilder()->select(...['uid', 'path', 'base'])->executeQuery()->fetchAllAssociative();
95  }
96 
97  protected function ‪getPreparedQueryBuilder(): QueryBuilder
98  {
99  $queryBuilder = $this->‪getConnectionPool()->getQueryBuilderForTable(self::TABLE_NAME);
100  $queryBuilder->getRestrictions()->removeAll();
101  $queryBuilder
102  ->from(self::TABLE_NAME)
103  ->where(
104  $queryBuilder->expr()->gt('base', $queryBuilder->createNamedParameter(0, ‪Connection::PARAM_INT)),
105  $queryBuilder->expr()->neq('path', $queryBuilder->createNamedParameter('')),
106  $queryBuilder->expr()->eq('identifier', $queryBuilder->createNamedParameter(''))
107  );
108 
109  return $queryBuilder;
110  }
111 
113  {
114  return GeneralUtility::makeInstance(ConnectionPool::class);
115  }
116 }
‪TYPO3\CMS\Core\Database\Connection\PARAM_INT
‪const PARAM_INT
Definition: Connection.php:52
‪TYPO3\CMS\Install\Updates\SysFileMountIdentifierMigration\getPrerequisites
‪getPrerequisites()
Definition: SysFileMountIdentifierMigration.php:45
‪TYPO3\CMS\Install\Attribute\UpgradeWizard
Definition: UpgradeWizard.php:25
‪TYPO3\CMS\Install\Updates\SysFileMountIdentifierMigration\hasRecordsToUpdate
‪hasRecordsToUpdate()
Definition: SysFileMountIdentifierMigration.php:87
‪TYPO3\CMS\Install\Updates\SysFileMountIdentifierMigration\executeUpdate
‪executeUpdate()
Definition: SysFileMountIdentifierMigration.php:57
‪TYPO3\CMS\Install\Updates\SysFileMountIdentifierMigration\getConnectionPool
‪getConnectionPool()
Definition: SysFileMountIdentifierMigration.php:112
‪TYPO3\CMS\Install\Updates
Definition: LegacyClassesForIde.php:22
‪TYPO3\CMS\Install\Updates\SysFileMountIdentifierMigration\getDescription
‪getDescription()
Definition: SysFileMountIdentifierMigration.php:40
‪TYPO3\CMS\Install\Updates\SysFileMountIdentifierMigration\columnsExistInTable
‪columnsExistInTable()
Definition: SysFileMountIdentifierMigration.php:72
‪TYPO3\CMS\Install\Updates\SysFileMountIdentifierMigration\TABLE_NAME
‪const TABLE_NAME
Definition: SysFileMountIdentifierMigration.php:33
‪TYPO3\CMS\Webhooks\Message\$record
‪identifier readonly int readonly array $record
Definition: PageModificationMessage.php:36
‪TYPO3\CMS\Install\Updates\SysFileMountIdentifierMigration
Definition: SysFileMountIdentifierMigration.php:32
‪TYPO3\CMS\Install\Updates\SysFileMountIdentifierMigration\getTitle
‪getTitle()
Definition: SysFileMountIdentifierMigration.php:35
‪TYPO3\CMS\Install\Updates\SysFileMountIdentifierMigration\getRecordsToUpdate
‪getRecordsToUpdate()
Definition: SysFileMountIdentifierMigration.php:92
‪TYPO3\CMS\Install\Updates\SysFileMountIdentifierMigration\getPreparedQueryBuilder
‪getPreparedQueryBuilder()
Definition: SysFileMountIdentifierMigration.php:97
‪TYPO3\CMS\Core\Database\Connection
Definition: Connection.php:41
‪TYPO3\CMS\Install\Updates\UpgradeWizardInterface
Definition: UpgradeWizardInterface.php:24
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:52
‪TYPO3\CMS\Install\Updates\SysFileMountIdentifierMigration\updateNecessary
‪updateNecessary()
Definition: SysFileMountIdentifierMigration.php:52