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