You are here

public function FeedsDrushCommands::lockFeed in Feeds 8.3

Lock a feed specified by its id.

@command feeds:lock @aliases feeds-lk @usage feeds:lock 1

Parameters

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

File

src/Commands/FeedsDrushCommands.php, line 226

Class

FeedsDrushCommands
Defines Drush commands for the Feeds module.

Namespace

Drupal\feeds\Commands

Code

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

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