‪TYPO3CMS  9.5
ExtensionManagerTables.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 
22 
29 {
33  public function ‪getIdentifier(): string
34  {
35  return 'extensionManagerTables';
36  }
37 
41  public function ‪getTitle(): string
42  {
43  return 'Add the default Extension Manager database tables';
44  }
45 
49  public function ‪getDescription(): string
50  {
51  return 'Creates necessary database tables and adds static data for the Extension Manager.';
52  }
53 
59  public function ‪updateNecessary(): bool
60  {
61  $result = false;
62  // First check necessary database update
63  $updateStatements = array_filter($this->‪getUpdateStatements());
64  if (count($updateStatements) === 0) {
65  // Get count of rows in repository database table
66  $count = GeneralUtility::makeInstance(ConnectionPool::class)
67  ->getConnectionForTable('tx_extensionmanager_domain_model_repository')
68  ->count('*', 'tx_extensionmanager_domain_model_repository', []);
69 
70  if ($count === 0) {
71  $result = true;
72  }
73  } else {
74  $result = true;
75  }
76  return $result;
77  }
78 
82  public function ‪getPrerequisites(): array
83  {
84  return [
85  DatabaseUpdatedPrerequisite::class
86  ];
87  }
88 
94  public function ‪executeUpdate(): bool
95  {
96  $result = true;
97 
98  $sqlReader = GeneralUtility::makeInstance(SqlReader::class);
99  $createTableStatements = $this->‪getTableStatements();
100 
101  // First perform all create, add and change queries
102  $schemaMigrationService = GeneralUtility::makeInstance(SchemaMigrator::class);
103  $schemaMigrationService->install($createTableStatements);
104 
105  // Perform import of static data
106  $rawDefinitions = file_get_contents(
107  ‪ExtensionManagementUtility::extPath('extensionmanager', 'ext_tables_static+adt.sql')
108  );
109 
110  $insertStatements = $sqlReader->getInsertStatementArray($rawDefinitions);
111  $schemaMigrationService->importStaticData($insertStatements);
112 
113  return $result;
114  }
115 
121  protected function ‪getUpdateStatements()
122  {
123  $updateStatements = [];
124  $emTableStatements = $this->‪getTableStatements();
125  if (count($emTableStatements)) {
126  $schemaMigrationService = GeneralUtility::makeInstance(SchemaMigrator::class);
127  $updateSuggestions = $schemaMigrationService->getUpdateSuggestions($emTableStatements);
128  $updateStatements = array_merge_recursive(...array_values($updateSuggestions));
129  }
130  return $updateStatements;
131  }
132 
138  protected function ‪getTableStatements(): array
139  {
140  $rawDefinitions = file_get_contents(‪ExtensionManagementUtility::extPath('extensionmanager', 'ext_tables.sql'));
141  $sqlReader = GeneralUtility::makeInstance(SqlReader::class);
142  return $sqlReader->getCreateTableStatementArray($rawDefinitions);
143  }
144 }
‪TYPO3\CMS\Install\Updates\ExtensionManagerTables\getIdentifier
‪string getIdentifier()
Definition: ExtensionManagerTables.php:33
‪TYPO3\CMS\Install\Updates\ExtensionManagerTables\getDescription
‪string getDescription()
Definition: ExtensionManagerTables.php:49
‪TYPO3\CMS\Install\Updates\RepeatableInterface
Definition: RepeatableInterface.php:25
‪TYPO3\CMS\Install\Updates\ExtensionManagerTables\getUpdateStatements
‪array getUpdateStatements()
Definition: ExtensionManagerTables.php:121
‪TYPO3\CMS\Install\Updates\ExtensionManagerTables\getTitle
‪string getTitle()
Definition: ExtensionManagerTables.php:41
‪TYPO3\CMS\Install\Updates\ExtensionManagerTables\executeUpdate
‪bool executeUpdate()
Definition: ExtensionManagerTables.php:94
‪TYPO3\CMS\Install\Updates\ExtensionManagerTables\getPrerequisites
‪string[] getPrerequisites()
Definition: ExtensionManagerTables.php:82
‪TYPO3\CMS\Core\Database\Schema\SqlReader
Definition: SqlReader.php:29
‪TYPO3\CMS\Core\Database\Schema\SchemaMigrator
Definition: SchemaMigrator.php:35
‪TYPO3\CMS\Install\Updates
Definition: AbstractDownloadExtensionUpdate.php:3
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility
Definition: ExtensionManagementUtility.php:36
‪TYPO3\CMS\Install\Updates\ExtensionManagerTables\updateNecessary
‪bool updateNecessary()
Definition: ExtensionManagerTables.php:59
‪TYPO3\CMS\Install\Updates\UpgradeWizardInterface
Definition: UpgradeWizardInterface.php:22
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility\extPath
‪static string extPath($key, $script='')
Definition: ExtensionManagementUtility.php:149
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:44
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:45
‪TYPO3\CMS\Install\Updates\ExtensionManagerTables\getTableStatements
‪string[] getTableStatements()
Definition: ExtensionManagerTables.php:138
‪TYPO3\CMS\Install\Updates\ExtensionManagerTables
Definition: ExtensionManagerTables.php:29