You are here

public function FeedsDrushCommands::unlockFeed in Feeds 8.3

Unlock a feed specified by its id.

@command feeds:unlock @aliases feeds-ulk @usage feeds:unlock 1

Parameters

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

File

src/Commands/FeedsDrushCommands.php, line 260

Class

FeedsDrushCommands
Defines Drush commands for the Feeds module.

Namespace

Drupal\feeds\Commands

Code

public function unlockFeed($fid = NULL) {
  if (empty($fid)) {
    throw new \Exception($this
      ->t('Please specify the ID of the feed you want to unlock.'));
  }
  $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 unlocked.'));
      return;
    }
    if (!$this
      ->io()
      ->confirm($this
      ->t('The following feed will be unlocked: ":label" (id :id)', [
      ':label' => $feed
        ->label(),
      ':id' => $fid,
    ]))) {
      throw new UserAbortException();
    }
    $feed
      ->unlock();
    $this->logger
      ->success($this
      ->t('The feed ":label" has been unlocked.', [
      ':label' => $feed
        ->label(),
    ]));
  }
  else {
    throw new \Exception($this
      ->t('There is no feed with id :id', [
      ':id' => $fid,
    ]));
  }
}