Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
2 changes: 2 additions & 0 deletions config/one-time-operations.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@
// Database Connection Name - Change the model connection, support for Multitenancy
// Only change when you want to deviate from your system default repository
'connection' => null,

'model' => \TimoKoerber\LaravelOneTimeOperations\Models\Operation::class,
];
4 changes: 2 additions & 2 deletions src/Commands/OneTimeOperationShowCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use Illuminate\Support\Collection;
use Throwable;
use TimoKoerber\LaravelOneTimeOperations\Commands\Utils\OperationsLineElement;
use TimoKoerber\LaravelOneTimeOperations\Models\Operation;
use TimoKoerber\LaravelOneTimeOperations\Models\ModelFactory;
use TimoKoerber\LaravelOneTimeOperations\OneTimeOperationFile;
use TimoKoerber\LaravelOneTimeOperations\OneTimeOperationManager;

Expand Down Expand Up @@ -75,7 +75,7 @@ protected function shouldDisplayByFilter(string $filterName): bool

protected function getOperationLinesForOutput(): Collection
{
$operationModels = Operation::all();
$operationModels = ModelFactory::instance()->all();
$operationFiles = OneTimeOperationManager::getAllOperationFiles();
$operationOutputLines = collect();

Expand Down
7 changes: 4 additions & 3 deletions src/Commands/OneTimeOperationsProcessCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
namespace TimoKoerber\LaravelOneTimeOperations\Commands;

use Illuminate\Contracts\Console\Isolatable;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Arr;
use Illuminate\Support\Collection;
use TimoKoerber\LaravelOneTimeOperations\Jobs\OneTimeOperationProcessJob;
use TimoKoerber\LaravelOneTimeOperations\Models\Operation;
use TimoKoerber\LaravelOneTimeOperations\Models\ModelFactory;
use TimoKoerber\LaravelOneTimeOperations\OneTimeOperationFile;
use TimoKoerber\LaravelOneTimeOperations\OneTimeOperationManager;

Expand Down Expand Up @@ -90,7 +91,7 @@ protected function processOperationFile(OneTimeOperationFile $operationFile): in
return self::SUCCESS;
}

protected function processOperationModel(Operation $operationModel): int
protected function processOperationModel(Model $operationModel): int
{
if (! $this->components->confirm('Operation was processed before. Process it again?')) {
$this->components->info('Operation aborted');
Expand Down Expand Up @@ -155,7 +156,7 @@ protected function storeOperation(OneTimeOperationFile $operationFile): void
return;
}

Operation::storeOperation($operationFile->getOperationName(), $this->isAsyncMode($operationFile));
ModelFactory::instance()->storeOperation($operationFile->getOperationName(), $this->isAsyncMode($operationFile));
}

protected function dispatchOperationJob(OneTimeOperationFile $operationFile)
Expand Down
32 changes: 32 additions & 0 deletions src/Models/ModelFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

namespace TimoKoerber\LaravelOneTimeOperations\Models;

use Illuminate\Foundation\Application;

class ModelFactory
{

private $model;

public function __construct(Application $app)
{
$this->model = $app['config']->get('one-time-operations.model', Operation::class);
}

/**
* @return Operation
*/
public function model()
{
return new $this->model;
}

/**
* @return Operation
*/
public static function instance()
{
return app(self::class)->model();
}
}
7 changes: 4 additions & 3 deletions src/OneTimeOperationFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@

namespace TimoKoerber\LaravelOneTimeOperations;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
use SplFileInfo;
use TimoKoerber\LaravelOneTimeOperations\Models\Operation;
use TimoKoerber\LaravelOneTimeOperations\Models\ModelFactory;

class OneTimeOperationFile
{
Expand Down Expand Up @@ -40,8 +41,8 @@ public function getClassObject(): OneTimeOperation
return $this->classObject;
}

public function getModel(): ?Operation
public function getModel(): ?Model
{
return Operation::whereName($this->getOperationName())->first();
return ModelFactory::instance()->whereName($this->getOperationName())->first();
}
}
11 changes: 6 additions & 5 deletions src/OneTimeOperationManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,15 @@
namespace TimoKoerber\LaravelOneTimeOperations;

use Illuminate\Contracts\Filesystem\FileNotFoundException;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\App;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\File;
use Illuminate\Support\Str;
use SplFileInfo;
use Symfony\Component\Finder\Exception\DirectoryNotFoundException;
use TimoKoerber\LaravelOneTimeOperations\Models\Operation;
use TimoKoerber\LaravelOneTimeOperations\Models\ModelFactory;

class OneTimeOperationManager
{
Expand Down Expand Up @@ -44,7 +45,7 @@ public static function getUnprocessedFiles(): Collection
return $allOperationFiles->filter(function (SplFileInfo $operationFilepath) {
$operation = self::getOperationNameFromFilename($operationFilepath->getBasename());

return Operation::whereName($operation)->doesntExist();
return ModelFactory::instance()->whereName($operation)->doesntExist();
});
}

Expand All @@ -67,12 +68,12 @@ public static function getClassObjectByName(string $operationName): OneTimeOpera
return File::getRequire($filepath);
}

public static function getModelByName(string $operationName): ?Operation
public static function getModelByName(string $operationName): ?Model
{
return Operation::whereName($operationName)->first();
return ModelFactory::instance()->whereName($operationName)->first();
}

public static function getOperationFileByModel(Operation $operationModel): OneTimeOperationFile
public static function getOperationFileByModel(Model $operationModel): OneTimeOperationFile
{
$filepath = self::pathToFileByName($operationModel->name);

Expand Down
11 changes: 8 additions & 3 deletions src/Providers/OneTimeOperationsServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@
use TimoKoerber\LaravelOneTimeOperations\Commands\OneTimeOperationShowCommand;
use TimoKoerber\LaravelOneTimeOperations\Commands\OneTimeOperationsMakeCommand;
use TimoKoerber\LaravelOneTimeOperations\Commands\OneTimeOperationsProcessCommand;
use TimoKoerber\LaravelOneTimeOperations\Models\ModelFactory;

class OneTimeOperationsServiceProvider extends ServiceProvider
{
public array $singletons = [
ModelFactory::class
];

public function boot(): void
{
$this->loadMigrationsFrom([__DIR__.'/../../database/migrations']);
$this->loadMigrationsFrom([__DIR__ . '/../../database/migrations']);

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

if ($this->app->runningInConsole()) {
Expand All @@ -27,7 +32,7 @@ public function boot(): void
public function register()
{
$this->mergeConfigFrom(
__DIR__.'/../../config/one-time-operations.php', 'one-time-operations'
__DIR__ . '/../../config/one-time-operations.php', 'one-time-operations'
);
}
}