Skip to content

Commit

Permalink
Update InstallCommand.php
Browse files Browse the repository at this point in the history
  • Loading branch information
mooxbot committed Dec 9, 2023
1 parent aa6047d commit 4aabeb2
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions src/Commands/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Moox\Jobs\Commands;

use Illuminate\Console\Command;
use Illuminate\Support\Facades\File;

class InstallCommand extends Command
{
Expand Down Expand Up @@ -44,7 +45,45 @@ public function handle()
$this->comment('adrolli/filament-job-manager package uninstalled successfully.');
}

$this->comment('Running Migrations...');
$this->call('migrate');

$this->comment('Registering the Filament Resources...');

$providerPath = app_path('Providers/Filament/AdminPanelProvider.php');

if (File::exists($providerPath)) {

$content = File::get($providerPath);

$pluginsToAdd = [
'JobsPlugin::make(),',
'JobsWaitingPlugin::make(),',
'JobsFailedPlugin::make(),',
'JobsBatchesPlugin::make(),',
];

$pattern = '/->plugins\(\[([\s\S]*?)\]\);/';

$replacement = function ($matches) use ($pluginsToAdd) {
$existingPlugins = trim($matches[1]);
$newPlugins = implode("\n", $pluginsToAdd);

return "->plugins([\n".$existingPlugins."\n".$newPlugins."\n]);";
};

$newContent = preg_replace_callback($pattern, $replacement, $content);

File::put($providerPath, $newContent);

$this->info('Plugins added to AdminPanelProvider.');

} else {

$this->error('AdminPanelProvider not found.');

}

$this->info('Moox Jobs was installed successfully');
}
}

0 comments on commit 4aabeb2

Please sign in to comment.