Import command basic structure

This commit is contained in:
2024-07-05 20:55:13 +02:00
parent fa8a79c5b6
commit 0888277b2f

View File

@@ -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("<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);
}
}