diff --git a/app/Console/Commands/Import.php b/app/Console/Commands/Import.php index b3d4f93..6d49207 100644 --- a/app/Console/Commands/Import.php +++ b/app/Console/Commands/Import.php @@ -3,7 +3,9 @@ namespace App\Console\Commands; use Illuminate\Console\Command; -use Illuminate\Support\Facades\Storage; +use Illuminate\Support\Facades\File; +use JsonMachine\Items; +use JsonMachine\JsonDecoder\PassThruDecoder; class Import extends Command { @@ -21,6 +23,17 @@ class Import extends Command */ protected $description = 'Import data from gzipped backup init files'; + public function ImportToDB($dir, $files) + { + foreach ($files as $file) { + $stream = gzopen($dir.'/'.$file,'rb'); + $items = Items::fromStream($stream, ['pointer' => '/results']); + foreach ($items as $item) { + print_r($item); + } + } + } + /** * Execute the console command. */ @@ -28,10 +41,20 @@ class Import extends Command { $dir = $this->argument('dir'); - $files = Storage::disk('loacl')->files($dir); + $files = File::glob($dir . '/*.js'); + + $this->question('Which file to import?'); + $i = 1; foreach ($files as $file) { - var_dump($file); + $this->comment("[" . $i++ . "]. " . $file); } + $num = $this->ask('Enter number:'); + $file = $files[$num - 1]; + $this->info('Your choice: ' . $file); + + $files = explode(PHP_EOL, File::get($file)); + + $this->ImportToDB($dir, $files); } }