/**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     echo "Retrieving " . (string) $this->request->getUri() . ".\n";
     $client = new Client();
     $collection = $client->getEntity($this->request);
     $repo = new PiftCiJobRepository();
     // Save the maximum updated value in options as we won't have the actual
     // maximum when parsing later pages.
     $max_updated = $this->getMaxUpdated();
     $hit_last_updated = false;
     /** @var PiftCiJob $job */
     foreach ($collection as $job) {
         $max_updated = $max_updated < $job->updated ? $job->updated : $max_updated;
         if (!empty($this->options['last_updated']) && $job->updated < $this->options['last_updated']) {
             $hit_last_updated = true;
             break;
         }
         $repo->saveEntity($job);
     }
     if (!$hit_last_updated && ($next_url = $collection->getNextLink())) {
         $next_url_params = [];
         parse_str($next_url->getQuery(), $next_url_params);
         $this->options['max_updated'] = $max_updated;
         $this->dispatch(new RetrievePiftCiJobCollectionJob(new PiftCiJobCollectionRequest($next_url_params), $this->options));
     } else {
         if (!empty($this->options['last_updated']) && ($job_status = JobStatus::find('pift_ci_jobs'))) {
             echo sprintf("Completed retrieving ci jobs from %s.\n", date('Y-m-d H:i:s', $this->options['last_updated']));
             $job_status->queued = false;
             $job_status->last_updated = $max_updated;
             $job_status->save();
         }
     }
 }
 public function getJobStatus($name, callable $get_last_updated)
 {
     $job = JobStatus::find($name);
     if (!$job) {
         $job = new JobStatus();
         $job->_id = $name;
         $job->last_updated = $get_last_updated();
         $job->queued = false;
     }
     return $job;
 }
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     echo "Retrieving " . (string) $this->request->getUri() . ".\n";
     $client = new Client();
     $collection = $client->getEntity($this->request);
     $repo = new NodeRepository();
     // Save the maximum updated value in options as we won't have the actual
     // maximum when parsing later pages.
     $max_updated = $this->getMaxUpdated();
     $hit_last_updated = false;
     /** @var Node $node */
     foreach ($collection as $node) {
         $max_updated = $max_updated < $node->changed ? $node->changed : $max_updated;
         if (!empty($this->options['last_updated']) && $node->changed < $this->options['last_updated']) {
             $hit_last_updated = true;
             break;
         }
         $repo->saveEntity($node);
     }
     foreach ($repo->terms as $tid) {
         // This should already be an integer, but make sure.
         $tid = (int) $tid;
         if (is_null(Term::find($tid))) {
             echo "Queueing term " . $tid . "...\n";
             $this->dispatch(new RetrieveTermJob(new TaxonomyTermRequest($tid)));
         }
     }
     foreach ($repo->releases as $release) {
         echo "Queuing release " . $release . "...\n";
         $this->dispatch(new RetrieveFieldReleaseJob(new FieldCollectionRequest($release)));
     }
     if (!$hit_last_updated && ($next_url = $collection->getNextLink())) {
         $next_url_params = [];
         parse_str($next_url->getQuery(), $next_url_params);
         $this->options['max_updated'] = $max_updated;
         $this->dispatch(new RetrieveNodeCollectionJob(new NodeCollectionRequest($next_url_params), $this->options));
     } else {
         if (!empty($this->options['last_updated']) && ($job_status = JobStatus::find('nodes-' . $this->getOption('type', '')))) {
             echo sprintf("Completed retrieving nodes from %s.\n", date('Y-m-d H:i:s', $this->options['last_updated']));
             $job_status->queued = false;
             $job_status->last_updated = $max_updated;
             $job_status->save();
         }
     }
 }
 /**
  * Execute the job.
  *
  * @return void
  */
 public function handle()
 {
     echo "Retrieving " . (string) $this->request->getUri() . ".\n";
     $client = new Client();
     $collection = $client->getEntity($this->request);
     $repo = new UserRepository();
     // Save the maximum updated value in options as we won't have the actual
     // maximum when parsing later pages.
     $max_uid = $this->getOption('max_uid');
     $hit_last_uid = false;
     /** @var User $user */
     foreach ($collection as $user) {
         // Skip anonymous user as we don't need to save it.
         if (!$user->uid) {
             continue;
         }
         $max_uid = $max_uid < $user->uid ? $user->uid : $max_uid;
         if (!empty($this->options['last_uid']) && $user->uid < $this->options['last_uid']) {
             $hit_last_uid = true;
             break;
         }
         $repo->saveEntity($user);
     }
     foreach ($repo->organizations as $organization) {
         echo "Queuing organization " . $organization . "...\n";
         $this->dispatch(new RetrieveFieldOrganizationJob(new FieldCollectionRequest($organization)));
     }
     if (!$hit_last_uid && ($next_url = $collection->getNextLink())) {
         $next_url_params = [];
         parse_str($next_url->getQuery(), $next_url_params);
         $this->options['max_uid'] = $max_uid;
         $this->dispatch(new RetrieveUserCollectionJob(new UserCollectionRequest($next_url_params), $this->options));
     } else {
         if (!empty($this->options['last_uid']) && ($job_status = JobStatus::find('users'))) {
             echo sprintf("Completed retrieving users from uid %d.\n", $this->options['last_uid']);
             $job_status->queued = false;
             $job_status->last_uid = $max_uid;
             $job_status->save();
         }
     }
 }