61 lines
1.4 KiB
PHP
61 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
use Illuminate\Console\Command;
|
|
use Illuminate\Support\Facades\File;
|
|
use JsonMachine\Items;
|
|
use JsonMachine\JsonDecoder\PassThruDecoder;
|
|
|
|
class Import extends Command
|
|
{
|
|
/**
|
|
* The name and signature of the console command.
|
|
*
|
|
* @var string
|
|
*/
|
|
protected $signature = 'import {dir}';
|
|
|
|
/**
|
|
* The console command description.
|
|
*
|
|
* @var string
|
|
*/
|
|
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.
|
|
*/
|
|
public function handle()
|
|
{
|
|
$dir = $this->argument('dir');
|
|
|
|
|
|
$files = File::glob($dir . '/*.js');
|
|
|
|
$this->question('Which file to import?');
|
|
$i = 1;
|
|
foreach ($files as $file) {
|
|
$this->comment("<fg=green>[" . $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);
|
|
}
|
|
}
|