TYPO3 CMS  TYPO3_7-6
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 
19 
24 {
25 
29  protected $title = 'Add the default Extension Manager database tables';
30 
34  protected $installToolSqlParser = null;
35 
39  protected function getInstallToolSqlParser()
40  {
41  if ($this->installToolSqlParser === null) {
42  $this->installToolSqlParser = GeneralUtility::makeInstance(\TYPO3\CMS\Install\Service\SqlSchemaMigrationService::class);
43  }
44 
46  }
47 
53  protected function getUpdateStatements()
54  {
55  $updateStatements = [];
56 
57  // Get all necessary statements for ext_tables.sql file
58  $rawDefinitions = GeneralUtility::getUrl(ExtensionManagementUtility::extPath('extensionmanager') . '/ext_tables.sql');
59  $fieldDefinitionsFromFile = $this->getInstallToolSqlParser()->getFieldDefinitions_fileContent($rawDefinitions);
60  if (count($fieldDefinitionsFromFile)) {
61  $fieldDefinitionsFromCurrentDatabase = $this->getInstallToolSqlParser()->getFieldDefinitions_database();
62  $diff = $this->getInstallToolSqlParser()->getDatabaseExtra($fieldDefinitionsFromFile, $fieldDefinitionsFromCurrentDatabase);
63  $updateStatements = $this->getInstallToolSqlParser()->getUpdateSuggestions($diff);
64  }
65 
66  return $updateStatements;
67  }
68 
75  public function checkForUpdate(&$description)
76  {
77  $result = false;
78  $description = 'Creates necessary database tables and adds static data for the Extension Manager.';
79 
80  // First check necessary database update
81  $updateStatements = $this->getUpdateStatements();
82  if (empty($updateStatements)) {
83  // Get count of rows in repository database table
84  $count = $this->getDatabaseConnection()->exec_SELECTcountRows('*', 'tx_extensionmanager_domain_model_repository');
85  if ($count === 0) {
86  $result = true;
87  }
88  } else {
89  $result = true;
90  }
91 
92  return $result;
93  }
94 
100  protected function hasError(&$customMessages)
101  {
102  $result = false;
103  if ($this->getDatabaseConnection()->sql_error()) {
104  $customMessages .= '<br /><br />SQL-ERROR: ' . htmlspecialchars($this->getDatabaseConnection()->sql_error());
105  $result = true;
106  }
107 
108  return $result;
109  }
110 
118  public function performUpdate(array &$dbQueries, &$customMessages)
119  {
120  $result = false;
121 
122  // First perform all create, add and change queries
123  $updateStatements = $this->getUpdateStatements();
124  foreach ((array)$updateStatements['add'] as $string) {
125  $this->getDatabaseConnection()->admin_query($string);
126  $dbQueries[] = $string;
127  $result = ($result || $this->hasError($customMessages));
128  }
129  foreach ((array)$updateStatements['change'] as $string) {
130  $this->getDatabaseConnection()->admin_query($string);
131  $dbQueries[] = $string;
132  $result = ($result || $this->hasError($customMessages));
133  }
134  foreach ((array)$updateStatements['create_table'] as $string) {
135  $this->getDatabaseConnection()->admin_query($string);
136  $dbQueries[] = $string;
137  $result = ($result || $this->hasError($customMessages));
138  }
139 
140  // Perform statis import anyway
141  $rawDefinitions = GeneralUtility::getUrl(ExtensionManagementUtility::extPath('extensionmanager') . 'ext_tables_static+adt.sql');
142  $statements = $this->getInstallToolSqlParser()->getStatementarray($rawDefinitions, 1);
143  foreach ($statements as $statement) {
144  if (trim($statement) !== '') {
145  $this->getDatabaseConnection()->admin_query($statement);
146  $dbQueries[] = $statement;
147  $result = ($result || $this->hasError($customMessages));
148  }
149  }
150 
151  return !$result;
152  }
153 }
static getUrl($url, $includeHeader=0, $requestHeaders=false, &$report=null)
performUpdate(array &$dbQueries, &$customMessages)