/
UpgradeController.php
1347 lines (1254 loc) · 55.8 KB
/
UpgradeController.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
declare(strict_types=1);
/*
* This file is part of the TYPO3 CMS project.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*
* The TYPO3 project - inspiring people to share!
*/
namespace TYPO3\CMS\Install\Controller;
use PhpParser\NodeTraverser;
use PhpParser\NodeVisitor\NameResolver;
use PhpParser\ParserFactory;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;
use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\Database\Schema\Exception\StatementException;
use TYPO3\CMS\Core\FormProtection\FormProtectionFactory;
use TYPO3\CMS\Core\Http\JsonResponse;
use TYPO3\CMS\Core\Messaging\FlashMessage;
use TYPO3\CMS\Core\Messaging\FlashMessageQueue;
use TYPO3\CMS\Core\Migrations\TcaMigration;
use TYPO3\CMS\Core\Package\PackageInterface;
use TYPO3\CMS\Core\Package\PackageManager;
use TYPO3\CMS\Core\Registry;
use TYPO3\CMS\Core\Service\OpcodeCacheService;
use TYPO3\CMS\Core\Type\ContextualFeedbackSeverity;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\StringUtility;
use TYPO3\CMS\Install\CoreVersion\CoreRelease;
use TYPO3\CMS\Install\ExtensionScanner\CodeScannerInterface;
use TYPO3\CMS\Install\ExtensionScanner\Php\CodeStatistics;
use TYPO3\CMS\Install\ExtensionScanner\Php\GeneratorClassesResolver;
use TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\ArrayDimensionMatcher;
use TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\ArrayGlobalMatcher;
use TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\ClassConstantMatcher;
use TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\ClassNameMatcher;
use TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\ConstantMatcher;
use TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\ConstructorArgumentMatcher;
use TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\FunctionCallMatcher;
use TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\InterfaceMethodChangedMatcher;
use TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\MethodAnnotationMatcher;
use TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\MethodArgumentDroppedMatcher;
use TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\MethodArgumentDroppedStaticMatcher;
use TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\MethodArgumentRequiredMatcher;
use TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\MethodArgumentRequiredStaticMatcher;
use TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\MethodArgumentUnusedMatcher;
use TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\MethodCallMatcher;
use TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\MethodCallStaticMatcher;
use TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\PropertyAnnotationMatcher;
use TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\PropertyExistsStaticMatcher;
use TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\PropertyProtectedMatcher;
use TYPO3\CMS\Install\ExtensionScanner\Php\Matcher\PropertyPublicMatcher;
use TYPO3\CMS\Install\ExtensionScanner\Php\MatcherFactory;
use TYPO3\CMS\Install\Service\ClearCacheService;
use TYPO3\CMS\Install\Service\CoreUpdateService;
use TYPO3\CMS\Install\Service\CoreVersionService;
use TYPO3\CMS\Install\Service\DatabaseUpgradeWizardsService;
use TYPO3\CMS\Install\Service\LateBootService;
use TYPO3\CMS\Install\Service\LoadTcaService;
use TYPO3\CMS\Install\Service\UpgradeWizardsService;
use TYPO3\CMS\Install\UpgradeAnalysis\DocumentationFile;
/**
* Upgrade controller
* @internal This class is a specific controller implementation and is not considered part of the Public TYPO3 API.
*/
class UpgradeController extends AbstractController
{
/**
* @var CoreUpdateService
*/
protected $coreUpdateService;
/**
* @var CoreVersionService
*/
protected $coreVersionService;
public function __construct(
protected readonly PackageManager $packageManager,
private readonly LateBootService $lateBootService,
private readonly DatabaseUpgradeWizardsService $databaseUpgradeWizardsService,
private readonly FormProtectionFactory $formProtectionFactory
) {
}
/**
* Matcher registry of extension scanner.
* Node visitors that implement CodeScannerInterface
*
* @var array
*/
protected $matchers = [
[
'class' => ArrayDimensionMatcher::class,
'configurationFile' => 'EXT:install/Configuration/ExtensionScanner/Php/ArrayDimensionMatcher.php',
],
[
'class' => ArrayGlobalMatcher::class,
'configurationFile' => 'EXT:install/Configuration/ExtensionScanner/Php/ArrayGlobalMatcher.php',
],
[
'class' => ClassConstantMatcher::class,
'configurationFile' => 'EXT:install/Configuration/ExtensionScanner/Php/ClassConstantMatcher.php',
],
[
'class' => ClassNameMatcher::class,
'configurationFile' => 'EXT:install/Configuration/ExtensionScanner/Php/ClassNameMatcher.php',
],
[
'class' => ConstantMatcher::class,
'configurationFile' => 'EXT:install/Configuration/ExtensionScanner/Php/ConstantMatcher.php',
],
[
'class' => ConstructorArgumentMatcher::class,
'configurationFile' => 'EXT:install/Configuration/ExtensionScanner/Php/ConstructorArgumentMatcher.php',
],
[
'class' => PropertyAnnotationMatcher::class,
'configurationFile' => 'EXT:install/Configuration/ExtensionScanner/Php/PropertyAnnotationMatcher.php',
],
[
'class' => MethodAnnotationMatcher::class,
'configurationFile' => 'EXT:install/Configuration/ExtensionScanner/Php/MethodAnnotationMatcher.php',
],
[
'class' => FunctionCallMatcher::class,
'configurationFile' => 'EXT:install/Configuration/ExtensionScanner/Php/FunctionCallMatcher.php',
],
[
'class' => InterfaceMethodChangedMatcher::class,
'configurationFile' => 'EXT:install/Configuration/ExtensionScanner/Php/InterfaceMethodChangedMatcher.php',
],
[
'class' => MethodArgumentDroppedMatcher::class,
'configurationFile' => 'EXT:install/Configuration/ExtensionScanner/Php/MethodArgumentDroppedMatcher.php',
],
[
'class' => MethodArgumentDroppedStaticMatcher::class,
'configurationFile' => 'EXT:install/Configuration/ExtensionScanner/Php/MethodArgumentDroppedStaticMatcher.php',
],
[
'class' => MethodArgumentRequiredMatcher::class,
'configurationFile' => 'EXT:install/Configuration/ExtensionScanner/Php/MethodArgumentRequiredMatcher.php',
],
[
'class' => MethodArgumentRequiredStaticMatcher::class,
'configurationFile' => 'EXT:install/Configuration/ExtensionScanner/Php/MethodArgumentRequiredStaticMatcher.php',
],
[
'class' => MethodArgumentUnusedMatcher::class,
'configurationFile' => 'EXT:install/Configuration/ExtensionScanner/Php/MethodArgumentUnusedMatcher.php',
],
[
'class' => MethodCallMatcher::class,
'configurationFile' => 'EXT:install/Configuration/ExtensionScanner/Php/MethodCallMatcher.php',
],
[
'class' => MethodCallStaticMatcher::class,
'configurationFile' => 'EXT:install/Configuration/ExtensionScanner/Php/MethodCallStaticMatcher.php',
],
[
'class' => PropertyExistsStaticMatcher::class,
'configurationFile' => 'EXT:install/Configuration/ExtensionScanner/Php/PropertyExistsStaticMatcher.php',
],
[
'class' => PropertyProtectedMatcher::class,
'configurationFile' => 'EXT:install/Configuration/ExtensionScanner/Php/PropertyProtectedMatcher.php',
],
[
'class' => PropertyPublicMatcher::class,
'configurationFile' => 'EXT:install/Configuration/ExtensionScanner/Php/PropertyPublicMatcher.php',
],
];
/**
* Main "show the cards" view
*/
public function cardsAction(ServerRequestInterface $request): ResponseInterface
{
$view = $this->initializeView($request);
$hasExtensions = false;
foreach ($this->packageManager->getAvailablePackages() as $package) {
if (!$package->getPackageMetaData()->isExtensionType() || $package->getPackageMetaData()->isFrameworkType()) {
continue;
}
$hasExtensions = true;
break;
}
$view->assign('hasExtensions', $hasExtensions);
return new JsonResponse([
'success' => true,
'html' => $view->render('Upgrade/Cards'),
]);
}
/**
* Activate a new core
*/
public function coreUpdateActivateAction(ServerRequestInterface $request): ResponseInterface
{
$this->coreUpdateInitialize();
return new JsonResponse([
'success' => $this->coreUpdateService->activateVersion($this->coreUpdateGetVersionToHandle($request)),
'status' => $this->coreUpdateService->getMessages(),
]);
}
/**
* Check if core update is possible
*/
public function coreUpdateCheckPreConditionsAction(ServerRequestInterface $request): ResponseInterface
{
$this->coreUpdateInitialize();
return new JsonResponse([
'success' => $this->coreUpdateService->checkPreConditions($this->coreUpdateGetVersionToHandle($request)),
'status' => $this->coreUpdateService->getMessages(),
]);
}
/**
* Download new core
*/
public function coreUpdateDownloadAction(ServerRequestInterface $request): ResponseInterface
{
$this->coreUpdateInitialize();
return new JsonResponse([
'success' => $this->coreUpdateService->downloadVersion($this->coreUpdateGetVersionToHandle($request)),
'status' => $this->coreUpdateService->getMessages(),
]);
}
/**
* Core Update Get Data Action
*/
public function coreUpdateGetDataAction(ServerRequestInterface $request): ResponseInterface
{
$view = $this->initializeView($request);
$coreUpdateService = GeneralUtility::makeInstance(CoreUpdateService::class);
$coreVersionService = GeneralUtility::makeInstance(CoreVersionService::class);
$coreUpdateEnabled = $coreUpdateService->isCoreUpdateEnabled();
$coreUpdateComposerMode = Environment::isComposerMode();
$coreUpdateIsReleasedVersion = $coreVersionService->isInstalledVersionAReleasedVersion();
$coreUpdateIsSymLinkedCore = is_link(Environment::getPublicPath() . '/typo3_src');
$isUpdatable = !$coreUpdateComposerMode && $coreUpdateEnabled && $coreUpdateIsReleasedVersion && $coreUpdateIsSymLinkedCore;
$view->assignMultiple([
'coreIsUpdatable' => $isUpdatable,
'coreUpdateEnabled' => $coreUpdateEnabled,
'coreUpdateComposerMode' => $coreUpdateComposerMode,
'coreUpdateIsReleasedVersion' => $coreUpdateIsReleasedVersion,
'coreUpdateIsSymLinkedCore' => $coreUpdateIsSymLinkedCore,
]);
$buttons = [];
if ($isUpdatable) {
$buttons[] = [
'btnClass' => 'btn-warning t3js-coreUpdate-button t3js-coreUpdate-init',
'name' => 'coreUpdateCheckForUpdate',
'text' => 'Check for core updates',
];
}
return new JsonResponse([
'success' => true,
'html' => $view->render('Upgrade/CoreUpdate'),
'buttons' => $buttons,
]);
}
/**
* Check for new core
*/
public function coreUpdateIsUpdateAvailableAction(): ResponseInterface
{
$action = null;
$this->coreUpdateInitialize();
$messageQueue = new FlashMessageQueue('install');
$messages = [];
if ($this->coreVersionService->isInstalledVersionAReleasedVersion()) {
$versionMaintenanceWindow = $this->coreVersionService->getMaintenanceWindow();
$renderVersionInformation = false;
if (!$versionMaintenanceWindow->isSupportedByCommunity() && !$versionMaintenanceWindow->isSupportedByElts()) {
$messages[] = [
'title' => 'Outdated version',
'message' => 'The currently installed TYPO3 version ' . $this->coreVersionService->getInstalledVersion() . ' does not receive any further updates, please consider upgrading to a supported version!',
'severity' => ContextualFeedbackSeverity::ERROR,
];
$renderVersionInformation = true;
} else {
$currentVersion = $this->coreVersionService->getInstalledVersion();
$isCurrentVersionElts = $this->coreVersionService->isCurrentInstalledVersionElts();
$latestRelease = $this->coreVersionService->getYoungestPatchRelease();
$availableReleases = [];
if ($this->coreVersionService->isPatchReleaseSuitableForUpdate($latestRelease)) {
$availableReleases[] = $latestRelease;
if (!$latestRelease->isElts()) {
$action = ['title' => 'Update now to version ' . $latestRelease->getVersion(), 'action' => 'updateRegular'];
}
}
if (!$versionMaintenanceWindow->isSupportedByCommunity()) {
if ($latestRelease->isElts()) {
// Check if there's a public release left that's not installed yet
$latestCommunityDrivenRelease = $this->coreVersionService->getYoungestCommunityPatchRelease();
if ($this->coreVersionService->isPatchReleaseSuitableForUpdate($latestCommunityDrivenRelease)) {
$availableReleases[] = $latestCommunityDrivenRelease;
$action = ['title' => 'Update now to version ' . $latestCommunityDrivenRelease->getVersion(), 'action' => 'updateRegular'];
}
} elseif (!$isCurrentVersionElts) {
// Inform user about ELTS being available soon if:
// - regular support ran out
// - the current installed version is no ELTS
// - no ELTS update was released, yet
$messages[] = [
'title' => 'ELTS will be available soon',
'message' => sprintf('The currently installed TYPO3 version %s doesn\'t receive any community-driven updates anymore, consider subscribing to Extended Long Term Support (ELTS) releases. Please read the information below.', $currentVersion),
'severity' => ContextualFeedbackSeverity::WARNING,
];
$renderVersionInformation = true;
}
}
if ($availableReleases === []) {
$messages[] = [
'title' => 'Up to date',
'message' => 'There are no TYPO3 updates available.',
'severity' => ContextualFeedbackSeverity::NOTICE,
];
} else {
foreach ($availableReleases as $availableRelease) {
$isUpdateSecurityRelevant = $this->coreVersionService->isUpdateSecurityRelevant($availableRelease);
$versionString = $availableRelease->getVersion();
if ($availableRelease->isElts()) {
$versionString .= ' ELTS';
}
if ($isUpdateSecurityRelevant) {
$title = ($availableRelease->isElts() ? 'ELTS ' : '') . 'Security update available!';
$message = sprintf('The currently installed version is %s, update to security relevant released version %s is available.', $currentVersion, $versionString);
$severity = ContextualFeedbackSeverity::ERROR;
} else {
$title = ($availableRelease->isElts() ? 'ELTS ' : '') . 'Update available!';
$message = sprintf('Currently installed version is %s, update to regular released version %s is available.', $currentVersion, $versionString);
$severity = ContextualFeedbackSeverity::WARNING;
}
if ($availableRelease->isElts()) {
if ($isCurrentVersionElts) {
$message .= ' Please visit my.typo3.org to download the release in your ELTS area.';
} else {
$message .= ' ' . sprintf('The currently installed TYPO3 version %s doesn\'t receive any community-driven updates anymore, consider subscribing to Extended Long Term Support (ELTS) releases. Please read the information below.', $currentVersion);
}
$renderVersionInformation = true;
}
$messages[] = [
'title' => $title,
'message' => $message,
'severity' => $severity,
];
}
}
}
if ($renderVersionInformation) {
$supportedMajorReleases = $this->coreVersionService->getSupportedMajorReleases();
$supportMessages = [];
if (!empty($supportedMajorReleases['community'])) {
$supportMessages[] = sprintf('Currently community-supported TYPO3 versions: %s (more information at https://get.typo3.org).', implode(', ', $supportedMajorReleases['community']));
}
if (!empty($supportedMajorReleases['elts'])) {
$supportMessages[] = sprintf('Currently supported TYPO3 ELTS versions: %s (more information at https://typo3.com/elts).', implode(', ', $supportedMajorReleases['elts']));
}
$messages[] = [
'title' => 'TYPO3 Version information',
'message' => implode(' ', $supportMessages),
'severity' => ContextualFeedbackSeverity::INFO,
];
}
foreach ($messages as $message) {
$messageQueue->enqueue(new FlashMessage($message['message'], $message['title'], $message['severity']));
}
} else {
$messageQueue->enqueue(new FlashMessage(
'',
'Current version is a development version and can not be updated',
ContextualFeedbackSeverity::WARNING
));
}
$responseData = [
'success' => true,
'status' => $messageQueue,
];
if (isset($action)) {
$responseData['action'] = $action;
}
return new JsonResponse($responseData);
}
/**
* Move core to new location
*/
public function coreUpdateMoveAction(ServerRequestInterface $request): ResponseInterface
{
$this->coreUpdateInitialize();
return new JsonResponse([
'success' => $this->coreUpdateService->moveVersion($this->coreUpdateGetVersionToHandle($request)),
'status' => $this->coreUpdateService->getMessages(),
]);
}
/**
* Unpack a downloaded core
*/
public function coreUpdateUnpackAction(ServerRequestInterface $request): ResponseInterface
{
$this->coreUpdateInitialize();
return new JsonResponse([
'success' => $this->coreUpdateService->unpackVersion($this->coreUpdateGetVersionToHandle($request)),
'status' => $this->coreUpdateService->getMessages(),
]);
}
/**
* Verify downloaded core checksum
*/
public function coreUpdateVerifyChecksumAction(ServerRequestInterface $request): ResponseInterface
{
$this->coreUpdateInitialize();
return new JsonResponse([
'success' => $this->coreUpdateService->verifyFileChecksum($this->coreUpdateGetVersionToHandle($request)),
'status' => $this->coreUpdateService->getMessages(),
]);
}
/**
* Get list of loaded extensions
*/
public function extensionCompatTesterLoadedExtensionListAction(ServerRequestInterface $request): ResponseInterface
{
$formProtection = $this->formProtectionFactory->createFromRequest($request);
$view = $this->initializeView($request);
$view->assignMultiple([
'extensionCompatTesterLoadExtLocalconfToken' => $formProtection->generateToken('installTool', 'extensionCompatTesterLoadExtLocalconf'),
'extensionCompatTesterLoadExtTablesToken' => $formProtection->generateToken('installTool', 'extensionCompatTesterLoadExtTables'),
'extensionCompatTesterUninstallToken' => $formProtection->generateToken('installTool', 'extensionCompatTesterUninstallExtension'),
]);
return new JsonResponse([
'success' => true,
'html' => $view->render('Upgrade/ExtensionCompatTester'),
'buttons' => [
[
'btnClass' => 'btn-default disabled t3js-extensionCompatTester-check',
'text' => 'Check extensions',
],
],
]);
}
/**
* Load all ext_localconf files in order until given extension name
*/
public function extensionCompatTesterLoadExtLocalconfAction(ServerRequestInterface $request): ResponseInterface
{
$brokenExtensions = [];
$container = $this->lateBootService->getContainer();
$backup = $this->lateBootService->makeCurrent($container);
foreach ($this->packageManager->getActivePackages() as $package) {
try {
$this->extensionCompatTesterLoadExtLocalconfForExtension($package);
} catch (\Throwable $e) {
$brokenExtensions[] = [
'name' => $package->getPackageKey(),
'isProtected' => $package->isProtected(),
];
}
}
$this->lateBootService->makeCurrent(null, $backup);
return new JsonResponse([
'brokenExtensions' => $brokenExtensions,
], empty($brokenExtensions) ? 200 : 500);
}
/**
* Load all ext_localconf files in order until given extension name
*/
public function extensionCompatTesterLoadExtTablesAction(ServerRequestInterface $request): ResponseInterface
{
$brokenExtensions = [];
$container = $this->lateBootService->getContainer();
$backup = $this->lateBootService->makeCurrent($container);
$activePackages = $this->packageManager->getActivePackages();
foreach ($activePackages as $package) {
// Load all ext_localconf files first
$this->extensionCompatTesterLoadExtLocalconfForExtension($package);
}
foreach ($activePackages as $package) {
try {
$this->extensionCompatTesterLoadExtTablesForExtension($package);
} catch (\Throwable $e) {
$brokenExtensions[] = [
'name' => $package->getPackageKey(),
'isProtected' => $package->isProtected(),
];
}
}
$this->lateBootService->makeCurrent(null, $backup);
return new JsonResponse([
'brokenExtensions' => $brokenExtensions,
], empty($brokenExtensions) ? 200 : 500);
}
/**
* Unload one extension
*
* @throws \RuntimeException
*/
public function extensionCompatTesterUninstallExtensionAction(ServerRequestInterface $request): ResponseInterface
{
$extension = $request->getParsedBody()['install']['extension'];
if (empty($extension)) {
throw new \RuntimeException(
'No extension given',
1505407269
);
}
$messageQueue = new FlashMessageQueue('install');
if (ExtensionManagementUtility::isLoaded($extension)) {
try {
ExtensionManagementUtility::unloadExtension($extension);
GeneralUtility::makeInstance(ClearCacheService::class)->clearAll();
GeneralUtility::makeInstance(OpcodeCacheService::class)->clearAllActive();
$messageQueue->enqueue(new FlashMessage(
'Extension "' . $extension . '" unloaded.',
'',
ContextualFeedbackSeverity::ERROR
));
} catch (\Exception $e) {
$messageQueue->enqueue(new FlashMessage(
$e->getMessage(),
'',
ContextualFeedbackSeverity::ERROR
));
}
}
return new JsonResponse([
'success' => true,
'status' => $messageQueue,
]);
}
/**
* Create Extension Scanner Data action
*/
public function extensionScannerGetDataAction(ServerRequestInterface $request): ResponseInterface
{
$extensions = [];
foreach ($this->packageManager->getAvailablePackages() as $package) {
if (!$package->getPackageMetaData()->isExtensionType() || $package->getPackageMetaData()->isFrameworkType()) {
continue;
}
$extensions[] = $package->getPackageKey();
}
sort($extensions);
$view = $this->initializeView($request);
$formProtection = $this->formProtectionFactory->createFromRequest($request);
$view->assignMultiple([
'extensionScannerExtensionList' => $extensions,
'extensionScannerFilesToken' => $formProtection->generateToken('installTool', 'extensionScannerFiles'),
'extensionScannerScanFileToken' => $formProtection->generateToken('installTool', 'extensionScannerScanFile'),
'extensionScannerMarkFullyScannedRestFilesToken' => $formProtection->generateToken('installTool', 'extensionScannerMarkFullyScannedRestFiles'),
]);
return new JsonResponse([
'success' => true,
'html' => $view->render('Upgrade/ExtensionScanner'),
'buttons' => [
[
'btnClass' => 'btn-default t3js-extensionScanner-scan-all',
'text' => 'Scan all',
],
],
]);
}
/**
* Return a list of files of an extension
*/
public function extensionScannerFilesAction(ServerRequestInterface $request): ResponseInterface
{
// Get and validate path
$extension = $request->getParsedBody()['install']['extension'];
$extensionBasePath = $this->packageManager->getPackage($extension)->getPackagePath();
if (empty($extension) || !GeneralUtility::isAllowedAbsPath($extensionBasePath)) {
throw new \RuntimeException(
'Path to extension ' . $extension . ' not allowed.',
1499777261
);
}
if (!is_dir($extensionBasePath)) {
throw new \RuntimeException(
'Extension path ' . $extensionBasePath . ' does not exist or is no directory.',
1499777330
);
}
$finder = new Finder();
$files = $finder->files()->in($extensionBasePath)->name('*.php')->sortByName();
// A list of file names relative to extension directory
$relativeFileNames = [];
foreach ($files as $file) {
/** @var SplFileInfo $file */
$relativeFileNames[] = GeneralUtility::fixWindowsFilePath($file->getRelativePathname());
}
return new JsonResponse([
'success' => true,
'files' => $relativeFileNames,
]);
}
/**
* Ajax controller, part of "extension scanner". Called at the end of "scan all"
* as last action. Gets a list of RST file hashes that matched, goes through all
* existing RST files, finds those marked as "FullyScanned" and marks those that
* did not had any matches as "you are not affected".
*/
public function extensionScannerMarkFullyScannedRestFilesAction(ServerRequestInterface $request): ResponseInterface
{
$foundRestFileHashes = (array)($request->getParsedBody()['install']['hashes'] ?? []);
// First un-mark files marked as scanned-ok
$registry = new Registry();
$registry->removeAllByNamespace('extensionScannerNotAffected');
// Find all .rst files (except those from v8), see if they are tagged with "FullyScanned"
// and if their content is not in incoming "hashes" array, mark as "not affected"
$documentationFile = new DocumentationFile();
$finder = new Finder();
$restFilesBasePath = ExtensionManagementUtility::extPath('core') . 'Documentation/Changelog';
$restFiles = $finder->files()->in($restFilesBasePath);
$fullyScannedRestFilesNotAffected = [];
foreach ($restFiles as $restFile) {
// Skip files in "8.x" directory
/** @var SplFileInfo $restFile */
if (str_starts_with($restFile->getRelativePath(), '8')) {
continue;
}
// Build array of file (hashes) not affected by current scan, if they are tagged as "FullyScanned"
$listEntries = $documentationFile->getListEntry(str_replace(
'\\',
'/',
(string)realpath($restFile->getPathname())
));
$parsedRestFile = array_pop($listEntries);
if (!in_array($parsedRestFile['file_hash'], $foundRestFileHashes, true)
&& in_array('FullyScanned', $parsedRestFile['tags'], true)
) {
$fullyScannedRestFilesNotAffected[] = $parsedRestFile['file_hash'];
}
}
foreach ($fullyScannedRestFilesNotAffected as $fileHash) {
$registry->set('extensionScannerNotAffected', $fileHash, $fileHash);
}
return new JsonResponse([
'success' => true,
'markedAsNotAffected' => count($fullyScannedRestFilesNotAffected),
]);
}
/**
* Scan a single extension file for breaking / deprecated core code usages
*/
public function extensionScannerScanFileAction(ServerRequestInterface $request): ResponseInterface
{
// Get and validate path and file
$extension = $request->getParsedBody()['install']['extension'];
$extensionBasePath = $this->packageManager->getPackage($extension)->getPackagePath();
if (empty($extension) || !GeneralUtility::isAllowedAbsPath($extensionBasePath)) {
throw new \RuntimeException(
'Path to extension ' . $extension . ' not allowed.',
1499789246
);
}
if (!is_dir($extensionBasePath)) {
throw new \RuntimeException(
'Extension path ' . $extensionBasePath . ' does not exist or is no directory.',
1499789259
);
}
$file = $request->getParsedBody()['install']['file'];
$absoluteFilePath = $extensionBasePath . $file;
if (empty($file) || !GeneralUtility::isAllowedAbsPath($absoluteFilePath)) {
throw new \RuntimeException(
'Path to file ' . $file . ' of extension ' . $extension . ' not allowed.',
1499789384
);
}
if (!is_file($absoluteFilePath)) {
throw new \RuntimeException(
'File ' . $file . ' not found or is not a file.',
1499789433
);
}
$parser = (new ParserFactory())->create(ParserFactory::ONLY_PHP7);
// Parse PHP file to AST and traverse tree calling visitors
$statements = $parser->parse(file_get_contents($absoluteFilePath));
// The built in NameResolver translates class names shortened with 'use' to fully qualified
// class names at all places. Incredibly useful for us and added as first visitor.
// IMPORTANT: first process completely to resolve fully qualified names of arguments
// (otherwise GeneratorClassesResolver will NOT get reliable results)
$traverser = new NodeTraverser();
$traverser->addVisitor(new NameResolver());
$statements = $traverser->traverse($statements);
// IMPORTANT: second process to actually work on the pre-resolved statements
$traverser = new NodeTraverser();
// Understand GeneralUtility::makeInstance('My\\Package\\Foo\\Bar') as fqdn class name in first argument
$traverser->addVisitor(new GeneratorClassesResolver());
// Count ignored lines, effective code lines, ...
$statistics = new CodeStatistics();
$traverser->addVisitor($statistics);
// Add all configured matcher classes
$matcherFactory = new MatcherFactory();
$matchers = $matcherFactory->createAll($this->matchers);
foreach ($matchers as $matcher) {
$traverser->addVisitor($matcher);
}
$traverser->traverse($statements);
// Gather code matches
$matches = [[]];
foreach ($matchers as $matcher) {
/** @var CodeScannerInterface $matcher */
$matches[] = $matcher->getMatches();
}
$matches = array_merge(...$matches);
// Prepare match output
$restFilesBasePath = ExtensionManagementUtility::extPath('core') . 'Documentation/Changelog';
$documentationFile = new DocumentationFile();
$preparedMatches = [];
foreach ($matches as $match) {
$preparedHit = [];
$preparedHit['uniqueId'] = StringUtility::getUniqueId();
$preparedHit['message'] = $match['message'];
$preparedHit['line'] = $match['line'];
$preparedHit['indicator'] = $match['indicator'];
$preparedHit['lineContent'] = $this->extensionScannerGetLineFromFile($absoluteFilePath, $match['line']);
$preparedHit['restFiles'] = [];
foreach ($match['restFiles'] as $fileName) {
$finder = new Finder();
$restFileLocation = $finder->files()->in($restFilesBasePath)->name($fileName);
if ($restFileLocation->count() !== 1) {
throw new \RuntimeException(
'ResT file ' . $fileName . ' not found or multiple files found.',
1499803909
);
}
foreach ($restFileLocation as $restFile) {
/** @var SplFileInfo $restFile */
$restFileLocation = $restFile->getPathname();
break;
}
$listEntries = $documentationFile->getListEntry(str_replace(
'\\',
'/',
(string)realpath($restFileLocation)
));
$parsedRestFile = array_pop($listEntries);
$version = GeneralUtility::trimExplode(DIRECTORY_SEPARATOR, $restFileLocation);
array_pop($version);
// something like "8.2" .. "8.7" .. "master"
$parsedRestFile['version'] = array_pop($version);
$parsedRestFile['uniqueId'] = StringUtility::getUniqueId();
$preparedHit['restFiles'][] = $parsedRestFile;
}
$preparedMatches[] = $preparedHit;
}
return new JsonResponse([
'success' => true,
'matches' => $preparedMatches,
'isFileIgnored' => $statistics->isFileIgnored(),
'effectiveCodeLines' => $statistics->getNumberOfEffectiveCodeLines(),
'ignoredLines' => $statistics->getNumberOfIgnoredLines(),
]);
}
/**
* Check if loading ext_tables.php files still changes TCA
*/
public function tcaExtTablesCheckAction(ServerRequestInterface $request): ResponseInterface
{
$view = $this->initializeView($request);
$messageQueue = new FlashMessageQueue('install');
$loadTcaService = GeneralUtility::makeInstance(LoadTcaService::class);
$loadTcaService->loadExtensionTablesWithoutMigration();
$baseTca = $GLOBALS['TCA'];
$container = $this->lateBootService->getContainer();
$backup = $this->lateBootService->makeCurrent($container);
foreach ($this->packageManager->getActivePackages() as $package) {
$this->extensionCompatTesterLoadExtLocalconfForExtension($package);
$extensionKey = $package->getPackageKey();
$extTablesPath = $package->getPackagePath() . 'ext_tables.php';
if (@file_exists($extTablesPath)) {
$loadTcaService->loadSingleExtTablesFile($extensionKey);
$newTca = $GLOBALS['TCA'];
if ($newTca !== $baseTca) {
$messageQueue->enqueue(new FlashMessage(
'',
$extensionKey,
ContextualFeedbackSeverity::NOTICE
));
}
$baseTca = $newTca;
}
}
$this->lateBootService->makeCurrent(null, $backup);
return new JsonResponse([
'success' => true,
'status' => $messageQueue,
'html' => $view->render('Upgrade/TcaExtTablesCheck'),
'buttons' => [
[
'btnClass' => 'btn-default t3js-tcaExtTablesCheck-check',
'text' => 'Check loaded extensions',
],
],
]);
}
/**
* Check TCA for needed migrations
*/
public function tcaMigrationsCheckAction(ServerRequestInterface $request): ResponseInterface
{
$view = $this->initializeView($request);
$messageQueue = new FlashMessageQueue('install');
GeneralUtility::makeInstance(LoadTcaService::class)->loadExtensionTablesWithoutMigration();
$tcaMigration = GeneralUtility::makeInstance(TcaMigration::class);
$GLOBALS['TCA'] = $tcaMigration->migrate($GLOBALS['TCA']);
$tcaMessages = $tcaMigration->getMessages();
foreach ($tcaMessages as $tcaMessage) {
$messageQueue->enqueue(new FlashMessage(
'',
$tcaMessage,
ContextualFeedbackSeverity::NOTICE
));
}
return new JsonResponse([
'success' => true,
'status' => $messageQueue,
'html' => $view->render('Upgrade/TcaMigrationsCheck'),
'buttons' => [
[
'btnClass' => 'btn-default t3js-tcaMigrationsCheck-check',
'text' => 'Check TCA Migrations',
],
],
]);
}
/**
* Render list of versions
*/
public function upgradeDocsGetContentAction(ServerRequestInterface $request): ResponseInterface
{
$formProtection = $this->formProtectionFactory->createFromRequest($request);
$documentationDirectories = $this->getDocumentationDirectories();
$view = $this->initializeView($request);
$view->assignMultiple([
'upgradeDocsMarkReadToken' => $formProtection->generateToken('installTool', 'upgradeDocsMarkRead'),
'upgradeDocsUnmarkReadToken' => $formProtection->generateToken('installTool', 'upgradeDocsUnmarkRead'),
'upgradeDocsVersions' => $documentationDirectories,
]);
return new JsonResponse([
'success' => true,
'html' => $view->render('Upgrade/UpgradeDocsGetContent'),
]);
}
/**
* Render list of .rst files
*/
public function upgradeDocsGetChangelogForVersionAction(ServerRequestInterface $request): ResponseInterface
{
$version = $request->getQueryParams()['install']['version'] ?? '';
$this->assertValidVersion($version);
$documentationFiles = $this->getDocumentationFiles($version);
$view = $this->initializeView($request);
$view->assignMultiple([
'upgradeDocsFiles' => $documentationFiles['normalFiles'],
'upgradeDocsReadFiles' => $documentationFiles['readFiles'],
'upgradeDocsNotAffectedFiles' => $documentationFiles['notAffectedFiles'],
]);
return new JsonResponse([
'success' => true,
'html' => $view->render('Upgrade/UpgradeDocsGetChangelogForVersion'),
]);
}
/**
* Mark a .rst file as read
*/
public function upgradeDocsMarkReadAction(ServerRequestInterface $request): ResponseInterface
{
$registry = new Registry();
$filePath = $request->getParsedBody()['install']['ignoreFile'];
$fileHash = md5_file($filePath);
$registry->set('upgradeAnalysisIgnoredFiles', $fileHash, $filePath);
return new JsonResponse([
'success' => true,
]);
}
/**
* Mark a .rst file as not read
*/
public function upgradeDocsUnmarkReadAction(ServerRequestInterface $request): ResponseInterface
{
$registry = new Registry();
$filePath = $request->getParsedBody()['install']['ignoreFile'];
$fileHash = md5_file($filePath);
$registry->remove('upgradeAnalysisIgnoredFiles', $fileHash);
return new JsonResponse([
'success' => true,
]);
}
/**
* Check if new tables and fields should be added before executing wizards
*/
public function upgradeWizardsBlockingDatabaseAddsAction(): ResponseInterface
{
// ext_localconf, db and ext_tables must be loaded for the updates :(
$this->lateBootService->loadExtLocalconfDatabaseAndExtTables(false);
$adds = [];
$needsUpdate = false;
try {
$adds = $this->databaseUpgradeWizardsService->getBlockingDatabaseAdds();
$this->lateBootService->resetGlobalContainer();
if (!empty($adds)) {
$needsUpdate = true;
}
} catch (StatementException $exception) {
$needsUpdate = true;
}
return new JsonResponse([
'success' => true,
'needsUpdate' => $needsUpdate,
'adds' => $adds,
]);
}
/**
* Add new tables and fields
*/
public function upgradeWizardsBlockingDatabaseExecuteAction(): ResponseInterface
{
// ext_localconf, db and ext_tables must be loaded for the updates :(
$this->lateBootService->loadExtLocalconfDatabaseAndExtTables(false);
$errors = $this->databaseUpgradeWizardsService->addMissingTablesAndFields();