forked from TYPO3-extensions/static_info_tables
-
Notifications
You must be signed in to change notification settings - Fork 0
/
class.ext_update.php
158 lines (145 loc) · 5.84 KB
/
class.ext_update.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
<?php
namespace SJBR\StaticInfoTables;
/*
* Copyright notice
*
* (c) 2013-2017 Stanislas Rolland <typo3(arobas)sjbr.ca>
* All rights reserved
*
* This script is part of the Typo3 project. The Typo3 project is
* free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* The GNU General Public License can be found at
* http://www.gnu.org/copyleft/gpl.html.
*
* This script is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* This copyright notice MUST APPEAR in all copies of the script!
*/
use SJBR\StaticInfoTables\Cache\ClassCacheManager;
use SJBR\StaticInfoTables\Utility\DatabaseUpdateUtility;
use TYPO3\CMS\Extbase\Object\ObjectManager;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Extbase\Utility\LocalizationUtility;
use TYPO3\CMS\Extensionmanager\Utility\InstallUtility;
use TYPO3\CMS\Install\Service\SqlSchemaMigrationService;
/**
* Class for updating the db
*/
class ext_update
{
/**
* @var string Name of the extension this controller belongs to
*/
protected $extensionName = 'StaticInfoTables';
/**
* @var \TYPO3\CMS\Extbase\Object\ObjectManager Extbase Object Manager
*/
protected $objectManager;
/**
* @var \TYPO3\CMS\Extensionmanager\Utility\InstallUtility Extension Manager Install Tool
*/
protected $installTool;
/**
* Main function, returning the HTML content
*
* @return string HTML
*/
public function main()
{
$content = '';
$this->objectManager = GeneralUtility::makeInstance(ObjectManager::class);
$this->installTool = $this->objectManager->get(InstallUtility::class);
$installToolSqlParser = GeneralUtility::makeInstance(SqlSchemaMigrationService::class);
$this->installTool->injectInstallToolSqlParser($installToolSqlParser);
$databaseUpdateUtility = GeneralUtility::makeInstance(DatabaseUpdateUtility::class);
// Clear the class cache
$classCacheManager = GeneralUtility::makeInstance(ClassCacheManager::class);
$classCacheManager->reBuild();
// Process the database updates of this base extension (we want to re-process these updates every time the update script is invoked)
$extensionSitePath = ExtensionManagementUtility::extPath(GeneralUtility::camelCaseToLowerCaseUnderscored($this->extensionName));
$content .= '<p>' . nl2br(LocalizationUtility::translate('updateTables', $this->extensionName)) . '</p>';
$this->importStaticSqlFile($extensionSitePath);
// Get the extensions which want to extend static_info_tables
$loadedExtensions = array_unique(ExtensionManagementUtility::getLoadedExtensionListArray());
foreach ($loadedExtensions as $extensionKey) {
$extensionInfoFile = ExtensionManagementUtility::extPath($extensionKey) . 'Configuration/DomainModelExtension/StaticInfoTables.txt';
if (file_exists($extensionInfoFile)) {
// We need to reprocess the database structure update sql statements (ext_tables)
$this->processDatabaseUpdates($extensionKey);
// Now we process the static data updates (ext_tables_static+adt)
// Note: The Install Tool Utility does not handle sql update statements
$databaseUpdateUtility->doUpdate($extensionKey);
$content .= '<p>' . nl2br(LocalizationUtility::translate('updateLanguageLabels', $this->extensionName)) . ' ' . $extensionKey . '</p>';
}
}
if (!$content) {
// Nothing to do
$content .= '<p>' . nl2br(LocalizationUtility::translate('nothingToDo', $this->extensionName)) . '</p>';
}
// Notice for old language packs
$content .= '<p>' . nl2br(LocalizationUtility::translate('update.oldLanguagePacks', $this->extensionName)) . '</p>';
return $content;
}
/**
* Processes the tables SQL File (ext_tables)
*
* @param string $extensionKey
* @return void
*/
protected function processDatabaseUpdates($extensionKey)
{
$extensionSitePath = ExtensionManagementUtility::extPath($extensionKey);
$extTablesSqlFile = $extensionSitePath . 'ext_tables.sql';
$extTablesSqlContent = '';
if (file_exists($extTablesSqlFile)) {
$extTablesSqlContent .= GeneralUtility::getUrl($extTablesSqlFile);
}
if ($extTablesSqlContent !== '') {
$this->installTool->updateDbWithExtTablesSql($extTablesSqlContent);
}
}
/**
* Imports a static tables SQL File (ext_tables_static+adt)
*
* @param string $extensionSitePath
* @return void
*/
protected function importStaticSqlFile($extensionSitePath)
{
$extTablesStaticSqlFile = $extensionSitePath . 'ext_tables_static+adt.sql';
$extTablesStaticSqlContent = '';
if (file_exists($extTablesStaticSqlFile)) {
$extTablesStaticSqlContent .= GeneralUtility::getUrl($extTablesStaticSqlFile);
}
if ($extTablesStaticSqlContent !== '') {
if (class_exists('TYPO3\\CMS\\Core\\Database\\ConnectionPool')) {
// TYPO3 CMS 8+ LTS
$connectionPool = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Database\ConnectionPool::class);
// Drop all tables
foreach (array_keys($GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['static_info_tables']['tables']) as $tableName) {
$connection = $connectionPool->getConnectionForTable($tableName);
try {
$connection->executeUpdate($connection->getDatabasePlatform()->getDropTableSQL($connection->quoteIdentifier($tableName)));
} catch (\Doctrine\DBAL\Exception\TableNotFoundException $e) {
// Ignore table not found exception
}
}
// Re-create all tables
$this->processDatabaseUpdates(GeneralUtility::camelCaseToLowerCaseUnderscored($this->extensionName));
}
$this->installTool->importStaticSql($extTablesStaticSqlContent);
}
}
public function access()
{
return true;
}
}