SHARE
TWEET

Untitled

Codecabra Feb 17th, 2019 80 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. namespace App\Console\Commands;
  4.  
  5. use Illuminate\Console\Command;
  6. use Symfony\Component\Console\Exception\InvalidOptionException;
  7. use Symfony\Component\Process\Process;
  8. use Symfony\Component\Process\Exception\ProcessFailedException;
  9.  
  10. class LoadConfig extends Command
  11. {
  12.     /**
  13.      * The name and signature of the console command.
  14.      *
  15.      * @var string
  16.      */
  17.     protected $signature = 'voyager:load';
  18.  
  19.     /**
  20.      * The console command description.
  21.      *
  22.      * @var string
  23.      */
  24.     protected $description = 'Command description';
  25.  
  26.     protected $dump_path;
  27.     /**
  28.      * Create a new command instance.
  29.      *
  30.      * @return void
  31.      */
  32.     public function __construct()
  33.     {
  34.         parent::__construct();
  35.         $this->dump_path = database_path('dumps/settings.sql');
  36.         $this->process = new Process(
  37.             sprintf(
  38.                 'mysql -h%s -u%s -p%s %s < %s',
  39.                 config('database.connections.mysql.host'),
  40.                 config('database.connections.mysql.username'),
  41.                 config('database.connections.mysql.password'),
  42.                 config('database.connections.mysql.database'),
  43.                 $this->dump_path
  44.             ));
  45.     }
  46.  
  47.     /**
  48.      * Execute the console command.
  49.      *
  50.      * @return mixed
  51.      */
  52.     public function handle()
  53.     {
  54.         try {
  55.             if (file_exists($this->dump_path)){
  56.                 $this->process->mustRun();
  57.                 $this->info('The config has been load successfully.');
  58.             }else{
  59.                 $this->error('Dump file doesnot exist');
  60.             }
  61.         } catch (ProcessFailedException $exception) {
  62.             $this->error($exception->getMessage());
  63.             $this->error('The config load has been failed.');
  64.         }
  65.     }
  66. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top