class PullCommand in Entity Share 8
Same name and namespace in other branches
- 8.2 modules/entity_share_client/src/Command/PullCommand.php \Drupal\entity_share_client\Command\PullCommand
Class PullCommand.
@package Drupal\entity_share_client
@DrupalCommand ( extension="entity_share_client", extensionType="module" )
Hierarchy
- class \Drupal\entity_share_client\Command\PullCommand extends \Symfony\Component\Console\Command\Command uses \Drupal\Console\Core\Command\Shared\CommandTrait
Expanded class hierarchy of PullCommand
1 string reference to 'PullCommand'
- console.services.yml in modules/
entity_share_client/ console.services.yml - modules/entity_share_client/console.services.yml
1 service uses PullCommand
- entity_share_client.entity_share_client_pull in modules/
entity_share_client/ console.services.yml - Drupal\entity_share_client\Command\PullCommand
File
- modules/
entity_share_client/ src/ Command/ PullCommand.php, line 27
Namespace
Drupal\entity_share_client\CommandView source
class PullCommand extends Command {
use CommandTrait;
/**
* The cli service doing all the work.
*
* @var \Drupal\entity_share_client\Service\EntityShareClientCliService
*/
protected $cliService;
/**
* The io interface composed of a commands input and output.
*
* @var \Symfony\Component\Console\Style\StyleInterface
*/
protected $io;
/**
* Constructor with cli service injection.
*
* @param \Drupal\entity_share_client\Service\EntityShareClientCliService $cliService
* The cli service to delegate all actions to.
*/
public function __construct(EntityShareClientCliService $cliService) {
parent::__construct();
$this->cliService = $cliService;
}
/**
* Set up the io interface.
*
* @param \Symfony\Component\Console\Input\InputInterface $input
* The input interface.
* @param \Symfony\Component\Console\Output\OutputInterface $output
* The output interface.
*/
protected function setupIo(InputInterface $input, OutputInterface $output) {
$this->io = new DrupalStyle($input, $output);
}
/**
* Get the io interface.
*
* @return \Symfony\Component\Console\Style\StyleInterface
* The io interface.
*/
protected function getIo() {
return $this->io;
}
/**
* The translation function akin to drupal's t().
*
* @param string $string
* The string to translate.
* @param array $args
* The replacements.
*
* @return string
* The translated string.
*/
public function t($string, array $args = []) {
$c = 'commands.' . strtr($this
->getName(), [
':' => '.',
]) . '.messages.';
$translations = [
'Channel successfully pulled. Execution time @time ms.' => $c . 'success',
'There is no remote website configured with the id: @remote_id.' => $c . 'no_remote',
'There is no channel configured or accessible with the id: @channel_id.' => $c . 'no_channel',
'Beginning to import content from URL: @url' => $c . 'beginning_url_import',
'@number entities have been imported.' => $c . 'number_imported',
'Looking for new content in channel @channel' => $c . 'update_channel_lookup',
'Looking for updated content at URL: @url' => $c . 'update_page_lookup',
'Channel successfully pulled. Number of updated entities: @count, execution time: @time ms' => $c . 'update_success',
];
if (array_key_exists($string, $translations)) {
$string = $translations[$string];
}
// Translate with consoles translations.
return strtr($this
->trans($string), $args);
}
/**
* {@inheritdoc}
*/
protected function configure() {
$this
->setName('entity_share_client:pull')
->setDescription($this
->trans('commands.entity_share_client.pull.description'))
->addArgument('remote_id', InputArgument::REQUIRED, $this
->trans('commands.entity_share_client.pull.arguments.remote_id'))
->addArgument('channel_id', InputArgument::REQUIRED, $this
->trans('commands.entity_share_client.pull.arguments.channel_id'))
->addOption('update', 'u', InputOption::VALUE_OPTIONAL, $this
->trans('commands.entity_share_client.pull.options.update'), FALSE);
}
/**
* {@inheritdoc}
*/
protected function execute(InputInterface $input, OutputInterface $output) {
$this
->setupIo($input, $output);
try {
// Make the magic happen.
$update = $input
->getOption('update') !== FALSE;
if ($update) {
$this->cliService
->ioPullUpdates($input
->getArgument('remote_id'), $input
->getArgument('channel_id'), $this
->getIo(), [
$this,
't',
]);
}
else {
$this->cliService
->ioPull($input
->getArgument('remote_id'), $input
->getArgument('channel_id'), $this
->getIo(), [
$this,
't',
]);
}
} catch (\Exception $e) {
$this
->getIo()
->error($e
->getMessage());
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PullCommand:: |
protected | property | The cli service doing all the work. | |
PullCommand:: |
protected | property | The io interface composed of a commands input and output. | |
PullCommand:: |
protected | function | Configures the current command. | |
PullCommand:: |
protected | function | Executes the current command. | |
PullCommand:: |
protected | function | Get the io interface. | |
PullCommand:: |
protected | function | Set up the io interface. | |
PullCommand:: |
public | function | The translation function akin to drupal's t(). | |
PullCommand:: |
public | function | Constructor with cli service injection. |