Skip to content

Commit 7508177

Browse files
committed
Add update script
1 parent 204fad6 commit 7508177

1 file changed

Lines changed: 52 additions & 0 deletions

File tree

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<?php
2+
3+
namespace Aerni\LivewireForms\UpdateScripts;
4+
5+
use Illuminate\Support\Facades\File;
6+
use Illuminate\Support\Str;
7+
use Statamic\UpdateScripts\UpdateScript;
8+
9+
class MigrateViewPath extends UpdateScript
10+
{
11+
public function shouldUpdate($newVersion, $oldVersion)
12+
{
13+
return $this->isUpdatingTo('10.3.0');
14+
}
15+
16+
public function update()
17+
{
18+
$configPath = config_path('livewire-forms.php');
19+
20+
if (! File::exists($configPath)) {
21+
return;
22+
}
23+
24+
$oldViewPath = config('livewire-forms.view_path');
25+
$oldAbsolutePath = resource_path("views/{$oldViewPath}");
26+
$livewireViewPath = config('livewire.view_path', resource_path('views/livewire'));
27+
28+
if (! str_starts_with($oldAbsolutePath, "{$livewireViewPath}/")) {
29+
$this->console()->warn("The 'view_path' config is now relative to Livewire's configured view path. Your custom value '{$oldViewPath}' could not be auto-migrated. Please update config/livewire-forms.php manually.");
30+
31+
return;
32+
}
33+
34+
$newViewPath = Str::after($oldAbsolutePath, "{$livewireViewPath}/");
35+
36+
if ($newViewPath === $oldViewPath) {
37+
return;
38+
}
39+
40+
$contents = File::get($configPath);
41+
42+
$contents = str_replace(
43+
"'view_path' => '{$oldViewPath}'",
44+
"'view_path' => '{$newViewPath}'",
45+
$contents,
46+
);
47+
48+
File::put($configPath, $contents);
49+
50+
$this->console()->info("Updated 'view_path' config from '{$oldViewPath}' to '{$newViewPath}'. The path is now relative to Livewire's configured view path.");
51+
}
52+
}

0 commit comments

Comments
 (0)