public function FeedsDrushCommands::importFeed in Feeds 8.3
Import a feed specified by its id.
@command feeds:import @aliases feeds-im @option import-disabled Also import feed if it is not active. @usage feeds:import 1
Parameters
int $fid: The id of the feed which should get imported.
array $options: A list of options for this command. See below.
Throws
\Exception In case something went wrong when importing the feed.
File
- src/
Commands/ FeedsDrushCommands.php, line 190
Class
- FeedsDrushCommands
- Defines Drush commands for the Feeds module.
Namespace
Drupal\feeds\CommandsCode
public function importFeed($fid = NULL, array $options = [
'import-disabled' => FALSE,
]) {
if (empty($fid)) {
throw new \Exception($this
->t('Please specify the ID of the feed you want to import.'));
}
$feed = $this
->getFeed($fid);
// Check if the feed we got is valid.
if ($feed instanceof FeedInterface) {
// Only import feed if it is either active, or the user specifically wants
// to import the feed regardless of its active state.
if (!$feed
->isActive() && !$options['import-disabled']) {
throw new \Exception($this
->t('The specified feed is disabled. If you want to force importing, specify --import-disabled.'));
}
if (!$this
->io()
->confirm($this
->t('Do you really want to import the feed ":label" (id :id)?', [
':label' => $feed
->label(),
':id' => $fid,
]))) {
throw new UserAbortException();
}
// User has confirmed importing, start import!
$feed
->import();
}
else {
throw new \Exception($this
->t('There is no feed with id :id', [
':id' => $fid,
]));
}
}