Skip to content
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
.phpunit.result.cache

/.idea
/vendor
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,10 @@
use TimoKoerber\LaravelOneTimeOperations\Models\Operation;
use TimoKoerber\LaravelOneTimeOperations\OneTimeOperationManager;

class CreateOneTimeOperationsTable extends Migration
{
protected string $name;

public function __construct()
{
$this->name = OneTimeOperationManager::getTableName();
}

return new class () extends Migration {
public function up()
{
Schema::create($this->name, function (Blueprint $table) {
Schema::create(OneTimeOperationManager::getTableName(), function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->enum('dispatched', [Operation::DISPATCHED_SYNC, Operation::DISPATCHED_ASYNC]);
Expand All @@ -27,6 +19,6 @@ public function up()

public function down()
{
Schema::dropIfExists($this->name);
Schema::dropIfExists(OneTimeOperationManager::getTableName());
}
}
};
31 changes: 25 additions & 6 deletions src/Providers/OneTimeOperationsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace TimoKoerber\LaravelOneTimeOperations\Providers;

use Illuminate\Filesystem\Filesystem;
use Illuminate\Support\ServiceProvider;
use TimoKoerber\LaravelOneTimeOperations\Commands\OneTimeOperationShowCommand;
use TimoKoerber\LaravelOneTimeOperations\Commands\OneTimeOperationsMakeCommand;
Expand All @@ -11,16 +12,22 @@ class OneTimeOperationsServiceProvider extends ServiceProvider
{
public function boot(): void
{
$this->loadMigrationsFrom([__DIR__.'/../../database/migrations']);

$this->publishes([
__DIR__.'/../../config/one-time-operations.php' => config_path('one-time-operations.php'),
]);

if ($this->app->runningInConsole()) {
$this->commands(OneTimeOperationsMakeCommand::class);
$this->commands(OneTimeOperationsProcessCommand::class);
$this->commands(OneTimeOperationShowCommand::class);

$this->publishes([
__DIR__.'/../../config/one-time-operations.php' => config_path('one-time-operations.php'),
], 'one-time-operations-config');

$this->publishes([
__DIR__.'/../../database/migrations/2023_02_28_000000_create_one_time_operations_table.php' => database_path('migrations/'.date('Y_m_d_His', time()).'_create_one_time_operations_table.php'),
], 'one-time-operations-migrations');

if (! $this->migrationFileExists()) {
$this->loadMigrationsFrom([__DIR__.'/../../database/migrations']);
}
}
}

Expand All @@ -30,4 +37,16 @@ public function register()
__DIR__.'/../../config/one-time-operations.php', 'one-time-operations'
);
}

protected function migrationFileExists(): bool
{
$files = $this->app->make(Filesystem::class)->glob(sprintf(
'%s%s%s',
database_path('migrations'),
DIRECTORY_SEPARATOR,
'*_create_one_time_operations_table.php'
));

return count($files) > 0;
}
}