From 81028c493f2aea4379ff18565eef420b3611fe8d Mon Sep 17 00:00:00 2001 From: raza9798 Date: Mon, 17 Jun 2024 21:00:33 +0530 Subject: [PATCH] rapid kit support on progress --- src/Console/Commands/InitilizeCommand.php | 11 +++++- .../Commands/RapidKitSupportCommand.php | 30 +++++++++++++++ src/Controller/BackupController.php | 37 +++++++++++++++++++ src/RapidKitProvider.php | 2 + src/assets/Banner.php | 22 +++++++++++ src/stubs/config/backupDatabaseConfig.stub | 6 +++ 6 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 src/Console/Commands/RapidKitSupportCommand.php create mode 100644 src/Controller/BackupController.php create mode 100644 src/assets/Banner.php create mode 100644 src/stubs/config/backupDatabaseConfig.stub diff --git a/src/Console/Commands/InitilizeCommand.php b/src/Console/Commands/InitilizeCommand.php index f9db8af..8c5e08a 100644 --- a/src/Console/Commands/InitilizeCommand.php +++ b/src/Console/Commands/InitilizeCommand.php @@ -5,6 +5,8 @@ use Illuminate\Console\Command; use Illuminate\Support\Facades\Artisan; use Illuminate\Support\Str; +use Intelrx\Rapidkit\assets\Banner; +use Intelrx\Rapidkit\Controller\BackupController; class InitilizeCommand extends Command { @@ -27,6 +29,13 @@ class InitilizeCommand extends Command */ public function handle() { - $this->info('Installing RapidKit package...'); + (new Banner())->renderTitle('Installing and configuring RapidKit package...'); + + Artisan::call("vendor:publish", [ + "--provider" => "Spatie\Backup\BackupServiceProvider" + ]); + + (new BackupController())->configureDatabaseDump(); + } } diff --git a/src/Console/Commands/RapidKitSupportCommand.php b/src/Console/Commands/RapidKitSupportCommand.php new file mode 100644 index 0000000..18aa804 --- /dev/null +++ b/src/Console/Commands/RapidKitSupportCommand.php @@ -0,0 +1,30 @@ +info('Welcome to Laravel Rapid Kit Support!'); + } +} diff --git a/src/Controller/BackupController.php b/src/Controller/BackupController.php new file mode 100644 index 0000000..f250248 --- /dev/null +++ b/src/Controller/BackupController.php @@ -0,0 +1,37 @@ +error('Database Config file does not exist'); + return; + } + $stubPath = dirname(__DIR__, 2) . '/src/stubs/config/backupDatabaseConfig.stub';; + + $configPath = config_path('database.php'); + $stubContent = File::get($stubPath); + + $configContent = File::get($configPath); + if (strpos($configContent, "'dump'") === false) { + $newConfigContent = preg_replace( + "/('mysql' => \[.*?)(\s+\],)/s", + "$1\n {$stubContent}$2", + $configContent + ); + + if (File::put($configPath, $newConfigContent)) { + (new Banner())->log('Backup configuration updated for MySql'); + } else { + (new Banner())->error('Failed to update config file'); + } + } else { + (new Banner())->error('Configuration already exsists'); + } + } +} diff --git a/src/RapidKitProvider.php b/src/RapidKitProvider.php index 3fbcd7a..0ad8b91 100644 --- a/src/RapidKitProvider.php +++ b/src/RapidKitProvider.php @@ -2,6 +2,7 @@ namespace Intelrx\Rapidkit; +use App\Console\Commands\RapidKitSupportCommand; use Illuminate\Support\Facades\Artisan; use Illuminate\Support\ServiceProvider; use Intelrx\Rapidkit\Console\Commands\InitilizeCommand; @@ -26,6 +27,7 @@ public function boot(): void $this->commands([ ResourceGeneratorCommand::class, InitilizeCommand::class, + RapidKitSupportCommand::class, ]); } } diff --git a/src/assets/Banner.php b/src/assets/Banner.php new file mode 100644 index 0000000..5af47a9 --- /dev/null +++ b/src/assets/Banner.php @@ -0,0 +1,22 @@ + [ + 'dump_binary_path' => 'C:/xampp/mysql/bin/', // backup for windows + // 'dump_binary_path' => '/usr/bin/', // backup for ubuntu + 'use_single_transaction', + 'timeout' => 60 * 5, // 5 minute timeout +],