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