/** * Starts a background job using a new process. * * @param \Drupal\feeds\FeedInterface $feed * The feed to start the job for. * @param string $method * Method to execute on importer; one of 'import' or 'clear'. * * @throws Exception $e * * @todo Inject these dependencies. */ protected function startBackgroundJob(FeedInterface $feed, $method) { $cid = 'feeds_feed:' . $feed->id(); $token = Crypt::randomStringHashed(55); \Drupal::state()->set($cid, array('token' => $token, 'method' => $method)); $client = \Drupal::httpClient(); // Do not wait for a response. $client->addSubscriber(new AsyncPlugin()); $url = $this->url('feeds.execute', array('feeds_feed' => $feed->id()), array('absolute' => TRUE)); $request = $client->post($url)->addPostFields(array('token' => $token)); $request->send(); }
/** * {@inheritdoc} */ public function setSubscription(array &$data) { if (isset($data['lease']) && is_numeric($data['lease'])) { $data['expires'] = (int) REQUEST_TIME + $data['lease']; } else { // @todo Change schema to allow NULL values. $data['lease'] = 0; $data['expires'] = 0; } // Updating an existing subscription. if ($this->hasSubscription($data['id'])) { unset($data['created']); $this->connection->update($this->table)->fields($data)->condition('id', $data['id'])->execute(); return FALSE; } else { $data['secret'] = Crypt::randomStringHashed(55); $data['token'] = Crypt::randomStringHashed(55); $data['created'] = REQUEST_TIME; $this->connection->insert($this->table)->fields($data)->execute(); return TRUE; } }