/** * Execute the console command. * * @return mixed */ public function fire() { $filename = $this->argument('filename'); $stream = fopen($filename, 'r'); $this->user = User::whereEmail('*****@*****.**')->first(); try { $listener = new StreamingJsonListener(function ($entry) { $name = $this->clean($entry['author']); if (array_has($this->ignore, strtolower($name)) || str_contains(strtolower($name), 'quote')) { $quote = $this->clean($entry['text']); $this->output->write("{$this->count}: {$name} "); $this->error("{$quote}"); } else { $author = Author::firstOrCreate(['name' => $name]); if (!array_has($this->authors, strtolower($name))) { $this->authors[strtolower($name)] = true; } $quote = $this->clean($entry['text']); $q = new Quote(['content' => $quote, 'user_id' => $this->user->id, 'author_id' => $author->id, 'published' => true]); if ($q->save()) { $this->count++; $this->output->writeln("{$this->count}: {$name} <info>{$quote}</info>"); } else { $this->output->write("{$this->count}: {$name} "); $this->warn("{$quote}"); } } }); $parser = new \JsonStreamingParser_Parser($stream, $listener); $parser->parse(); $this->info("{$this->count} quotes pushed."); } catch (\JsonStreamingParser_ParsingError $e) { fclose($stream); } }