forked from riasvdv/statamic-redirect
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddDescriptionColumnToRedirectsTable.php
More file actions
53 lines (41 loc) · 1.56 KB
/
AddDescriptionColumnToRedirectsTable.php
File metadata and controls
53 lines (41 loc) · 1.56 KB
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
<?php
namespace Rias\StatamicRedirect\UpdateScripts;
use Illuminate\Database\QueryException;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Schema;
use Statamic\UpdateScripts\UpdateScript;
class AddDescriptionColumnToRedirectsTable extends UpdateScript
{
public function shouldUpdate($newVersion, $oldVersion)
{
$connection = config('statamic.redirect.redirect_connection');
if ($connection === 'stache') {
return false;
}
if ($connection === 'default') {
$connection = config('database.default');
}
try {
return ! Schema::connection($connection)->hasColumn('redirects', 'description');
} catch (QueryException) {
// Query exception happens when database is not set up
return false;
}
}
public function update()
{
$connection = config('statamic.redirect.redirect_connection');
if ($connection === 'redirect-sqlite') {
Schema::connection($connection)->table('redirects', function (Blueprint $table): void {
$table->text('description')->nullable()->after('enabled');
});
$this->console()->info('Added description field to the redirects table!');
return;
}
Artisan::call('vendor:publish', [
'--tag' => 'statamic-redirect-redirect-migrations',
]);
$this->console()->info('New migration for Redirect description published, make sure to run it!');
}
}