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