Esempio n. 1
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $page = 1;
     $per_page = 50;
     $notLastPage = true;
     $options = array('page' => $page, 'per_page' => $per_page, 'productfeed' => 'true');
     $this->info('Start importing programs into the database');
     while ($notLastPage) {
         $APIdata = DaisyconHelper::getRestAPI("programs", $options);
         if (is_array($APIdata)) {
             $resultCount = count($APIdata['response']);
             if ($resultCount > 0) {
                 if ($page == 1) {
                     $this->info('Clear database table');
                     Program::truncate();
                 }
                 foreach ($APIdata['response'] as $program) {
                     $program = (array) $program;
                     $program['program_id'] = $program['id'];
                     $program['description'] = $program['descriptions'][0]->description;
                     $program['url'] = DaisyconHelper::changeProgramURL($program['url']);
                     Program::create((array) $program);
                 }
                 $totalCount = Program::all()->count();
                 $comment = sprintf('Page %d loaded with %d record(s); Total records: %d', $page, $resultCount, $totalCount);
                 $this->comment($comment);
             } else {
                 $this->comment('No programs found');
             }
         }
         if ($resultCount < $per_page) {
             $notLastPage = false;
         }
         $options['page'] = $page++;
     }
     $count = Program::all()->count();
     return $this->info($count . ' programs imported');
 }
Esempio n. 2
0
 /**
  * Execute the console command.
  *
  * @return mixed
  */
 public function fire()
 {
     $media_id = Config::get("daisycon.media_id");
     $sub_id = Config::get("daisycon.sub_id");
     $page = 1;
     $per_page = 50;
     $notLastPage = true;
     $options = array('page' => $page, 'per_page' => $per_page, 'media_id' => $media_id, 'placeholder_media_id' => $media_id, 'placeholder_subid' => $sub_id);
     $this->info('Start importing feeds into the database');
     while ($notLastPage) {
         $APIdata = DaisyconHelper::getRestAPI("productfeeds", $options);
         if (is_array($APIdata)) {
             $resultCount = count($APIdata['response']);
             if ($resultCount > 0) {
                 if ($page == 1) {
                     $this->info('Truncate database table');
                     Feed::truncate();
                 }
                 foreach ($APIdata['response'] as $feedinfo) {
                     $feedinfo = (array) $feedinfo;
                     $feedinfo['feed_id'] = $feedinfo['id'];
                     Feed::create($feedinfo);
                 }
                 $totalCount = Feed::all()->count();
                 $comment = sprintf('Page %d loaded with %d record(s); Total records: %d', $page, $resultCount, $totalCount);
                 $this->comment($comment);
             } else {
                 return $this->comment('Geen feeds gevonden');
             }
         }
         if (isset($resultCount) && $resultCount < $per_page) {
             $notLastPage = false;
         }
         $options['page'] = $page++;
     }
     $count = Feed::all()->count();
     return $this->info($count . ' feeds imported');
 }