‪TYPO3CMS  10.4
ExtensionManagerTables.php
Go to the documentation of this file.
1 <?php
2 
3 /*
4  * This file is part of the TYPO3 CMS project.
5  *
6  * It is free software; you can redistribute it and/or modify it under
7  * the terms of the GNU General Public License, either version 2
8  * of the License, or any later version.
9  *
10  * For the full copyright and license information, please read the
11  * LICENSE.txt file that was distributed with this source code.
12  *
13  * The TYPO3 project - inspiring people to share!
14  */
15 
17 
23 
30 {
34  public function ‪getIdentifier(): string
35  {
36  return 'extensionManagerTables';
37  }
38 
42  public function ‪getTitle(): string
43  {
44  return 'Add the default Extension Manager database tables';
45  }
46 
50  public function ‪getDescription(): string
51  {
52  return 'Creates necessary database tables and adds static data for the Extension Manager.';
53  }
54 
60  public function ‪updateNecessary(): bool
61  {
62  $result = false;
63  // First check necessary database update
64  $updateStatements = array_filter($this->‪getUpdateStatements());
65  if (count($updateStatements) === 0) {
66  // Get count of rows in repository database table
67  $count = GeneralUtility::makeInstance(ConnectionPool::class)
68  ->getConnectionForTable('tx_extensionmanager_domain_model_repository')
69  ->count('*', 'tx_extensionmanager_domain_model_repository', []);
70 
71  if ($count === 0) {
72  $result = true;
73  }
74  } else {
75  $result = true;
76  }
77  return $result;
78  }
79 
83  public function ‪getPrerequisites(): array
84  {
85  return [
86  DatabaseUpdatedPrerequisite::class
87  ];
88  }
89 
95  public function ‪executeUpdate(): bool
96  {
97  $result = true;
98 
99  $sqlReader = GeneralUtility::makeInstance(SqlReader::class);
100  $createTableStatements = $this->‪getTableStatements();
101 
102  // First perform all create, add and change queries
103  $schemaMigrationService = GeneralUtility::makeInstance(SchemaMigrator::class);
104  $schemaMigrationService->install($createTableStatements);
105 
106  // Perform import of static data
107  $rawDefinitions = file_get_contents(
108  ‪ExtensionManagementUtility::extPath('extensionmanager', 'ext_tables_static+adt.sql')
109  );
110 
111  $insertStatements = $sqlReader->getInsertStatementArray($rawDefinitions);
112  $schemaMigrationService->importStaticData($insertStatements);
113 
114  return $result;
115  }
116 
122  protected function ‪getUpdateStatements()
123  {
124  $updateStatements = [];
125  $emTableStatements = $this->‪getTableStatements();
126  if (count($emTableStatements)) {
127  $schemaMigrationService = GeneralUtility::makeInstance(SchemaMigrator::class);
128  $updateSuggestions = $schemaMigrationService->getUpdateSuggestions($emTableStatements);
129  $updateStatements = array_merge_recursive(...array_values($updateSuggestions));
130  }
131  return $updateStatements;
132  }
133 
139  protected function ‪getTableStatements(): array
140  {
141  $rawDefinitions = file_get_contents(‪ExtensionManagementUtility::extPath('extensionmanager', 'ext_tables.sql'));
142  $sqlReader = GeneralUtility::makeInstance(SqlReader::class);
143  return $sqlReader->getCreateTableStatementArray($rawDefinitions);
144  }
145 }
‪TYPO3\CMS\Install\Updates\ExtensionManagerTables\getIdentifier
‪string getIdentifier()
Definition: ExtensionManagerTables.php:34
‪TYPO3\CMS\Install\Updates\ExtensionManagerTables\getDescription
‪string getDescription()
Definition: ExtensionManagerTables.php:50
‪TYPO3\CMS\Install\Updates\RepeatableInterface
Definition: RepeatableInterface.php:26
‪TYPO3\CMS\Install\Updates\ExtensionManagerTables\getUpdateStatements
‪array getUpdateStatements()
Definition: ExtensionManagerTables.php:122
‪TYPO3\CMS\Install\Updates\ExtensionManagerTables\getTitle
‪string getTitle()
Definition: ExtensionManagerTables.php:42
‪TYPO3\CMS\Install\Updates\ExtensionManagerTables\executeUpdate
‪bool executeUpdate()
Definition: ExtensionManagerTables.php:95
‪TYPO3\CMS\Install\Updates\ExtensionManagerTables\getPrerequisites
‪string[] getPrerequisites()
Definition: ExtensionManagerTables.php:83
‪TYPO3\CMS\Core\Database\Schema\SqlReader
Definition: SqlReader.php:31
‪TYPO3\CMS\Core\Database\Schema\SchemaMigrator
Definition: SchemaMigrator.php:36
‪TYPO3\CMS\Install\Updates
Definition: AbstractDownloadExtensionUpdate.php:16
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility
Definition: ExtensionManagementUtility.php:43
‪TYPO3\CMS\Install\Updates\ExtensionManagerTables\updateNecessary
‪bool updateNecessary()
Definition: ExtensionManagerTables.php:60
‪TYPO3\CMS\Install\Updates\UpgradeWizardInterface
Definition: UpgradeWizardInterface.php:24
‪TYPO3\CMS\Core\Utility\ExtensionManagementUtility\extPath
‪static string extPath($key, $script='')
Definition: ExtensionManagementUtility.php:127
‪TYPO3\CMS\Core\Database\ConnectionPool
Definition: ConnectionPool.php:46
‪TYPO3\CMS\Core\Utility\GeneralUtility
Definition: GeneralUtility.php:46
‪TYPO3\CMS\Install\Updates\ExtensionManagerTables\getTableStatements
‪string[] getTableStatements()
Definition: ExtensionManagerTables.php:139
‪TYPO3\CMS\Install\Updates\ExtensionManagerTables
Definition: ExtensionManagerTables.php:30