TYPO3 CMS  TYPO3_8-7
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 
27 {
31  protected $title = 'Add the default Extension Manager database tables';
32 
47  protected function getUpdateStatements()
48  {
49  $updateStatements = [];
50 
51  $emTableStatements = $this->getTableStatements();
52 
53  if (count($emTableStatements)) {
54  $schemaMigrationService = GeneralUtility::makeInstance(SchemaMigrator::class);
55  $updateSuggestions = $schemaMigrationService->getUpdateSuggestions($emTableStatements);
56  $updateStatements = array_merge_recursive(...array_values($updateSuggestions));
57  }
58 
59  return $updateStatements;
60  }
61 
69  protected function getTableStatements(): array
70  {
71  $rawDefinitions = file_get_contents(ExtensionManagementUtility::extPath('extensionmanager', 'ext_tables.sql'));
72  $sqlReader = GeneralUtility::makeInstance(SqlReader::class);
73  return $sqlReader->getCreateTableStatementArray($rawDefinitions);
74  }
75 
91  public function checkForUpdate(&$description)
92  {
93  $result = false;
94  $description = 'Creates necessary database tables and adds static data for the Extension Manager.';
95 
96  // First check necessary database update
97  $updateStatements = array_filter($this->getUpdateStatements());
98  if (count($updateStatements) === 0) {
99  // Get count of rows in repository database table
100  $count = GeneralUtility::makeInstance(ConnectionPool::class)
101  ->getConnectionForTable('tx_extensionmanager_domain_model_repository')
102  ->count('*', 'tx_extensionmanager_domain_model_repository', []);
103 
104  if ($count === 0) {
105  $result = true;
106  }
107  } else {
108  $result = true;
109  }
110 
111  return $result;
112  }
113 
121  public function performUpdate(array &$dbQueries, &$customMessage)
122  {
123  $result = true;
124  $sqlReader = GeneralUtility::makeInstance(SqlReader::class);
125 
126  $createTableStatements = $this->getTableStatements();
127 
128  // First perform all create, add and change queries
129  $schemaMigrationService = GeneralUtility::makeInstance(SchemaMigrator::class);
130  $schemaMigrationService->install($createTableStatements);
131 
132  // Perform import of static data
133  $rawDefinitions = file_get_contents(
134  ExtensionManagementUtility::extPath('extensionmanager', 'ext_tables_static+adt.sql')
135  );
136 
137  $insertStatements = $sqlReader->getInsertStatementArray($rawDefinitions);
138  $results = $schemaMigrationService->importStaticData($insertStatements);
139 
140  foreach ($results as $statement => $errorMessage) {
141  $dbQueries[] = $statement;
142  if ($errorMessage) {
143  $result = false;
144  $customMessage .= '<br /><br />SQL-ERROR: ' . htmlspecialchars($errorMessage);
145  }
146  }
147 
148  return $result;
149  }
150 }
static makeInstance($className,... $constructorArguments)