Skip to content

Commit

Permalink
rapid kit support on progress
Browse files Browse the repository at this point in the history
  • Loading branch information
Raza9798 committed Jun 17, 2024
1 parent d53938f commit 81028c4
Show file tree
Hide file tree
Showing 6 changed files with 107 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/Console/Commands/InitilizeCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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();

}
}
30 changes: 30 additions & 0 deletions src/Console/Commands/RapidKitSupportCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;

class RapidKitSupportCommand extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'rapid:support';

/**
* The console command description.
*
* @var string
*/
protected $description = 'Laravel Rapid Kit Support';

/**
* Execute the console command.
*/
public function handle()
{
$this->info('Welcome to Laravel Rapid Kit Support!');
}
}
37 changes: 37 additions & 0 deletions src/Controller/BackupController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
<?php

namespace Intelrx\Rapidkit\Controller;
use Illuminate\Routing\Controller;
use Illuminate\Support\Facades\File;
use Intelrx\Rapidkit\assets\Banner;

class BackupController extends Controller
{
public function configureDatabaseDump(){
if (!File::exists(config_path('database.php'))) {
(new Banner())->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');
}
}
}
2 changes: 2 additions & 0 deletions src/RapidKitProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,6 +27,7 @@ public function boot(): void
$this->commands([
ResourceGeneratorCommand::class,
InitilizeCommand::class,
RapidKitSupportCommand::class,
]);
}
}
Expand Down
22 changes: 22 additions & 0 deletions src/assets/Banner.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php
namespace Intelrx\Rapidkit\assets;

class Banner
{
public function renderTitle($title)
{
fwrite(STDERR, "\e[36m============================================================\e[0m\n");
fwrite(STDERR, "\e[36m$title\e[0m\n");
fwrite(STDERR, "\e[36m============================================================\e[0m\n");
}

public function log($message)
{
fwrite(STDERR, "\e[32m$message\e[0m\n");
}

public function error($message)
{
fwrite(STDERR, "\e[31m$message\e[0m\n");
}
}
6 changes: 6 additions & 0 deletions src/stubs/config/backupDatabaseConfig.stub
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
'dump' => [
'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
],

0 comments on commit 81028c4

Please sign in to comment.