Import command basic structure
This commit is contained in:
@@ -3,7 +3,9 @@
|
|||||||
namespace App\Console\Commands;
|
namespace App\Console\Commands;
|
||||||
|
|
||||||
use Illuminate\Console\Command;
|
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
|
class Import extends Command
|
||||||
{
|
{
|
||||||
@@ -21,6 +23,17 @@ class Import extends Command
|
|||||||
*/
|
*/
|
||||||
protected $description = 'Import data from gzipped backup init files';
|
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.
|
* Execute the console command.
|
||||||
*/
|
*/
|
||||||
@@ -28,10 +41,20 @@ class Import extends Command
|
|||||||
{
|
{
|
||||||
$dir = $this->argument('dir');
|
$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) {
|
foreach ($files as $file) {
|
||||||
var_dump($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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user