예제 #1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $database = $this->option('database') ?: $this->config->get('database.default');
     if (!is_dir(storage_path() . '/aperture')) {
         mkdir(storage_path() . '/aperture');
     }
     $selection = array();
     foreach (scandir(storage_path() . '/aperture', SCANDIR_SORT_DESCENDING) as $file) {
         if (strpos($file, $this->argument('table') . '_' . $database)) {
             $selection[] = $file;
         }
     }
     if (count($selection) === 0) {
         return $this->error('No snapshots found.');
     } elseif (count($selection) === 1) {
         $choice = 0;
     } else {
         foreach ($selection as $key => $file) {
             echo '[' . $key . '] Snapshot from ';
             $parts = explode('_', $file);
             echo date('H:i, M jS', $parts[0]) . "\n";
         }
         $choice = (int) $this->ask('Which snapshot do you want to restore from? ');
     }
     if ($this->snapshot->hasRows($database, $this->argument('table'), $this->option('chunk')) && !$this->confirm('This will clear any existing data in ' . $this->argument('table') . '. Continue? [y|N]', false)) {
         return $this->error('Restoration aborted');
     }
     $file = fopen(storage_path() . '/aperture/' . $selection[$choice], 'r');
     $this->snapshot->handle = $file;
     $this->snapshot->restore($database, $this->argument('table'), $this->option('chunk'));
     fclose($file);
     $this->info('Snapshot restored!');
 }
예제 #2
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $database = $this->option('database') ?: $this->config->get('database.default');
     if (!is_dir(storage_path() . '/aperture')) {
         mkdir(storage_path() . '/aperture');
     }
     $file = fopen(storage_path() . '/aperture/' . time() . '_' . $this->argument('table') . '_' . $database . '.csv', 'w');
     $this->snapshot->handle = $file;
     $this->snapshot->take($database, $this->argument('table'), $this->option('chunk'));
     fclose($file);
     $this->info('Snapshot finished!');
 }