TYPO3 CMS  TYPO3_7-6
ExtensionCompatibilityTester.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 
29 {
35  protected $protocolFile = '';
36 
42  protected $errorProtocolFile = '';
43 
49  protected $logError = false;
50 
55  public function __construct()
56  {
57  $this->protocolFile = PATH_site . 'typo3temp/ExtensionCompatibilityTester.txt';
58  $this->errorProtocolFile = PATH_site . 'typo3temp/ExtensionCompatibilityTesterErrors.json';
59  }
60 
68  protected function executeAction()
69  {
70  register_shutdown_function([$this, 'logError']);
71  $getVars = GeneralUtility::_GET('install');
72  if (isset($getVars['extensionCompatibilityTester']) && isset($getVars['extensionCompatibilityTester']['forceCheck']) && ($getVars['extensionCompatibilityTester']['forceCheck'] == 1)) {
73  $this->deleteProtocolFile();
74  }
76  return 'OK';
77  }
78 
84  protected function deleteProtocolFile()
85  {
86  if (file_exists($this->protocolFile)) {
87  unlink($this->protocolFile);
88  }
89  if (file_exists($this->errorProtocolFile)) {
90  unlink($this->errorProtocolFile);
91  }
92  }
93 
101  protected function getExtensionsToLoad()
102  {
103  $extensionsToLoad = [];
104  $extensionsToExclude = $this->getExtensionsToExclude();
105  foreach ($GLOBALS['TYPO3_LOADED_EXT'] as $key => $extension) {
106  if (!in_array($key, $extensionsToExclude)) {
107  $extensionsToLoad[$key] = $extension;
108  }
109  }
110  return $extensionsToLoad;
111  }
112 
120  protected function getExtensionsToExclude()
121  {
122  $exclude = GeneralUtility::getUrl($this->protocolFile);
123  return GeneralUtility::trimExplode(',', (string)$exclude);
124  }
125 
134  protected function tryToLoadExtLocalconfAndExtTablesOfExtensions(array $extensions)
135  {
136  foreach ($extensions as $extensionKey => $extension) {
137  $this->writeCurrentExtensionToFile($extensionKey);
138  $this->loadExtLocalconfForExtension($extensionKey, $extension);
139  $this->removeCurrentExtensionFromFile($extensionKey);
140  }
141  ExtensionManagementUtility::loadBaseTca(false);
142  foreach ($extensions as $extensionKey => $extension) {
143  $this->writeCurrentExtensionToFile($extensionKey);
144  $this->loadExtTablesForExtension($extensionKey, $extension);
145  $this->removeCurrentExtensionFromFile($extensionKey);
146  }
147  }
148 
157  protected function loadExtTablesForExtension($extensionKey, array $extension)
158  {
159  // In general it is recommended to not rely on it to be globally defined in that
160  // scope, but we can not prohibit this without breaking backwards compatibility
161  global $T3_SERVICES, $T3_VAR, $TYPO3_CONF_VARS;
162  global $TBE_MODULES, $TBE_MODULES_EXT, $TCA;
163  global $PAGES_TYPES, $TBE_STYLES;
164  global $_EXTKEY;
165  // Load each ext_tables.php file of loaded extensions
166  $_EXTKEY = $extensionKey;
167  if (isset($extension['ext_tables.php']) && $extension['ext_tables.php']) {
168  // $_EXTKEY and $_EXTCONF are available in ext_tables.php
169  // and are explicitly set in cached file as well
170  $_EXTCONF = $GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$_EXTKEY];
171  require $extension['ext_tables.php'];
173  }
174  }
175 
184  protected function loadExtLocalconfForExtension($extensionKey, array $extension)
185  {
186  // This is the main array meant to be manipulated in the ext_localconf.php files
187  // In general it is recommended to not rely on it to be globally defined in that
188  // scope but to use $GLOBALS['TYPO3_CONF_VARS'] instead.
189  // Nevertheless we define it here as global for backwards compatibility.
190  global $TYPO3_CONF_VARS;
191  $_EXTKEY = $extensionKey;
192  if (isset($extension['ext_localconf.php']) && $extension['ext_localconf.php']) {
193  // $_EXTKEY and $_EXTCONF are available in ext_localconf.php
194  // and are explicitly set in cached file as well
195  $_EXTCONF = $GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$_EXTKEY];
196  require $extension['ext_localconf.php'];
197  }
198  }
199 
207  protected function writeCurrentExtensionToFile($extensionKey)
208  {
209  $incompatibleExtensions = array_filter(GeneralUtility::trimExplode(',', (string)GeneralUtility::getUrl($this->protocolFile)));
210  $incompatibleExtensions = array_merge($incompatibleExtensions, [$extensionKey]);
211  GeneralUtility::writeFile($this->protocolFile, implode(', ', $incompatibleExtensions));
212  $this->logError = true;
213  }
214 
221  protected function removeCurrentExtensionFromFile($extensionKey)
222  {
223  $extensionsInFile = array_filter(GeneralUtility::trimExplode(',', (string)GeneralUtility::getUrl($this->protocolFile)));
224  $extensionsByKey = array_flip($extensionsInFile);
225  unset($extensionsByKey[$extensionKey]);
226  $extensionsForFile = array_flip($extensionsByKey);
227  GeneralUtility::writeFile($this->protocolFile, implode(', ', $extensionsForFile));
228  $this->logError = false;
229  }
230 
236  public function logError()
237  {
238  // Logging is disabled.
239  if (!$this->logError) {
240  return;
241  }
242 
243  // Fetch existing errors, add last one and write to file again.
244  $lastError = error_get_last();
245  $errors = [];
246 
247  if (file_exists($this->errorProtocolFile)) {
248  $errors = json_decode(GeneralUtility::getUrl($this->errorProtocolFile));
249  }
250  switch ($lastError['type']) {
251  case E_ERROR:
252  $lastError['type'] = 'E_ERROR';
253  break;
254  case E_WARNING:
255  $lastError['type'] = 'E_WARNING';
256  break;
257  case E_PARSE:
258  $lastError['type'] = 'E_PARSE';
259  break;
260  case E_NOTICE:
261  $lastError['type'] = 'E_NOTICE';
262  break;
263  case E_NOTICE:
264  $lastError['type'] = 'E_NOTICE';
265  break;
266  }
267  $errors[] = $lastError;
268 
269  GeneralUtility::writeFile($this->errorProtocolFile, json_encode($errors));
270  }
271 }
static trimExplode($delim, $string, $removeEmptyValues=false, $limit=0)
$_EXTCONF
static getUrl($url, $includeHeader=0, $requestHeaders=false, &$report=null)
$TCA['tx_blogexample_domain_model_blog']
Definition: Blog.php:4
if(TYPO3_MODE==='BE') $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tsfebeuserauth.php']['frontendEditingController']['default']
static writeFile($file, $content, $changePermissions=false)