From f3703bcd690c7d5e502ff4eb0dba29fb5d699b46 Mon Sep 17 00:00:00 2001 From: Igor Biki <ibiki@uwaterloo.ca> Date: Thu, 3 Mar 2022 13:27:21 -0500 Subject: [PATCH] ISTWCMS-5409: Adding drush command to get lightweight cron key and url. --- drush.services.yml | 2 +- src/Commands/UwDrushCommands.php | 58 +++++++++++++++++++++++++++++++- 2 files changed, 58 insertions(+), 2 deletions(-) diff --git a/drush.services.yml b/drush.services.yml index 06e8b381..67a12db7 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 63f48731..1b33c93e 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(); + } + } -- GitLab