SHARE
TWEET

Untitled

Codecabra Feb 17th, 2019 67 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\Process\Process;
  7. use Symfony\Component\Process\Exception\ProcessFailedException;
  8.  
  9.  
  10. class SaveConfig extends Command
  11. {
  12.     /**
  13.      * The name and signature of the console command.
  14.      *
  15.      * @var string
  16.      */
  17.     protected $signature = 'voyager:save {--t|translate : Add translations table to dump}';
  18.  
  19.     /**
  20.      * The console command description.
  21.      *
  22.      * @var string
  23.      */
  24.     protected $description = 'Command description';
  25.  
  26.  
  27.     protected $process;
  28.     private $tables;
  29.  
  30.  
  31.     /**
  32.      * Create a new command instance.
  33.      *
  34.      * @return void
  35.      */
  36.     public function __construct()
  37.     {
  38.         parent::__construct();
  39.         $this->tables = [
  40.             'data_rows',
  41.             'data_types',
  42.             'menu_items',
  43.             'menus',
  44.             'permission_role',
  45.             'permissions',
  46.             'roles',
  47.             'settings',
  48.             'user_roles',
  49.         ];
  50.     }
  51.  
  52.  
  53.     /**
  54.      * Execute the console command.
  55.      *
  56.      * @return mixed
  57.      */
  58.     public function handle()
  59.     {
  60.         $this->prepare();
  61.         try {
  62.             $this->process->mustRun();
  63.             $this->info('The config has been saved successfully.');
  64.         } catch (ProcessFailedException $exception) {
  65.             $this->error($exception->getMessage());
  66.             $this->error('The config save has been failed.');
  67.         }
  68.     }
  69.  
  70.     private function prepare()
  71.     {
  72.         if ($this->option('translate')){
  73.             $this->tables[] = 'translations';
  74.         }
  75.         $tables = implode(' ',$this->tables);
  76.         $this->process = new Process(
  77.             sprintf(
  78.                 'mysqldump -h%s -u%s -p%s %s %s > %s',
  79.                 config('database.connections.mysql.host'),
  80.                 config('database.connections.mysql.username'),
  81.                 config('database.connections.mysql.password'),
  82.                 config('database.connections.mysql.database'),
  83.                 $tables,
  84.                 database_path('dumps/settings.sql')
  85.             ));
  86.     }
  87. }
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