diff --git a/drush.services.yml b/drush.services.yml index 06e8b381a753b4c1393330dcf1d67e16f0be8489..67a12db74056cdd584f4e303475cba428116ad67 100644 --- a/drush.services.yml +++ b/drush.services.yml @@ -1,6 +1,6 @@ services: uw_cfg_common.commands: class: Drupal\uw_cfg_common\Commands\UwDrushCommands - arguments: ['@entity_type.manager', '@uw_cfg_common.missing_blocks'] + arguments: ['@entity_type.manager', '@uw_cfg_common.missing_blocks', '@config.factory', '@request_stack'] tags: - { name: drush.command } diff --git a/src/Commands/UwDrushCommands.php b/src/Commands/UwDrushCommands.php index 63f48731525b422bd61ceb9c350b197be891e97f..1b33c93e4a55a13ac352c89008a4048a3d06240f 100644 --- a/src/Commands/UwDrushCommands.php +++ b/src/Commands/UwDrushCommands.php @@ -2,11 +2,13 @@ namespace Drupal\uw_cfg_common\Commands; +use Drupal\Core\Config\ConfigFactoryInterface; use Drupal\Core\Entity\EntityTypeManagerInterface; use Drupal\uw_cfg_common\Service\UWMissingBlocks; use Drupal\uw_cfg_common\UwRoles\UwRoles; use Drush\Commands\DrushCommands; use Drush\Utils\StringUtils; +use Symfony\Component\HttpFoundation\RequestStack; /** * Drush commands for uw_cfg_common module. @@ -29,12 +31,28 @@ class UwDrushCommands extends DrushCommands { */ protected $missingBlocks; + /** + * Config factory from core. + * + * @var \Drupal\Core\Config\ConfigFactoryInterface + */ + protected $configFactory; + + /** + * Request from core. + * + * @var \Symfony\Component\HttpFoundation\Request + */ + protected $request; + /** * {@inheritDoc} */ - public function __construct(EntityTypeManagerInterface $entityTypeManager, UWMissingBlocks $missingBlocks) { + public function __construct(EntityTypeManagerInterface $entityTypeManager, UWMissingBlocks $missingBlocks, ConfigFactoryInterface $configFactory, RequestStack $requestStack) { $this->entityTypeManager = $entityTypeManager; $this->missingBlocks = $missingBlocks; + $this->configFactory = $configFactory; + $this->request = $requestStack->getCurrentRequest(); } /** @@ -167,4 +185,42 @@ class UwDrushCommands extends DrushCommands { $this->logger()->success('Missing blocks removed from saved and unsaved layouts.'); } + /** + * Command to retrieve scheduler's lightweight cron key. + * + * @return string + * Lightweight cron key. + * + * @command uw:lightweight-cron-key + * @aliases uw-lwc-key + * @usage drush uw-lwc-key + * - Return light weight cron key. + */ + public function getLightWeightCronKey(): string { + $key = ''; + $config = $this->configFactory->get('scheduler.settings'); + + if (!empty($config)) { + $key = $config->get('lightweight_cron_access_key'); + } + + return $key; + } + + /** + * Command to retrieve scheduler's lightweight cron url. + * + * @return string + * Lightweight cron url. + * + * @command uw:lightweight-cron-url + * @aliases uw-lwc-url + * @usage drush uw-lwc-url + * - Return light weight cron url with key. + */ + public function getLightWeightCronUrl(): string { + $host = $this->request->getSchemeAndHttpHost(); + return $host . '/scheduler/cron/' . $this->getLightWeightCronKey(); + } + }