[TASK] Clean up UpgradeWizardsService API
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Controller / UpgradeController.php
1 <?php
2 declare(strict_types = 1);
3 namespace TYPO3\CMS\Install\Controller;
4
5 /*
6 * This file is part of the TYPO3 CMS project.
7 *
8 * It is free software; you can redistribute it and/or modify it under
9 * the terms of the GNU General Public License, either version 2
10 * of the License, or any later version.
11 *
12 * For the full copyright and license information, please read the
13 * LICENSE.txt file that was distributed with this source code.
14 *
15 * The TYPO3 project - inspiring people to share!
16 */
17
18 use PhpParser\NodeTraverser;
19 use PhpParser\NodeVisitor\NameResolver;
20 use PhpParser\ParserFactory;
21 use Psr\Http\Message\ResponseInterface;
22 use Psr\Http\Message\ServerRequestInterface;
23 use Symfony\Component\Finder\Finder;
24 use Symfony\Component\Finder\SplFileInfo;
25 use TYPO3\CMS\Core\Core\Environment;
26 use TYPO3\CMS\Core\Database\ConnectionPool;
27 use TYPO3\CMS\Core\FormProtection\FormProtectionFactory;
28 use TYPO3\CMS\Core\FormProtection\InstallToolFormProtection;
29 use TYPO3\CMS\Core\Http\JsonResponse;
30 use TYPO3\CMS\Core\Messaging\FlashMessage;
31 use TYPO3\CMS\Core\Messaging\FlashMessageQueue;
32 use TYPO3\CMS\Core\Migrations\TcaMigration;
33 use TYPO3\CMS\Core\Registry;
34 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
35 use TYPO3\CMS\Core\Utility\GeneralUtility;
36 use TYPO3\CMS\Install\ExtensionScanner\Php\CodeStatistics;
37 use TYPO3\CMS\Install\ExtensionScanner\Php\GeneratorClassesResolver;
38 use TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\ArrayDimensionMatcher;
39 use TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\ArrayGlobalMatcher;
40 use TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\ClassConstantMatcher;
41 use TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\ClassNameMatcher;
42 use TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\ConstantMatcher;
43 use TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\FunctionCallMatcher;
44 use TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\InterfaceMethodChangedMatcher;
45 use TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\MethodAnnotationMatcher;
46 use TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\MethodArgumentDroppedMatcher;
47 use TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\MethodArgumentDroppedStaticMatcher;
48 use TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\MethodArgumentRequiredMatcher;
49 use TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\MethodArgumentRequiredStaticMatcher;
50 use TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\MethodArgumentUnusedMatcher;
51 use TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\MethodCallMatcher;
52 use TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\MethodCallStaticMatcher;
53 use TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\PropertyAnnotationMatcher;
54 use TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\PropertyExistsStaticMatcher;
55 use TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\PropertyProtectedMatcher;
56 use TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\PropertyPublicMatcher;
57 use TYPO3\CMS\Install\ExtensionScanner\Php\MatcherFactory;
58 use TYPO3\CMS\Install\Service\CoreUpdateService;
59 use TYPO3\CMS\Install\Service\CoreVersionService;
60 use TYPO3\CMS\Install\Service\LoadTcaService;
61 use TYPO3\CMS\Install\Service\UpgradeWizardsService;
62 use TYPO3\CMS\Install\UpgradeAnalysis\DocumentationFile;
63
64 /**
65 * Upgrade controller
66 */
67 class UpgradeController extends AbstractController
68 {
69 /**
70 * @var CoreUpdateService
71 */
72 protected $coreUpdateService;
73
74 /**
75 * @var CoreVersionService
76 */
77 protected $coreVersionService;
78
79 /**
80 * Matcher registry of extension scanner.
81 * Node visitors that implement CodeScannerInterface
82 *
83 * @var array
84 */
85 protected $matchers = [
86 [
87 'class' => ArrayDimensionMatcher::class,
88 'configurationFile' => 'EXT:install/Configuration/ExtensionScanner/Php/ArrayDimensionMatcher.php',
89 ],
90 [
91 'class' => ArrayGlobalMatcher::class,
92 'configurationFile' => 'EXT:install/Configuration/ExtensionScanner/Php/ArrayGlobalMatcher.php',
93 ],
94 [
95 'class' => ClassConstantMatcher::class,
96 'configurationFile' => 'EXT:install/Configuration/ExtensionScanner/Php/ClassConstantMatcher.php',
97 ],
98 [
99 'class' => ClassNameMatcher::class,
100 'configurationFile' => 'EXT:install/Configuration/ExtensionScanner/Php/ClassNameMatcher.php',
101 ],
102 [
103 'class' => ConstantMatcher::class,
104 'configurationFile' => 'EXT:install/Configuration/ExtensionScanner/Php/ConstantMatcher.php',
105 ],
106 [
107 'class' => PropertyAnnotationMatcher::class,
108 'configurationFile' => 'EXT:install/Configuration/ExtensionScanner/Php/PropertyAnnotationMatcher.php',
109 ],
110 [
111 'class' => MethodAnnotationMatcher::class,
112 'configurationFile' => 'EXT:install/Configuration/ExtensionScanner/Php/MethodAnnotationMatcher.php',
113 ],
114 [
115 'class' => FunctionCallMatcher::class,
116 'configurationFile' => 'EXT:install/Configuration/ExtensionScanner/Php/FunctionCallMatcher.php',
117 ],
118 [
119 'class' => InterfaceMethodChangedMatcher::class,
120 'configurationFile' => 'EXT:install/Configuration/ExtensionScanner/Php/InterfaceMethodChangedMatcher.php',
121 ],
122 [
123 'class' => MethodArgumentDroppedMatcher::class,
124 'configurationFile' => 'EXT:install/Configuration/ExtensionScanner/Php/MethodArgumentDroppedMatcher.php',
125 ],
126 [
127 'class' => MethodArgumentDroppedStaticMatcher::class,
128 'configurationFile' => 'EXT:install/Configuration/ExtensionScanner/Php/MethodArgumentDroppedStaticMatcher.php',
129 ],
130 [
131 'class' => MethodArgumentRequiredMatcher::class,
132 'configurationFile' => 'EXT:install/Configuration/ExtensionScanner/Php/MethodArgumentRequiredMatcher.php',
133 ],
134 [
135 'class' => MethodArgumentRequiredStaticMatcher::class,
136 'configurationFile' => 'EXT:install/Configuration/ExtensionScanner/Php/MethodArgumentRequiredStaticMatcher.php',
137 ],
138 [
139 'class' => MethodArgumentUnusedMatcher::class,
140 'configurationFile' => 'EXT:install/Configuration/ExtensionScanner/Php/MethodArgumentUnusedMatcher.php',
141 ],
142 [
143 'class' => MethodCallMatcher::class,
144 'configurationFile' => 'EXT:install/Configuration/ExtensionScanner/Php/MethodCallMatcher.php',
145 ],
146 [
147 'class' => MethodCallStaticMatcher::class,
148 'configurationFile' => 'EXT:install/Configuration/ExtensionScanner/Php/MethodCallStaticMatcher.php',
149 ],
150 [
151 'class' => PropertyExistsStaticMatcher::class,
152 'configurationFile' => 'EXT:install/Configuration/ExtensionScanner/Php/PropertyExistsStaticMatcher.php'
153 ],
154 [
155 'class' => PropertyProtectedMatcher::class,
156 'configurationFile' => 'EXT:install/Configuration/ExtensionScanner/Php/PropertyProtectedMatcher.php',
157 ],
158 [
159 'class' => PropertyPublicMatcher::class,
160 'configurationFile' => 'EXT:install/Configuration/ExtensionScanner/Php/PropertyPublicMatcher.php',
161 ],
162 ];
163
164 /**
165 * Main "show the cards" view
166 *
167 * @param ServerRequestInterface $request
168 * @return ResponseInterface
169 */
170 public function cardsAction(ServerRequestInterface $request): ResponseInterface
171 {
172 $view = $this->initializeStandaloneView($request, 'Upgrade/Cards.html');
173 return new JsonResponse([
174 'success' => true,
175 'html' => $view->render(),
176 ]);
177 }
178
179 /**
180 * Activate a new core
181 *
182 * @param ServerRequestInterface $request
183 * @return ResponseInterface
184 */
185 public function coreUpdateActivateAction(ServerRequestInterface $request): ResponseInterface
186 {
187 $this->coreUpdateInitialize();
188 return new JsonResponse([
189 'success' => $this->coreUpdateService->activateVersion($this->coreUpdateGetVersionToHandle($request)),
190 'status' => $this->coreUpdateService->getMessages(),
191 ]);
192 }
193
194 /**
195 * Check if core update is possible
196 *
197 * @param ServerRequestInterface $request
198 * @return ResponseInterface
199 */
200 public function coreUpdateCheckPreConditionsAction(ServerRequestInterface $request): ResponseInterface
201 {
202 $this->coreUpdateInitialize();
203 return new JsonResponse([
204 'success' => $this->coreUpdateService->checkPreConditions($this->coreUpdateGetVersionToHandle($request)),
205 'status' => $this->coreUpdateService->getMessages(),
206 ]);
207 }
208
209 /**
210 * Download new core
211 *
212 * @param ServerRequestInterface $request
213 * @return ResponseInterface
214 */
215 public function coreUpdateDownloadAction(ServerRequestInterface $request): ResponseInterface
216 {
217 $this->coreUpdateInitialize();
218 return new JsonResponse([
219 'success' => $this->coreUpdateService->downloadVersion($this->coreUpdateGetVersionToHandle($request)),
220 'status' => $this->coreUpdateService->getMessages(),
221 ]);
222 }
223
224 /**
225 * Core Update Get Data Action
226 *
227 * @param ServerRequestInterface $request
228 * @return ResponseInterface
229 */
230 public function coreUpdateGetDataAction(ServerRequestInterface $request): ResponseInterface
231 {
232 $view = $this->initializeStandaloneView($request, 'Upgrade/CoreUpdate.html');
233 $coreUpdateService = GeneralUtility::makeInstance(CoreUpdateService::class);
234 $coreVersionService = GeneralUtility::makeInstance(CoreVersionService::class);
235 $view->assignMultiple([
236 'coreUpdateEnabled' => $coreUpdateService->isCoreUpdateEnabled(),
237 'coreUpdateComposerMode' => Environment::isComposerMode(),
238 'coreUpdateIsReleasedVersion' => $coreVersionService->isInstalledVersionAReleasedVersion(),
239 'coreUpdateIsSymLinkedCore' => is_link(Environment::getPublicPath() . '/typo3_src'),
240 ]);
241 return new JsonResponse([
242 'success' => true,
243 'html' => $view->render(),
244 ]);
245 }
246
247 /**
248 * Check for new core
249 *
250 * @return ResponseInterface
251 */
252 public function coreUpdateIsUpdateAvailableAction(): ResponseInterface
253 {
254 $this->coreUpdateInitialize();
255 $messageQueue = new FlashMessageQueue('install');
256 if ($this->coreVersionService->isInstalledVersionAReleasedVersion()) {
257 $isDevelopmentUpdateAvailable = $this->coreVersionService->isYoungerPatchDevelopmentReleaseAvailable();
258 $isUpdateAvailable = $this->coreVersionService->isYoungerPatchReleaseAvailable();
259 $isUpdateSecurityRelevant = $this->coreVersionService->isUpdateSecurityRelevant();
260 if (!$isUpdateAvailable && !$isDevelopmentUpdateAvailable) {
261 $messageQueue->enqueue(new FlashMessage(
262 '',
263 'No regular update available',
264 FlashMessage::NOTICE
265 ));
266 } elseif ($isUpdateAvailable) {
267 $newVersion = $this->coreVersionService->getYoungestPatchRelease();
268 if ($isUpdateSecurityRelevant) {
269 $messageQueue->enqueue(new FlashMessage(
270 '',
271 'Update to security relevant released version ' . $newVersion . ' is available!',
272 FlashMessage::WARNING
273 ));
274 $action = ['title' => 'Update now', 'action' => 'updateRegular'];
275 } else {
276 $messageQueue->enqueue(new FlashMessage(
277 '',
278 'Update to regular released version ' . $newVersion . ' is available!',
279 FlashMessage::INFO
280 ));
281 $action = ['title' => 'Update now', 'action' => 'updateRegular'];
282 }
283 } elseif ($isDevelopmentUpdateAvailable) {
284 $newVersion = $this->coreVersionService->getYoungestPatchDevelopmentRelease();
285 $messageQueue->enqueue(new FlashMessage(
286 '',
287 'Update to development release ' . $newVersion . ' is available!',
288 FlashMessage::INFO
289 ));
290 $action = ['title' => 'Update now', 'action' => 'updateDevelopment'];
291 }
292 } else {
293 $messageQueue->enqueue(new FlashMessage(
294 '',
295 'Current version is a development version and can not be updated',
296 FlashMessage::WARNING
297 ));
298 }
299 $responseData = [
300 'success' => true,
301 'status' => $messageQueue,
302 ];
303 if (isset($action)) {
304 $responseData['action'] = $action;
305 }
306 return new JsonResponse($responseData);
307 }
308
309 /**
310 * Move core to new location
311 *
312 * @param ServerRequestInterface $request
313 * @return ResponseInterface
314 */
315 public function coreUpdateMoveAction(ServerRequestInterface $request): ResponseInterface
316 {
317 $this->coreUpdateInitialize();
318 return new JsonResponse([
319 'success' => $this->coreUpdateService->moveVersion($this->coreUpdateGetVersionToHandle($request)),
320 'status' => $this->coreUpdateService->getMessages(),
321 ]);
322 }
323
324 /**
325 * Unpack a downloaded core
326 *
327 * @param ServerRequestInterface $request
328 * @return ResponseInterface
329 */
330 public function coreUpdateUnpackAction(ServerRequestInterface $request): ResponseInterface
331 {
332 $this->coreUpdateInitialize();
333 return new JsonResponse([
334 'success' => $this->coreUpdateService->unpackVersion($this->coreUpdateGetVersionToHandle($request)),
335 'status' => $this->coreUpdateService->getMessages(),
336 ]);
337 }
338
339 /**
340 * Verify downloaded core checksum
341 *
342 * @param ServerRequestInterface $request
343 * @return ResponseInterface
344 */
345 public function coreUpdateVerifyChecksumAction(ServerRequestInterface $request): ResponseInterface
346 {
347 $this->coreUpdateInitialize();
348 return new JsonResponse([
349 'success' => $this->coreUpdateService->verifyFileChecksum($this->coreUpdateGetVersionToHandle($request)),
350 'status' => $this->coreUpdateService->getMessages(),
351 ]);
352 }
353
354 /**
355 * Get list of loaded extensions
356 *
357 * @param ServerRequestInterface $request
358 * @return ResponseInterface
359 */
360 public function extensionCompatTesterLoadedExtensionListAction(ServerRequestInterface $request): ResponseInterface
361 {
362 $formProtection = FormProtectionFactory::get(InstallToolFormProtection::class);
363 $view = $this->initializeStandaloneView($request, 'Upgrade/ExtensionCompatTester.html');
364 $view->assignMultiple([
365 'extensionCompatTesterLoadExtLocalconfToken' => $formProtection->generateToken('installTool', 'extensionCompatTesterLoadExtLocalconf'),
366 'extensionCompatTesterLoadExtTablesToken' => $formProtection->generateToken('installTool', 'extensionCompatTesterLoadExtTables'),
367 'extensionCompatTesterUninstallToken' => $formProtection->generateToken('installTool', 'extensionCompatTesterUninstallExtension'),
368 ]);
369
370 return new JsonResponse([
371 'success' => true,
372 'extensions' => array_keys($GLOBALS['TYPO3_LOADED_EXT']),
373 'html' => $view->render(),
374 ]);
375 }
376
377 /**
378 * Load all ext_localconf files in order until given extension name
379 *
380 * @param ServerRequestInterface $request
381 * @return ResponseInterface
382 */
383 public function extensionCompatTesterLoadExtLocalconfAction(ServerRequestInterface $request): ResponseInterface
384 {
385 $extension = $request->getParsedBody()['install']['extension'];
386 foreach ($GLOBALS['TYPO3_LOADED_EXT'] as $extKey => $extDetails) {
387 $this->extensionCompatTesterLoadExtLocalconfForExtension($extKey, $extDetails);
388 if ($extKey === $extension) {
389 break;
390 }
391 }
392 return new JsonResponse([
393 'success' => true,
394 ]);
395 }
396
397 /**
398 * Load all ext_localconf files in order until given extension name
399 *
400 * @param ServerRequestInterface $request
401 * @return ResponseInterface
402 */
403 public function extensionCompatTesterLoadExtTablesAction(ServerRequestInterface $request): ResponseInterface
404 {
405 $extension = $request->getParsedBody()['install']['extension'];
406 foreach ($GLOBALS['TYPO3_LOADED_EXT'] as $extKey => $extDetails) {
407 // Load all ext_localconf files first
408 $this->extensionCompatTesterLoadExtLocalconfForExtension($extKey, $extDetails);
409 }
410 foreach ($GLOBALS['TYPO3_LOADED_EXT'] as $extKey => $extDetails) {
411 $this->extensionCompatTesterLoadExtTablesForExtension($extKey, $extDetails);
412 if ($extKey === $extension) {
413 break;
414 }
415 }
416 return new JsonResponse([
417 'success' => true,
418 ]);
419 }
420
421 /**
422 * Unload one extension
423 *
424 * @param ServerRequestInterface $request
425 * @return ResponseInterface
426 * @throws \RuntimeException
427 */
428 public function extensionCompatTesterUninstallExtensionAction(ServerRequestInterface $request): ResponseInterface
429 {
430 $extension = $request->getParsedBody()['install']['extension'];
431 if (empty($extension)) {
432 throw new \RuntimeException(
433 'No extension given',
434 1505407269
435 );
436 }
437 $messageQueue = new FlashMessageQueue('install');
438 if (ExtensionManagementUtility::isLoaded($extension)) {
439 try {
440 ExtensionManagementUtility::unloadExtension($extension);
441 $messageQueue->enqueue(new FlashMessage(
442 'Extension "' . $extension . '" unloaded.',
443 '',
444 FlashMessage::ERROR
445 ));
446 } catch (\Exception $e) {
447 $messageQueue->enqueue(new FlashMessage(
448 $e->getMessage(),
449 '',
450 FlashMessage::ERROR
451 ));
452 }
453 }
454 return new JsonResponse([
455 'success' => true,
456 'status' => $messageQueue,
457 ]);
458 }
459
460 /**
461 * Create Extension Scanner Data action
462 *
463 * @param ServerRequestInterface $request
464 * @return ResponseInterface
465 */
466 public function extensionScannerGetDataAction(ServerRequestInterface $request): ResponseInterface
467 {
468 $extensionsInTypo3conf = (new Finder())->directories()->in(Environment::getPublicPath() . '/typo3conf/ext')->depth(0)->sortByName();
469 $view = $this->initializeStandaloneView($request, 'Upgrade/ExtensionScanner.html');
470 $formProtection = FormProtectionFactory::get(InstallToolFormProtection::class);
471 $view->assignMultiple([
472 'extensionScannerExtensionList' => $extensionsInTypo3conf,
473 'extensionScannerFilesToken' => $formProtection->generateToken('installTool', 'extensionScannerFiles'),
474 'extensionScannerScanFileToken' => $formProtection->generateToken('installTool', 'extensionScannerScanFile'),
475 'extensionScannerMarkFullyScannedRestFilesToken' => $formProtection->generateToken('installTool', 'extensionScannerMarkFullyScannedRestFiles'),
476 ]);
477 return new JsonResponse([
478 'success' => true,
479 'html' => $view->render(),
480 ]);
481 }
482
483 /**
484 * Return a list of files of an extension
485 *
486 * @param ServerRequestInterface $request
487 * @return ResponseInterface
488 */
489 public function extensionScannerFilesAction(ServerRequestInterface $request): ResponseInterface
490 {
491 // Get and validate path
492 $extension = $request->getParsedBody()['install']['extension'];
493 $extensionBasePath = Environment::getPublicPath() . '/typo3conf/ext/' . $extension;
494 if (empty($extension) || !GeneralUtility::isAllowedAbsPath($extensionBasePath)) {
495 throw new \RuntimeException(
496 'Path to extension ' . $extension . ' not allowed.',
497 1499777261
498 );
499 }
500 if (!is_dir($extensionBasePath)) {
501 throw new \RuntimeException(
502 'Extension path ' . $extensionBasePath . ' does not exist or is no directory.',
503 1499777330
504 );
505 }
506
507 $finder = new Finder();
508 $files = $finder->files()->in($extensionBasePath)->name('*.php')->sortByName();
509 // A list of file names relative to extension directory
510 $relativeFileNames = [];
511 foreach ($files as $file) {
512 /** @var SplFileInfo $file */
513 $relativeFileNames[] = GeneralUtility::fixWindowsFilePath($file->getRelativePathname());
514 }
515 return new JsonResponse([
516 'success' => true,
517 'files' => $relativeFileNames,
518 ]);
519 }
520
521 /**
522 * Ajax controller, part of "extension scanner". Called at the end of "scan all"
523 * as last action. Gets a list of RST file hashes that matched, goes through all
524 * existing RST files, finds those marked as "FullyScanned" and marks those that
525 * did not had any matches as "you are not affected".
526 *
527 * @param ServerRequestInterface $request
528 * @return ResponseInterface
529 */
530 public function extensionScannerMarkFullyScannedRestFilesAction(ServerRequestInterface $request): ResponseInterface
531 {
532 $foundRestFileHashes = (array)$request->getParsedBody()['install']['hashes'];
533 // First un-mark files marked as scanned-ok
534 $registry = new Registry();
535 $registry->removeAllByNamespace('extensionScannerNotAffected');
536 // Find all .rst files (except those from v8), see if they are tagged with "FullyScanned"
537 // and if their content is not in incoming "hashes" array, mark as "not affected"
538 $documentationFile = new DocumentationFile();
539 $finder = new Finder();
540 $restFilesBasePath = ExtensionManagementUtility::extPath('core') . 'Documentation/Changelog';
541 $restFiles = $finder->files()->in($restFilesBasePath);
542 $fullyScannedRestFilesNotAffected = [];
543 foreach ($restFiles as $restFile) {
544 // Skip files in "8.x" directory
545 /** @var SplFileInfo $restFile */
546 if (strpos($restFile->getRelativePath(), '8') === 0) {
547 continue;
548 }
549
550 // Build array of file (hashes) not affected by current scan, if they are tagged as "FullyScanned"
551 $parsedRestFile = array_pop($documentationFile->getListEntry(str_replace(
552 '\\',
553 '/',
554 realpath($restFile->getPathname())
555 )));
556 if (!in_array($parsedRestFile['file_hash'], $foundRestFileHashes, true)
557 && in_array('FullyScanned', $parsedRestFile['tags'], true)
558 ) {
559 $fullyScannedRestFilesNotAffected[] = $parsedRestFile['file_hash'];
560 }
561 }
562 foreach ($fullyScannedRestFilesNotAffected as $fileHash) {
563 $registry->set('extensionScannerNotAffected', $fileHash, $fileHash);
564 }
565 return new JsonResponse([
566 'success' => true,
567 'markedAsNotAffected' => count($fullyScannedRestFilesNotAffected),
568 ]);
569 }
570
571 /**
572 * Scan a single extension file for breaking / deprecated core code usages
573 *
574 * @param ServerRequestInterface $request
575 * @return ResponseInterface
576 */
577 public function extensionScannerScanFileAction(ServerRequestInterface $request): ResponseInterface
578 {
579 // Get and validate path and file
580 $extension = $request->getParsedBody()['install']['extension'];
581 $extensionBasePath = Environment::getPublicPath() . '/typo3conf/ext/' . $extension;
582 if (empty($extension) || !GeneralUtility::isAllowedAbsPath($extensionBasePath)) {
583 throw new \RuntimeException(
584 'Path to extension ' . $extension . ' not allowed.',
585 1499789246
586 );
587 }
588 if (!is_dir($extensionBasePath)) {
589 throw new \RuntimeException(
590 'Extension path ' . $extensionBasePath . ' does not exist or is no directory.',
591 1499789259
592 );
593 }
594 $file = $request->getParsedBody()['install']['file'];
595 $absoluteFilePath = $extensionBasePath . '/' . $file;
596 if (empty($file) || !GeneralUtility::isAllowedAbsPath($absoluteFilePath)) {
597 throw new \RuntimeException(
598 'Path to file ' . $file . ' of extension ' . $extension . ' not allowed.',
599 1499789384
600 );
601 }
602 if (!is_file($absoluteFilePath)) {
603 throw new \RuntimeException(
604 'File ' . $file . ' not found or is not a file.',
605 1499789433
606 );
607 }
608
609 $parser = (new ParserFactory())->create(ParserFactory::PREFER_PHP7);
610 // Parse PHP file to AST and traverse tree calling visitors
611 $statements = $parser->parse(file_get_contents($absoluteFilePath));
612
613 $traverser = new NodeTraverser();
614 // The built in NameResolver translates class names shortened with 'use' to fully qualified
615 // class names at all places. Incredibly useful for us and added as first visitor.
616 $traverser->addVisitor(new NameResolver());
617 // Understand makeInstance('My\\Package\\Foo\\Bar') as fqdn class name in first argument
618 $traverser->addVisitor(new GeneratorClassesResolver());
619 // Count ignored lines, effective code lines, ...
620 $statistics = new CodeStatistics();
621 $traverser->addVisitor($statistics);
622
623 // Add all configured matcher classes
624 $matcherFactory = new MatcherFactory();
625 $matchers = $matcherFactory->createAll($this->matchers);
626 foreach ($matchers as $matcher) {
627 $traverser->addVisitor($matcher);
628 }
629
630 $traverser->traverse($statements);
631
632 // Gather code matches
633 $matches = [];
634 foreach ($matchers as $matcher) {
635 /** @var \TYPO3\CMS\Install\ExtensionScanner\CodeScannerInterface $matcher */
636 $matches = array_merge($matches, $matcher->getMatches());
637 }
638
639 // Prepare match output
640 $restFilesBasePath = ExtensionManagementUtility::extPath('core') . 'Documentation/Changelog';
641 $documentationFile = new DocumentationFile();
642 $preparedMatches = [];
643 foreach ($matches as $match) {
644 $preparedHit = [];
645 $preparedHit['uniqueId'] = str_replace('.', '', uniqid((string)mt_rand(), true));
646 $preparedHit['message'] = $match['message'];
647 $preparedHit['line'] = $match['line'];
648 $preparedHit['indicator'] = $match['indicator'];
649 $preparedHit['lineContent'] = $this->extensionScannerGetLineFromFile($absoluteFilePath, $match['line']);
650 $preparedHit['restFiles'] = [];
651 foreach ($match['restFiles'] as $fileName) {
652 $finder = new Finder();
653 $restFileLocation = $finder->files()->in($restFilesBasePath)->name($fileName);
654 if ($restFileLocation->count() !== 1) {
655 throw new \RuntimeException(
656 'ResT file ' . $fileName . ' not found or multiple files found.',
657 1499803909
658 );
659 }
660 foreach ($restFileLocation as $restFile) {
661 /** @var SplFileInfo $restFile */
662 $restFileLocation = $restFile->getPathname();
663 break;
664 }
665 $parsedRestFile = array_pop($documentationFile->getListEntry(str_replace(
666 '\\',
667 '/',
668 realpath($restFileLocation)
669 )));
670 $version = GeneralUtility::trimExplode(DIRECTORY_SEPARATOR, $restFileLocation);
671 array_pop($version);
672 // something like "8.2" .. "8.7" .. "master"
673 $parsedRestFile['version'] = array_pop($version);
674 $parsedRestFile['uniqueId'] = str_replace('.', '', uniqid((string)mt_rand(), true));
675 $preparedHit['restFiles'][] = $parsedRestFile;
676 }
677 $preparedMatches[] = $preparedHit;
678 }
679 return new JsonResponse([
680 'success' => true,
681 'matches' => $preparedMatches,
682 'isFileIgnored' => $statistics->isFileIgnored(),
683 'effectiveCodeLines' => $statistics->getNumberOfEffectiveCodeLines(),
684 'ignoredLines' => $statistics->getNumberOfIgnoredLines(),
685 ]);
686 }
687
688 /**
689 * Check if loading ext_tables.php files still changes TCA
690 *
691 * @param ServerRequestInterface $request
692 * @return ResponseInterface
693 */
694 public function tcaExtTablesCheckAction(ServerRequestInterface $request): ResponseInterface
695 {
696 $view = $this->initializeStandaloneView($request, 'Upgrade/TcaExtTablesCheck.html');
697 $messageQueue = new FlashMessageQueue('install');
698 $loadTcaService = GeneralUtility::makeInstance(LoadTcaService::class);
699 $loadTcaService->loadExtensionTablesWithoutMigration();
700 $baseTca = $GLOBALS['TCA'];
701 foreach ($GLOBALS['TYPO3_LOADED_EXT'] as $extensionKey => $extensionInformation) {
702 if ((is_array($extensionInformation) || $extensionInformation instanceof \ArrayAccess)
703 && $extensionInformation['ext_tables.php']
704 ) {
705 $loadTcaService->loadSingleExtTablesFile($extensionKey);
706 $newTca = $GLOBALS['TCA'];
707 if ($newTca !== $baseTca) {
708 $messageQueue->enqueue(new FlashMessage(
709 '',
710 $extensionKey,
711 FlashMessage::NOTICE
712 ));
713 }
714 $baseTca = $newTca;
715 }
716 }
717 return new JsonResponse([
718 'success' => true,
719 'status' => $messageQueue,
720 'html' => $view->render(),
721 ]);
722 }
723
724 /**
725 * Check TCA for needed migrations
726 *
727 * @param ServerRequestInterface $request
728 * @return ResponseInterface
729 */
730 public function tcaMigrationsCheckAction(ServerRequestInterface $request): ResponseInterface
731 {
732 $view = $this->initializeStandaloneView($request, 'Upgrade/TcaMigrationsCheck.html');
733 $messageQueue = new FlashMessageQueue('install');
734 GeneralUtility::makeInstance(LoadTcaService::class)->loadExtensionTablesWithoutMigration();
735 $tcaMigration = GeneralUtility::makeInstance(TcaMigration::class);
736 $GLOBALS['TCA'] = $tcaMigration->migrate($GLOBALS['TCA']);
737 $tcaMessages = $tcaMigration->getMessages();
738 foreach ($tcaMessages as $tcaMessage) {
739 $messageQueue->enqueue(new FlashMessage(
740 '',
741 $tcaMessage,
742 FlashMessage::NOTICE
743 ));
744 }
745 return new JsonResponse([
746 'success' => true,
747 'status' => $messageQueue,
748 'html' => $view->render(),
749 ]);
750 }
751
752 /**
753 * Render list of .rst files
754 *
755 * @param ServerRequestInterface $request
756 * @return ResponseInterface
757 */
758 public function upgradeDocsGetContentAction(ServerRequestInterface $request): ResponseInterface
759 {
760 $formProtection = FormProtectionFactory::get(InstallToolFormProtection::class);
761 $documentationFiles = $this->getDocumentationFiles();
762 $view = $this->initializeStandaloneView($request, 'Upgrade/UpgradeDocsGetContent.html');
763 $view->assignMultiple([
764 'upgradeDocsMarkReadToken' => $formProtection->generateToken('installTool', 'upgradeDocsMarkRead'),
765 'upgradeDocsUnmarkReadToken' => $formProtection->generateToken('installTool', 'upgradeDocsUnmarkRead'),
766 'upgradeDocsFiles' => $documentationFiles['normalFiles'],
767 'upgradeDocsReadFiles' => $documentationFiles['readFiles'],
768 'upgradeDocsNotAffectedFiles' => $documentationFiles['notAffectedFiles'],
769 ]);
770 return new JsonResponse([
771 'success' => true,
772 'html' => $view->render(),
773 ]);
774 }
775
776 /**
777 * Mark a .rst file as read
778 *
779 * @param ServerRequestInterface $request
780 * @return ResponseInterface
781 */
782 public function upgradeDocsMarkReadAction(ServerRequestInterface $request): ResponseInterface
783 {
784 $registry = new Registry();
785 $filePath = $request->getParsedBody()['install']['ignoreFile'];
786 $fileHash = md5_file($filePath);
787 $registry->set('upgradeAnalysisIgnoredFiles', $fileHash, $filePath);
788 return new JsonResponse([
789 'success' => true,
790 ]);
791 }
792
793 /**
794 * Mark a .rst file as not read
795 *
796 * @param ServerRequestInterface $request
797 * @return ResponseInterface
798 */
799 public function upgradeDocsUnmarkReadAction(ServerRequestInterface $request): ResponseInterface
800 {
801 $registry = new Registry();
802 $filePath = $request->getParsedBody()['install']['ignoreFile'];
803 $fileHash = md5_file($filePath);
804 $registry->remove('upgradeAnalysisIgnoredFiles', $fileHash);
805 return new JsonResponse([
806 'success' => true,
807 ]);
808 }
809
810 /**
811 * Check if new tables and fields should be added before executing wizards
812 *
813 * @return ResponseInterface
814 */
815 public function upgradeWizardsBlockingDatabaseAddsAction(): ResponseInterface
816 {
817 // ext_localconf, db and ext_tables must be loaded for the updates :(
818 $this->loadExtLocalconfDatabaseAndExtTables();
819 $upgradeWizardsService = new UpgradeWizardsService();
820 $adds = $upgradeWizardsService->getBlockingDatabaseAdds();
821 $needsUpdate = false;
822 if (!empty($adds)) {
823 $needsUpdate = true;
824 }
825 return new JsonResponse([
826 'success' => true,
827 'needsUpdate' => $needsUpdate,
828 'adds' => $adds,
829 ]);
830 }
831
832 /**
833 * Add new tables and fields
834 *
835 * @return ResponseInterface
836 */
837 public function upgradeWizardsBlockingDatabaseExecuteAction(): ResponseInterface
838 {
839 // ext_localconf, db and ext_tables must be loaded for the updates :(
840 $this->loadExtLocalconfDatabaseAndExtTables();
841 $upgradeWizardsService = new UpgradeWizardsService();
842 $upgradeWizardsService->addMissingTablesAndFields();
843 $messages = new FlashMessageQueue('install');
844 $messages->enqueue(new FlashMessage(
845 '',
846 'Added missing database fields and tables'
847 ));
848 return new JsonResponse([
849 'success' => true,
850 'status' => $messages,
851 ]);
852 }
853
854 /**
855 * Fix a broken DB charset setting
856 *
857 * @return ResponseInterface
858 */
859 public function upgradeWizardsBlockingDatabaseCharsetFixAction(): ResponseInterface
860 {
861 $upgradeWizardsService = new UpgradeWizardsService();
862 $upgradeWizardsService->setDatabaseCharsetUtf8();
863 $messages = new FlashMessageQueue('install');
864 $messages->enqueue(new FlashMessage(
865 '',
866 'Default connection database has been set to utf8'
867 ));
868 return new JsonResponse([
869 'success' => true,
870 'status' => $messages,
871 ]);
872 }
873
874 /**
875 * Test if database charset is ok
876 *
877 * @return ResponseInterface
878 */
879 public function upgradeWizardsBlockingDatabaseCharsetTestAction(): ResponseInterface
880 {
881 $upgradeWizardsService = new UpgradeWizardsService();
882 $result = !$upgradeWizardsService->isDatabaseCharsetUtf8();
883 return new JsonResponse([
884 'success' => true,
885 'needsUpdate' => $result,
886 ]);
887 }
888
889 /**
890 * Get list of upgrade wizards marked as done
891 *
892 * @return ResponseInterface
893 */
894 public function upgradeWizardsDoneUpgradesAction(): ResponseInterface
895 {
896 $this->loadExtLocalconfDatabaseAndExtTables();
897 $upgradeWizardsService = new UpgradeWizardsService();
898 $wizardsDone = $upgradeWizardsService->listOfWizardsDone();
899 $rowUpdatersDone = $upgradeWizardsService->listOfRowUpdatersDone();
900 $messages = new FlashMessageQueue('install');
901 if (empty($wizardsDone) && empty($rowUpdatersDone)) {
902 $messages->enqueue(new FlashMessage(
903 '',
904 'No wizards are marked as done'
905 ));
906 }
907 return new JsonResponse([
908 'success' => true,
909 'status' => $messages,
910 'wizardsDone' => $wizardsDone,
911 'rowUpdatersDone' => $rowUpdatersDone,
912 ]);
913 }
914
915 /**
916 * Execute one upgrade wizard
917 *
918 * @param ServerRequestInterface $request
919 * @return ResponseInterface
920 */
921 public function upgradeWizardsExecuteAction(ServerRequestInterface $request): ResponseInterface
922 {
923 // ext_localconf, db and ext_tables must be loaded for the updates :(
924 $this->loadExtLocalconfDatabaseAndExtTables();
925 $upgradeWizardsService = new UpgradeWizardsService();
926 $identifier = $request->getParsedBody()['install']['identifier'];
927 $showDatabaseQueries = (int)$request->getParsedBody()['install']['values']['showDatabaseQueries'];
928 $messages = $upgradeWizardsService->executeWizard($identifier, $showDatabaseQueries);
929 return new JsonResponse([
930 'success' => true,
931 'status' => $messages,
932 ]);
933 }
934
935 /**
936 * Input stage of a specific upgrade wizard
937 *
938 * @param ServerRequestInterface $request
939 * @return ResponseInterface
940 */
941 public function upgradeWizardsInputAction(ServerRequestInterface $request): ResponseInterface
942 {
943 // ext_localconf, db and ext_tables must be loaded for the updates :(
944 $this->loadExtLocalconfDatabaseAndExtTables();
945 $upgradeWizardsService = new UpgradeWizardsService();
946 $identifier = $request->getParsedBody()['install']['identifier'];
947 $result = $upgradeWizardsService->getWizardUserInput($identifier);
948 return new JsonResponse([
949 'success' => true,
950 'status' => [],
951 'userInput' => $result,
952 ]);
953 }
954
955 /**
956 * List available upgrade wizards
957 *
958 * @return ResponseInterface
959 */
960 public function upgradeWizardsListAction(): ResponseInterface
961 {
962 // ext_localconf, db and ext_tables must be loaded for the updates :(
963 $this->loadExtLocalconfDatabaseAndExtTables();
964 $upgradeWizardsService = new UpgradeWizardsService();
965 $wizards = $upgradeWizardsService->getUpgradeWizardsList();
966 return new JsonResponse([
967 'success' => true,
968 'status' => [],
969 'wizards' => $wizards,
970 ]);
971 }
972
973 /**
974 * Mark a wizard as "not done"
975 *
976 * @param ServerRequestInterface $request
977 * @return ResponseInterface
978 */
979 public function upgradeWizardsMarkUndoneAction(ServerRequestInterface $request): ResponseInterface
980 {
981 $this->loadExtLocalconfDatabaseAndExtTables();
982 $wizardToBeMarkedAsUndoneIdentifier = $request->getParsedBody()['install']['identifier'];
983 $upgradeWizardsService = new UpgradeWizardsService();
984 $result = $upgradeWizardsService->markWizardUndone($wizardToBeMarkedAsUndoneIdentifier);
985 $messages = new FlashMessageQueue('install');
986 if ($result) {
987 $messages->enqueue(new FlashMessage(
988 'Wizard has been marked undone'
989 ));
990 } else {
991 $messages->enqueue(new FlashMessage(
992 'Wizard has not been marked undone',
993 '',
994 FlashMessage::ERROR
995 ));
996 }
997 return new JsonResponse([
998 'success' => true,
999 'status' => $messages,
1000 ]);
1001 }
1002
1003 /**
1004 * Change install tool password
1005 *
1006 * @param ServerRequestInterface $request
1007 * @return ResponseInterface
1008 */
1009 public function upgradeWizardsGetDataAction(ServerRequestInterface $request): ResponseInterface
1010 {
1011 $view = $this->initializeStandaloneView($request, 'Upgrade/UpgradeWizards.html');
1012 $formProtection = FormProtectionFactory::get(InstallToolFormProtection::class);
1013 $view->assignMultiple([
1014 'upgradeWizardsMarkUndoneToken' => $formProtection->generateToken('installTool', 'upgradeWizardsMarkUndone'),
1015 'upgradeWizardsInputToken' => $formProtection->generateToken('installTool', 'upgradeWizardsInput'),
1016 'upgradeWizardsExecuteToken' => $formProtection->generateToken('installTool', 'upgradeWizardsExecute'),
1017 ]);
1018 return new JsonResponse([
1019 'success' => true,
1020 'html' => $view->render(),
1021 ]);
1022 }
1023
1024 /**
1025 * Execute silent database field adds like cache framework tables
1026 *
1027 * @return ResponseInterface
1028 */
1029 public function upgradeWizardsSilentUpgradesAction(): ResponseInterface
1030 {
1031 $this->loadExtLocalconfDatabaseAndExtTables();
1032 // Perform silent cache framework table upgrade
1033 $upgradeWizardsService = new UpgradeWizardsService();
1034 $statements = $upgradeWizardsService->silentCacheFrameworkTableSchemaMigration();
1035 $messages = new FlashMessageQueue('install');
1036 if (!empty($statements)) {
1037 $messages->enqueue(new FlashMessage(
1038 '',
1039 'Created some database cache tables.'
1040 ));
1041 }
1042 return new JsonResponse([
1043 'success' => true,
1044 'status' => $messages,
1045 ]);
1046 }
1047
1048 /**
1049 * Initialize the core upgrade actions
1050 *
1051 * @throws \RuntimeException
1052 */
1053 protected function coreUpdateInitialize()
1054 {
1055 $this->coreUpdateService = GeneralUtility::makeInstance(CoreUpdateService::class);
1056 $this->coreVersionService = GeneralUtility::makeInstance(CoreVersionService::class);
1057 if (!$this->coreUpdateService->isCoreUpdateEnabled()) {
1058 throw new \RuntimeException(
1059 'Core Update disabled in this environment',
1060 1381609294
1061 );
1062 }
1063 // @todo: Does the core updater really depend on loaded ext_* files?
1064 $this->loadExtLocalconfDatabaseAndExtTables();
1065 }
1066
1067 /**
1068 * Find out which version upgrade should be handled. This may
1069 * be different depending on whether development or regular release.
1070 *
1071 * @param ServerRequestInterface $request
1072 * @throws \RuntimeException
1073 * @return string Version to handle, eg. 6.2.2
1074 */
1075 protected function coreUpdateGetVersionToHandle(ServerRequestInterface $request): string
1076 {
1077 $type = $request->getQueryParams()['install']['type'];
1078 if (!isset($type) || empty($type)) {
1079 throw new \RuntimeException(
1080 'Type must be set to either "regular" or "development"',
1081 1380975303
1082 );
1083 }
1084 if ($type === 'development') {
1085 $versionToHandle = $this->coreVersionService->getYoungestPatchDevelopmentRelease();
1086 } else {
1087 $versionToHandle = $this->coreVersionService->getYoungestPatchRelease();
1088 }
1089 return $versionToHandle;
1090 }
1091
1092 /**
1093 * Loads ext_localconf.php for a single extension. Method is a modified copy of
1094 * the original bootstrap method.
1095 *
1096 * @param string $extensionKey
1097 * @param array $extension
1098 */
1099 protected function extensionCompatTesterLoadExtLocalconfForExtension($extensionKey, array $extension)
1100 {
1101 // This is the main array meant to be manipulated in the ext_localconf.php files
1102 // In general it is recommended to not rely on it to be globally defined in that
1103 // scope but to use $GLOBALS['TYPO3_CONF_VARS'] instead.
1104 // Nevertheless we define it here as global for backwards compatibility.
1105 global $TYPO3_CONF_VARS;
1106 $_EXTKEY = $extensionKey;
1107 if (isset($extension['ext_localconf.php']) && $extension['ext_localconf.php']) {
1108 // $_EXTKEY and $_EXTCONF are available in ext_localconf.php
1109 // and are explicitly set in cached file as well
1110 $_EXTCONF = $GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$_EXTKEY] ?? null;
1111 require $extension['ext_localconf.php'];
1112 }
1113 }
1114
1115 /**
1116 * Loads ext_tables.php for a single extension. Method is a modified copy of
1117 * the original bootstrap method.
1118 *
1119 * @param string $extensionKey
1120 * @param array $extension
1121 */
1122 protected function extensionCompatTesterLoadExtTablesForExtension($extensionKey, array $extension)
1123 {
1124 // In general it is recommended to not rely on it to be globally defined in that
1125 // scope, but we can not prohibit this without breaking backwards compatibility
1126 global $T3_SERVICES, $T3_VAR, $TYPO3_CONF_VARS;
1127 global $TBE_MODULES, $TBE_MODULES_EXT, $TCA;
1128 global $PAGES_TYPES, $TBE_STYLES;
1129 global $_EXTKEY;
1130 // Load each ext_tables.php file of loaded extensions
1131 $_EXTKEY = $extensionKey;
1132 if (isset($extension['ext_tables.php']) && $extension['ext_tables.php']) {
1133 // $_EXTKEY and $_EXTCONF are available in ext_tables.php
1134 // and are explicitly set in cached file as well
1135 $_EXTCONF = $GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf'][$_EXTKEY] ?? null;
1136 require $extension['ext_tables.php'];
1137 }
1138 }
1139
1140 /**
1141 * Get a list of '.rst' files and their details for "Upgrade documentation" view.
1142 *
1143 * @return array
1144 */
1145 protected function getDocumentationFiles(): array
1146 {
1147 $documentationFileService = new DocumentationFile();
1148 $documentationFiles = $documentationFileService->findDocumentationFiles(
1149 str_replace('\\', '/', realpath(ExtensionManagementUtility::extPath('core') . 'Documentation/Changelog'))
1150 );
1151 $documentationFiles = array_reverse($documentationFiles);
1152
1153 $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_registry');
1154 $filesMarkedAsRead = $queryBuilder
1155 ->select('*')
1156 ->from('sys_registry')
1157 ->where(
1158 $queryBuilder->expr()->eq(
1159 'entry_namespace',
1160 $queryBuilder->createNamedParameter('upgradeAnalysisIgnoredFiles', \PDO::PARAM_STR)
1161 )
1162 )
1163 ->execute()
1164 ->fetchAll();
1165 $hashesMarkedAsRead = [];
1166 foreach ($filesMarkedAsRead as $file) {
1167 $hashesMarkedAsRead[] = $file['entry_key'];
1168 }
1169
1170 $fileMarkedAsNotAffected = $queryBuilder
1171 ->select('*')
1172 ->from('sys_registry')
1173 ->where(
1174 $queryBuilder->expr()->eq(
1175 'entry_namespace',
1176 $queryBuilder->createNamedParameter('extensionScannerNotAffected', \PDO::PARAM_STR)
1177 )
1178 )
1179 ->execute()
1180 ->fetchAll();
1181 $hashesMarkedAsNotAffected = [];
1182 foreach ($fileMarkedAsNotAffected as $file) {
1183 $hashesMarkedAsNotAffected[] = $file['entry_key'];
1184 }
1185
1186 $readFiles = [];
1187 foreach ($documentationFiles as $section => &$files) {
1188 foreach ($files as $fileId => $fileData) {
1189 if (in_array($fileData['file_hash'], $hashesMarkedAsRead, true)) {
1190 $fileData['section'] = $section;
1191 $readFiles[$fileId] = $fileData;
1192 unset($files[$fileId]);
1193 }
1194 }
1195 }
1196
1197 $notAffectedFiles = [];
1198 foreach ($documentationFiles as $section => &$files) {
1199 foreach ($files as $fileId => $fileData) {
1200 if (in_array($fileData['file_hash'], $hashesMarkedAsNotAffected, true)) {
1201 $fileData['section'] = $section;
1202 $notAffectedFiles[$fileId] = $fileData;
1203 unset($files[$fileId]);
1204 }
1205 }
1206 }
1207
1208 return [
1209 'normalFiles' => $documentationFiles,
1210 'readFiles' => $readFiles,
1211 'notAffectedFiles' => $notAffectedFiles,
1212 ];
1213 }
1214
1215 /**
1216 * Find a code line in a file
1217 *
1218 * @param string $file Absolute path to file
1219 * @param int $lineNumber Find this line in file
1220 * @return string Code line
1221 */
1222 protected function extensionScannerGetLineFromFile(string $file, int $lineNumber): string
1223 {
1224 $fileContent = file($file, FILE_IGNORE_NEW_LINES);
1225 $line = '';
1226 if (isset($fileContent[$lineNumber - 1])) {
1227 $line = trim($fileContent[$lineNumber - 1]);
1228 }
1229 return $line;
1230 }
1231 }