TYPO3 CMS  TYPO3_6-2
ExtensionCompatibilityTester.php
Go to the documentation of this file.
1 <?php
3 
18 
28 
34  protected $protocolFile = '';
35 
41  protected $errorProtocolFile = '';
42 
48  protected $logError = FALSE;
49 
54  public function __construct() {
55  $this->protocolFile = PATH_site . 'typo3temp/ExtensionCompatibilityTester.txt';
56  $this->errorProtocolFile = PATH_site . 'typo3temp/ExtensionCompatibilityTesterErrors.json';
57  }
58 
66  protected function executeAction() {
67  register_shutdown_function(array($this, 'logError'));
68  $getVars = Utility\GeneralUtility::_GET('install');
69  if (isset($getVars['extensionCompatibilityTester']) && isset($getVars['extensionCompatibilityTester']['forceCheck']) && ($getVars['extensionCompatibilityTester']['forceCheck'] == 1)) {
70  $this->deleteProtocolFile();
71  }
73  return 'OK';
74  }
75 
81  protected function deleteProtocolFile() {
82  if (file_exists($this->protocolFile)) {
83  unlink($this->protocolFile);
84  }
85  if (file_exists($this->errorProtocolFile)) {
86  unlink($this->errorProtocolFile);
87  }
88  }
89 
97  protected function getExtensionsToLoad() {
98  $extensionsToLoad = array();
99  $extensionsToExclude = $this->getExtensionsToExclude();
100  foreach ($GLOBALS['TYPO3_LOADED_EXT'] as $key => $extension) {
101  if (!in_array($key, $extensionsToExclude)) {
102  $extensionsToLoad[$key] = $extension;
103  }
104  }
105  return $extensionsToLoad;
106  }
107 
115  protected function getExtensionsToExclude() {
116  $exclude = Utility\GeneralUtility::getUrl($this->protocolFile);
117  return Utility\GeneralUtility::trimExplode(',', (string)$exclude);
118  }
119 
128  protected function tryToLoadExtLocalconfAndExtTablesOfExtensions(array $extensions) {
129  foreach ($extensions as $extensionKey => $extension) {
130  $this->writeCurrentExtensionToFile($extensionKey);
131  $this->loadExtLocalconfForExtension($extensionKey, $extension);
132  $this->removeCurrentExtensionFromFile($extensionKey);
133  }
134  Utility\ExtensionManagementUtility::loadBaseTca(FALSE);
135  foreach ($extensions as $extensionKey => $extension) {
136  $this->writeCurrentExtensionToFile($extensionKey);
137  $this->loadExtTablesForExtension($extensionKey, $extension);
138  $this->removeCurrentExtensionFromFile($extensionKey);
139  }
140  }
141 
150  protected function loadExtTablesForExtension($extensionKey, array $extension) {
151  // In general it is recommended to not rely on it to be globally defined in that
152  // scope, but we can not prohibit this without breaking backwards compatibility
153  global $T3_SERVICES, $T3_VAR, $TYPO3_CONF_VARS;
154  global $TBE_MODULES, $TBE_MODULES_EXT, $TCA;
155  global $PAGES_TYPES, $TBE_STYLES, $FILEICONS;
156  global $_EXTKEY;
157  // Load each ext_tables.php file of loaded extensions
158  $_EXTKEY = $extensionKey;
159  if (isset($extension['ext_tables.php']) && $extension['ext_tables.php']) {
160  // $_EXTKEY and $_EXTCONF are available in ext_tables.php
161  // and are explicitly set in cached file as well
162  $_EXTCONF = $GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$_EXTKEY];
163  require $extension['ext_tables.php'];
164  Utility\ExtensionManagementUtility::loadNewTcaColumnsConfigFiles();
165  }
166  }
167 
176  protected function loadExtLocalconfForExtension($extensionKey, array $extension) {
177  // This is the main array meant to be manipulated in the ext_localconf.php files
178  // In general it is recommended to not rely on it to be globally defined in that
179  // scope but to use $GLOBALS['TYPO3_CONF_VARS'] instead.
180  // Nevertheless we define it here as global for backwards compatibility.
181  global $TYPO3_CONF_VARS;
182  $_EXTKEY = $extensionKey;
183  if (isset($extension['ext_localconf.php']) && $extension['ext_localconf.php']) {
184  // $_EXTKEY and $_EXTCONF are available in ext_localconf.php
185  // and are explicitly set in cached file as well
186  $_EXTCONF = $GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$_EXTKEY];
187  require $extension['ext_localconf.php'];
188  }
189  }
190 
198  protected function writeCurrentExtensionToFile($extensionKey) {
199  $incompatibleExtensions = array_filter(Utility\GeneralUtility::trimExplode(',', (string)Utility\GeneralUtility::getUrl($this->protocolFile)));
200  $incompatibleExtensions = array_merge($incompatibleExtensions, array($extensionKey));
201  Utility\GeneralUtility::writeFile($this->protocolFile, implode(', ', $incompatibleExtensions));
202  $this->logError = TRUE;
203  }
204 
211  protected function removeCurrentExtensionFromFile($extensionKey) {
212  $extensionsInFile = array_filter(Utility\GeneralUtility::trimExplode(',', (string)Utility\GeneralUtility::getUrl($this->protocolFile)));
213  $extensionsByKey = array_flip($extensionsInFile);
214  unset($extensionsByKey[$extensionKey]);
215  $extensionsForFile = array_flip($extensionsByKey);
216  Utility\GeneralUtility::writeFile($this->protocolFile, implode(', ', $extensionsForFile));
217  $this->logError = FALSE;
218  }
219 
225  public function logError() {
226  // Logging is disabled.
227  if (!$this->logError) {
228  return;
229  }
230 
231  // Fetch existing errors, add last one and write to file again.
232  $lastError = error_get_last();
233  $errors = array();
234 
235  if (file_exists($this->errorProtocolFile)) {
236  $errors = json_decode(Utility\GeneralUtility::getUrl($this->errorProtocolFile));
237  }
238  switch ($lastError['type']) {
239  case E_ERROR:
240  $lastError['type'] = 'E_ERROR';
241  break;
242  case E_WARNING:
243  $lastError['type'] = 'E_WARNING';
244  break;
245  case E_PARSE:
246  $lastError['type'] = 'E_PARSE';
247  break;
248  case E_NOTICE:
249  $lastError['type'] = 'E_NOTICE';
250  break;
251  case E_NOTICE:
252  $lastError['type'] = 'E_NOTICE';
253  break;
254  }
255  $errors[] = $lastError;
256 
257  Utility\GeneralUtility::writeFile($this->errorProtocolFile, json_encode($errors));
258  }
259 }
$TYPO3_CONF_VARS['SYS']['contentTable']
$TCA['tx_irretutorial_1ncsv_hotel']
static trimExplode($delim, $string, $removeEmptyValues=FALSE, $limit=0)
static getUrl($url, $includeHeader=0, $requestHeaders=FALSE, &$report=NULL)
if(!defined('TYPO3_MODE')) $_EXTCONF
if(!defined('TYPO3_MODE')) $GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_pre_processing'][]