class AcquiaContentHubPublisherCommands in Acquia Content Hub 8.2
Drush commands for Acquia Content Hub Publishers.
@package Drupal\acquia_contenthub_publisher\Commands
Hierarchy
- class \Drupal\acquia_contenthub_publisher\Commands\AcquiaContentHubPublisherCommands extends \Drush\Commands\DrushCommands
Expanded class hierarchy of AcquiaContentHubPublisherCommands
1 string reference to 'AcquiaContentHubPublisherCommands'
- drush.services.yml in modules/
acquia_contenthub_publisher/ drush.services.yml - modules/acquia_contenthub_publisher/drush.services.yml
1 service uses AcquiaContentHubPublisherCommands
- acquia_contenthub_publisher.commands in modules/
acquia_contenthub_publisher/ drush.services.yml - Drupal\acquia_contenthub_publisher\Commands\AcquiaContentHubPublisherCommands
File
- modules/
acquia_contenthub_publisher/ src/ Commands/ AcquiaContentHubPublisherCommands.php, line 20
Namespace
Drupal\acquia_contenthub_publisher\CommandsView source
class AcquiaContentHubPublisherCommands extends DrushCommands {
/**
* The database connection.
*
* @var \Drupal\Core\Database\Connection
*/
protected $database;
/**
* The Content Hub Configuration.
*
* @var \Drupal\Core\Config\ImmutableConfig
*/
protected $config;
/**
* Content Hub Client Factory.
*
* @var \Drupal\acquia_contenthub\Client\ClientFactory
*/
protected $clientFactory;
/**
* Logger Service.
*
* @var \Drupal\Core\Logger\LoggerChannelInterface
*/
protected $logger;
/**
* State Service.
*
* @var \Drupal\Core\State\StateInterface
*/
protected $state;
/**
* Module Handler Service.
*
* @var \Drupal\Core\Extension\ModuleHandlerInterface
*/
protected $moduleHandler;
/**
* Public Constructor.
*
* @param \Drupal\Core\Database\Connection $database
* The database connection.
* @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory
* The Config Factory.
* @param \Drupal\acquia_contenthub\Client\ClientFactory $client_factory
* The Client Factory.
* @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $logger
* The Logger Service.
* @param \Drupal\Core\State\StateInterface $state
* The State Service.
* @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
* The Module Handler Service.
*/
public function __construct(Connection $database, ConfigFactoryInterface $config_factory, ClientFactory $client_factory, LoggerChannelFactoryInterface $logger, StateInterface $state, ModuleHandlerInterface $module_handler) {
$this->database = $database;
$this->config = $config_factory
->get('acquia_contenthub.admin_settings');
$this->clientFactory = $client_factory;
$this->logger = $logger
->get('acquia_contenthub_publisher');
$this->state = $state;
$this->moduleHandler = $module_handler;
}
/**
* Publisher Upgrade Command.
*
* @command acquia:contenthub-publisher-upgrade
* @aliases ach-publisher-upgrade,ach-puup
*/
public function upgrade() {
// Only proceed if there still exists a legacy tracking table.
if (!$this->database
->schema()
->tableExists('acquia_contenthub_entities_tracking')) {
$this->logger
->log(LogLevel::CANCEL, dt('Legacy tracking table does not exist.'));
return;
}
// Make sure webhook stored is actually registered for this site in Plexus.
$settings = $this->clientFactory
->getSettings();
$client = $this->clientFactory
->getClient($settings);
if (!$client
->getSettings()
->getWebhook()) {
// Proceed to register a webhook in HMAC v2.
$webhook_url = Url::fromUri('internal:' . '/acquia-contenthub/webhook', [
'absolute' => TRUE,
])
->toString();
$webhook = $client
->getWebHook($webhook_url);
if (empty($webhook)) {
$connection_manager = \Drupal::service('acquia_contenthub.connection_manager');
$response = $connection_manager
->registerWebhook($webhook_url);
if (isset($response['success']) && FALSE === $response['success']) {
$message = dt('Registering webhooks encountered an error (code @code). @reason', [
'@code' => $response['error']['code'],
'@reason' => $response['error']['message'],
]);
$this->logger
->log(LogLevel::ERROR, $message);
return;
}
}
}
// Enqueue all exported entities.
$path = $this->moduleHandler
->getModule('acquia_contenthub_publisher')
->getPath();
$batch = [
'title' => t('Exporting'),
'operations' => [
[
'acquia_contenthub_publisher_enqueue_exported_entities',
[],
],
],
'finished' => 'acquia_contenthub_publisher_enqueue_exported_entities_finished',
'file' => $path . '/acquia_contenthub_publisher.migrate.inc',
];
batch_set($batch);
drush_backend_batch_process();
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
AcquiaContentHubPublisherCommands:: |
protected | property | Content Hub Client Factory. | |
AcquiaContentHubPublisherCommands:: |
protected | property | The Content Hub Configuration. | |
AcquiaContentHubPublisherCommands:: |
protected | property | The database connection. | |
AcquiaContentHubPublisherCommands:: |
protected | property | Logger Service. | |
AcquiaContentHubPublisherCommands:: |
protected | property | Module Handler Service. | |
AcquiaContentHubPublisherCommands:: |
protected | property | State Service. | |
AcquiaContentHubPublisherCommands:: |
public | function | Publisher Upgrade Command. | |
AcquiaContentHubPublisherCommands:: |
public | function | Public Constructor. |