Commit da27e8ad authored by Dimitris Spachos's avatar Dimitris Spachos Committed by Youri van Koppen
Browse files

Issue #3259633 by MegaChriz, dspachos: Added dependency injection for FeedsDrushCommands class.

parent d891643a
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
services:
  feeds_drush_commands.commands:
    class: \Drupal\feeds\Commands\FeedsDrushCommands
    arguments: ['@entity_type.manager']
    tags:
      - { name: drush.command }
+24 −5
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ namespace Drupal\feeds\Commands;
use Consolidation\OutputFormatters\StructuredData\RowsOfFields;
use Drupal\Component\Plugin\Exception\InvalidPluginDefinitionException;
use Drupal\Component\Plugin\Exception\PluginNotFoundException;
use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\feeds\FeedInterface;
use Drush\Commands\DrushCommands;
use Drush\Exceptions\UserAbortException;
@@ -14,6 +15,24 @@ use Drush\Exceptions\UserAbortException;
 */
class FeedsDrushCommands extends DrushCommands {

  /**
   * The entity type manager.
   *
   * @var \Drupal\Core\Entity\EntityTypeManagerInterface
   */
  protected $entityTypeManager;

  /**
   * Constructs a new FeedsDrushCommands object.
   *
   * @param \Drupal\Core\Entity\EntityTypeManagerInterface $entity_type_manager
   *   The entity type manager.
   */
  public function __construct(EntityTypeManagerInterface $entity_type_manager) {
    $this->entityTypeManager = $entity_type_manager;
    parent::__construct();
  }

  /**
   * Display all feeds using a drush command.
   *
@@ -56,7 +75,7 @@ class FeedsDrushCommands extends DrushCommands {
    'disabled' => FALSE,
    'format' => 'table',
  ]) {
    $entityQuery = \Drupal::entityQuery('feeds_feed');
    $entityQuery = $this->entityTypeManager->getStorage('feeds_feed')->getQuery();
    if (!empty($feed_type)) {
      $entityQuery->condition('type', $feed_type);
    }
@@ -69,7 +88,7 @@ class FeedsDrushCommands extends DrushCommands {
    if ($options['limit'] > 0) {
      $entityQuery->range(0, $options['limit']);
    }
    $feeds = \Drupal::entityTypeManager()
    $feeds = $this->entityTypeManager
      ->getStorage('feeds_feed')
      ->loadMultiple($entityQuery->execute());

@@ -233,12 +252,12 @@ class FeedsDrushCommands extends DrushCommands {
   *   In case something went wrong when importing the feeds.
   */
  public function importAllFeeds(array $feed_types, array $options = ['import-disabled' => FALSE]) {
    $entityQuery = \Drupal::entityQuery('feeds_feed');
    $entityQuery = $this->entityTypeManager->getStorage('feeds_feed')->getQuery();
    if (!empty($feed_types)) {
      $entityQuery->condition('type', $feed_types, 'IN');
    }

    $feeds = \Drupal::entityTypeManager()
    $feeds = $this->entityTypeManager
      ->getStorage('feeds_feed')
      ->loadMultiple($entityQuery->execute());

@@ -357,7 +376,7 @@ class FeedsDrushCommands extends DrushCommands {
  private function getFeed($fid) {
    try {
      // Load the feed entity.
      return \Drupal::entityTypeManager()
      return $this->entityTypeManager
        ->getStorage('feeds_feed')
        ->load($fid);
    }