You are here

public function FeedsDrushCommands::enableFeed in Feeds 8.3

Enable a feed specified by its id.

@command feeds:enable @aliases feeds-en @usage feeds:enable 1

Parameters

int $fid: The id of the feed which should get enabled.

Throws

\Drupal\Core\Entity\EntityStorageException In case the feed could not be loaded.

File

src/Commands/FeedsDrushCommands.php, line 110

Class

FeedsDrushCommands
Defines Drush commands for the Feeds module.

Namespace

Drupal\feeds\Commands

Code

public function enableFeed($fid = NULL) {
  if (empty($fid)) {
    throw new \Exception($this
      ->t('Please specify the ID of the feed you want to enable.'));
  }
  $feed = $this
    ->getFeed($fid);

  // Check if the feed we got is valid.
  if ($feed instanceof FeedInterface) {
    if ($feed
      ->isActive()) {
      $this
        ->logger()
        ->notice($this
        ->t('This feed is already enabled.'));
      return;
    }
    if (!$this
      ->io()
      ->confirm($this
      ->t('The following feed will be enabled: ":label" (id :id)', [
      ':label' => $feed
        ->label(),
      ':id' => $fid,
    ]))) {
      throw new UserAbortException();
    }
    $feed
      ->setActive(TRUE);
    $feed
      ->save();
    $this->logger
      ->success($this
      ->t('The feed ":label" has been enabled.', [
      ':label' => $feed
        ->label(),
    ]));
  }
  else {
    throw new \Exception($this
      ->t('There is no feed with id :id', [
      ':id' => $fid,
    ]));
  }
}