/**
  * Execute the console command.
  *
  * @return mixed
  */
 public function handle()
 {
     $user = User::first();
     if (!$user) {
         $this->error('No user to import articles to');
         return;
     }
     $archives = PostCategory::where('name', 'archives')->first();
     if (!$archives) {
         $archives = PostCategory::create(['name' => 'archives', 'description' => 'old posts from prev site']);
     }
     $this->archiveId = $archives->id;
     $upperBound = intval($this->ask('What is the upper bound for the article ids?'));
     $articlesToFetch = collect(ImportResult::getMissingIdsUpToLimit($upperBound));
     $articlesToFetch->each(function ($id) use($user) {
         try {
             $reader = $this->articleReader->getPage($id);
             $this->import($reader, $id, $user);
             ImportResult::create(['article_id' => $id, 'imported' => 1]);
         } catch (\Exception $e) {
             $this->error('Failed on article ' . $id . ' : ' . $e->getMessage());
             ImportResult::create(['article_id' => $id, 'imported' => 0]);
         }
     });
 }
 /**
  * @test
  */
 public function it_can_get_a_list_of_ids_missing_from_result_set()
 {
     ImportResult::create(['article_id' => 1, 'imported' => 1]);
     ImportResult::create(['article_id' => 7, 'imported' => 1]);
     ImportResult::create(['article_id' => 4, 'imported' => 0]);
     ImportResult::create(['article_id' => 3, 'imported' => 0]);
     ImportResult::create(['article_id' => 12, 'imported' => 0]);
     ImportResult::create(['article_id' => 9, 'imported' => 1]);
     $expected = [2, 5, 6, 8, 10, 11];
     $this->assertEquals($expected, ImportResult::getMissingIds());
 }