|
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
|
|
|
use Backpack\CRUD\app\Console\Commands\Upgrade\StepStatus; |
|
8
|
|
|
use Backpack\CRUD\app\Console\Commands\Upgrade\UpgradeContext; |
|
9
|
|
|
use Backpack\CRUD\app\Console\Commands\Upgrade\Support\ConfigFilesHelper; |
|
10
|
|
|
|
|
11
|
|
|
class CheckShowOperationComponentConfigStep extends Step |
|
12
|
|
|
{ |
|
13
|
|
|
protected string $operationFilename = 'show.php'; |
|
14
|
|
|
|
|
15
|
|
|
protected bool $missingComponent = false; |
|
16
|
|
|
|
|
17
|
|
|
protected ConfigFilesHelper $configs; |
|
18
|
|
|
|
|
19
|
|
|
public function __construct(UpgradeContext $context) |
|
20
|
|
|
{ |
|
21
|
|
|
parent::__construct($context); |
|
22
|
|
|
|
|
23
|
|
|
$this->configs = new ConfigFilesHelper( |
|
24
|
|
|
$context, |
|
25
|
|
|
config_path('backpack/operations/show.php'), |
|
26
|
|
|
base_path('vendor/backpack/crud/src/config/backpack/operations/show.php') |
|
27
|
|
|
); |
|
28
|
|
|
} |
|
29
|
|
|
|
|
30
|
|
|
public function title(): string |
|
31
|
|
|
{ |
|
32
|
|
|
return 'Check if Show operation config has the component option'; |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
public function run(): StepResult |
|
36
|
|
|
{ |
|
37
|
|
|
$this->missingComponent = false; |
|
38
|
|
|
|
|
39
|
|
|
if (! $this->configs->configFilesPublished()) { |
|
40
|
|
|
return StepResult::skipped('show.php config file is not published, core defaults already use the new datagrid component.'); |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
|
|
if (! $this->configs->publishedFileContainsKey($this->operationFilename, 'component')) { |
|
44
|
|
|
$this->missingComponent = true; |
|
45
|
|
|
|
|
46
|
|
|
return StepResult::warning( |
|
47
|
|
|
"The 'component' key is missing from the show operation config file.", |
|
48
|
|
|
); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
return StepResult::success('Show operation config file already has the new "component" key.'); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
public function canFix(StepResult $result): bool |
|
55
|
|
|
{ |
|
56
|
|
|
return $result->status === StepStatus::Warning && $this->missingComponent; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public function fixMessage(StepResult $result): string |
|
60
|
|
|
{ |
|
61
|
|
|
return 'Add the component key to the config file?'; |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
public function fix(StepResult $result): StepResult |
|
65
|
|
|
{ |
|
66
|
|
|
if (! $this->configs->configFilesPublished()) { |
|
67
|
|
|
return StepResult::skipped('show.php config file is not published, core defaults already use the new datagrid component.'); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
if ($this->configs->publishedFileContainsKey($this->operationFilename, 'component')) { |
|
71
|
|
|
return StepResult::success('Show operation config already defines the component option.'); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
$relativePath = $this->configs->publishedRelativePath($this->operationFilename); |
|
75
|
|
|
$snippet = ' // Which component to use for displaying the Show page?'.PHP_EOL |
|
76
|
|
|
." 'component' => 'bp-datagrid', // options: bp-datagrid, bp-datalist, or a custom component alias"; |
|
77
|
|
|
|
|
78
|
|
|
$error = null; |
|
79
|
|
|
|
|
80
|
|
|
if (! $this->configs->addKeyToConfigFile($this->operationFilename, $snippet, $error)) { |
|
81
|
|
|
return StepResult::failure($error ?? 'Could not update show.php automatically.'); |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
$this->missingComponent = false; |
|
85
|
|
|
|
|
86
|
|
|
return StepResult::success("Added the 'component' option to {$relativePath}."); |
|
87
|
|
|
} |
|
88
|
|
|
} |
|
89
|
|
|
|