|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Backpack\CRUD\app\Console\Commands\Upgrade\v7\Steps; |
|
4
|
|
|
|
|
5
|
|
|
use Backpack\CRUD\app\Console\Commands\Upgrade\Step; |
|
6
|
|
|
use Backpack\CRUD\app\Console\Commands\Upgrade\StepResult; |
|
7
|
|
|
|
|
8
|
|
|
class DetectEditorAddonRequirementsStep extends Step |
|
9
|
|
|
{ |
|
10
|
|
|
protected array $editors = [ |
|
11
|
|
|
'ckeditor' => 'backpack/ckeditor-field', |
|
12
|
|
|
'tinymce' => 'backpack/tinymce-field', |
|
13
|
|
|
]; |
|
14
|
|
|
|
|
15
|
|
|
public function title(): string |
|
16
|
|
|
{ |
|
17
|
|
|
return 'Ensure rich text editor add-ons are installed'; |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
public function run(): StepResult |
|
21
|
|
|
{ |
|
22
|
|
|
$matches = $this->context()->searchTokens(array_keys($this->editors)); |
|
23
|
|
|
$issues = []; |
|
24
|
|
|
|
|
25
|
|
|
foreach ($this->editors as $keyword => $package) { |
|
26
|
|
|
$paths = $matches[$keyword] ?? []; |
|
27
|
|
|
|
|
28
|
|
|
if (empty($paths)) { |
|
29
|
|
|
continue; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
if ($this->context()->hasComposerPackage($package)) { |
|
33
|
|
|
continue; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
$preview = array_slice($paths, 0, 10); |
|
37
|
|
|
$details = array_map(fn ($path) => "- {$keyword} usage: {$path}", $preview); |
|
38
|
|
|
|
|
39
|
|
|
if (count($paths) > count($preview)) { |
|
40
|
|
|
$details[] = sprintf('… %d more occurrence(s) omitted.', count($paths) - count($preview)); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
$issues[] = [ |
|
44
|
|
|
'summary' => sprintf('Install %s to keep using the %s field/column.', $package, $keyword), |
|
45
|
|
|
'details' => $details, |
|
46
|
|
|
]; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
if (empty($issues)) { |
|
50
|
|
|
return StepResult::success('No missing editor add-ons detected.'); |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
$summary = 'Install the missing editor packages listed below.'; |
|
54
|
|
|
$detailLines = []; |
|
55
|
|
|
|
|
56
|
|
|
foreach ($issues as $issue) { |
|
57
|
|
|
$detailLines[] = $issue['summary']; |
|
58
|
|
|
$detailLines = array_merge($detailLines, $issue['details']); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
return StepResult::warning($summary, $detailLines); |
|
62
|
|
|
} |
|
63
|
|
|
} |
|
64
|
|
|
|