Skip to content

Commit

Permalink
Add update script
Browse files Browse the repository at this point in the history
  • Loading branch information
riasvdv committed Dec 27, 2024
1 parent 451f09a commit b58c341
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/RedirectServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
use Rias\StatamicRedirect\Listeners\CreateRedirect;
use Rias\StatamicRedirect\Stache\Redirects\RedirectRepository as StacheRedirectRepository;
use Rias\StatamicRedirect\Stache\Redirects\RedirectStore;
use Rias\StatamicRedirect\UpdateScripts\AddDescriptionColumnToRedirectsTable;
use Rias\StatamicRedirect\UpdateScripts\AddHitsCount;
use Rias\StatamicRedirect\UpdateScripts\ClearErrors;
use Rias\StatamicRedirect\UpdateScripts\MoveRedirectsToDefaultSite;
Expand All @@ -43,6 +44,7 @@ class RedirectServiceProvider extends AddonServiceProvider
ClearErrors::class,
MoveRedirectsToDefaultSite::class,
RenameLocaleToSiteOnRedirectsTable::class,
AddDescriptionColumnToRedirectsTable::class,
];

protected $scripts = [
Expand Down
34 changes: 34 additions & 0 deletions src/UpdateScripts/AddDescriptionColumnToRedirectsTable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Rias\StatamicRedirect\UpdateScripts;

use Illuminate\Database\QueryException;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Schema;
use Statamic\UpdateScripts\UpdateScript;

class AddDescriptionColumnToRedirectsTable extends UpdateScript
{
public function shouldUpdate($newVersion, $oldVersion)
{
if (config('statamic.redirect.redirect_connection') === 'stache') {
return false;
}

try {
return ! Schema::connection(config('statamic.redirect.redirect_connection'))->hasColumn('redirects', 'description');
} catch (QueryException) {
// Query exception happens when database is not set up
return false;
}
}

public function update()
{
Artisan::call('vendor:publish', [
'--tag' => 'statamic-redirect-redirect-migrations'
]);

$this->console()->info('New migration for Redirect description published, make sure to it!');
}
}

0 comments on commit b58c341

Please sign in to comment.