Chris@0: fetcherManager = $fetcher_manager; Chris@0: $this->processorManager = $processor_manager; Chris@0: $this->parserManager = $parser_manager; Chris@0: $this->config = $config_factory->get('aggregator.settings'); Chris@0: $this->logger = $logger; Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function delete(FeedInterface $feed) { Chris@0: foreach ($this->processorManager->getDefinitions() as $id => $definition) { Chris@0: $this->processorManager->createInstance($id)->delete($feed); Chris@0: } Chris@0: } Chris@0: Chris@0: /** Chris@0: * {@inheritdoc} Chris@0: */ Chris@0: public function refresh(FeedInterface $feed) { Chris@0: // Store feed URL to track changes. Chris@0: $feed_url = $feed->getUrl(); Chris@0: Chris@0: // Fetch the feed. Chris@0: try { Chris@0: $success = $this->fetcherManager->createInstance($this->config->get('fetcher'))->fetch($feed); Chris@0: } Chris@0: catch (PluginException $e) { Chris@0: $success = FALSE; Chris@0: watchdog_exception('aggregator', $e); Chris@0: } Chris@0: Chris@17: // Store instances in an array so we don't have to instantiate new objects. Chris@0: $processor_instances = []; Chris@0: foreach ($this->config->get('processors') as $processor) { Chris@0: try { Chris@0: $processor_instances[$processor] = $this->processorManager->createInstance($processor); Chris@0: } Chris@0: catch (PluginException $e) { Chris@0: watchdog_exception('aggregator', $e); Chris@0: } Chris@0: } Chris@0: Chris@0: // We store the hash of feed data in the database. When refreshing a Chris@0: // feed we compare stored hash and new hash calculated from downloaded Chris@0: // data. If both are equal we say that feed is not updated. Chris@0: $hash = hash('sha256', $feed->source_string); Chris@0: $has_new_content = $success && ($feed->getHash() != $hash); Chris@0: Chris@0: if ($has_new_content) { Chris@0: // Parse the feed. Chris@0: try { Chris@0: if ($this->parserManager->createInstance($this->config->get('parser'))->parse($feed)) { Chris@0: if (!$feed->getWebsiteUrl()) { Chris@0: $feed->setWebsiteUrl($feed->getUrl()); Chris@0: } Chris@0: $feed->setHash($hash); Chris@0: // Update feed with parsed data. Chris@0: $feed->save(); Chris@0: Chris@0: // Log if feed URL has changed. Chris@0: if ($feed->getUrl() != $feed_url) { Chris@0: $this->logger->notice('Updated URL for feed %title to %url.', ['%title' => $feed->label(), '%url' => $feed->getUrl()]); Chris@0: } Chris@0: Chris@0: $this->logger->notice('There is new syndicated content from %site.', ['%site' => $feed->label()]); Chris@0: Chris@0: // If there are items on the feed, let enabled processors process them. Chris@0: if (!empty($feed->items)) { Chris@0: foreach ($processor_instances as $instance) { Chris@0: $instance->process($feed); Chris@0: } Chris@0: } Chris@0: } Chris@0: } Chris@0: catch (PluginException $e) { Chris@0: watchdog_exception('aggregator', $e); Chris@0: } Chris@0: } Chris@0: Chris@0: // Processing is done, call postProcess on enabled processors. Chris@0: foreach ($processor_instances as $instance) { Chris@0: $instance->postProcess($feed); Chris@0: } Chris@0: Chris@0: return $has_new_content; Chris@0: } Chris@0: Chris@0: }