Verified Commit 1d6ca731 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #3443497 by smustgrave, mikelutz: Remove deprecated code from \Drupal\Core\Cron

parent 8aeebfb3
Loading
Loading
Loading
Loading
Loading
+17 −79
Original line number Diff line number Diff line
@@ -27,62 +27,6 @@
 */
class Cron implements CronInterface {

  /**
   * The module handler service.
   *
   * @var \Drupal\Core\Extension\ModuleHandlerInterface
   */
  protected $moduleHandler;

  /**
   * The lock service.
   *
   * @var \Drupal\Core\Lock\LockBackendInterface
   */
  protected $lock;

  /**
   * The queue service.
   *
   * @var \Drupal\Core\Queue\QueueFactory
   */
  protected $queueFactory;

  /**
   * The state service.
   *
   * @var \Drupal\Core\State\StateInterface
   */
  protected $state;

  /**
   * The account switcher service.
   *
   * @var \Drupal\Core\Session\AccountSwitcherInterface
   */
  protected $accountSwitcher;

  /**
   * A logger instance.
   *
   * @var \Psr\Log\LoggerInterface
   */
  protected $logger;

  /**
   * The queue plugin manager.
   *
   * @var \Drupal\Core\Queue\QueueWorkerManagerInterface
   */
  protected $queueManager;

  /**
   * The time service.
   *
   * @var \Drupal\Component\Datetime\TimeInterface
   */
  protected $time;

  /**
   * The queue config.
   *
@@ -93,42 +37,36 @@ class Cron implements CronInterface {
  /**
   * Constructs a cron object.
   *
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler
   * @param \Drupal\Core\Extension\ModuleHandlerInterface $moduleHandler
   *   The module handler
   * @param \Drupal\Core\Lock\LockBackendInterface $lock
   *   The lock service.
   * @param \Drupal\Core\Queue\QueueFactory $queue_factory
   * @param \Drupal\Core\Queue\QueueFactory $queueFactory
   *   The queue service.
   * @param \Drupal\Core\State\StateInterface $state
   *   The state service.
   * @param \Drupal\Core\Session\AccountSwitcherInterface $account_switcher
   * @param \Drupal\Core\Session\AccountSwitcherInterface $accountSwitcher
   *   The account switching service.
   * @param \Psr\Log\LoggerInterface $logger
   *   A logger instance.
   * @param \Drupal\Core\Queue\QueueWorkerManagerInterface $queue_manager
   * @param \Drupal\Core\Queue\QueueWorkerManagerInterface $queueManager
   *   The queue plugin manager.
   * @param \Drupal\Component\Datetime\TimeInterface|null $time
   * @param \Drupal\Component\Datetime\TimeInterface $time
   *   The time service.
   * @param mixed[]|null $queue_config
   * @param array $queue_config
   *   Queue configuration from the service container.
   */
  public function __construct(ModuleHandlerInterface $module_handler, LockBackendInterface $lock, QueueFactory $queue_factory, StateInterface $state, AccountSwitcherInterface $account_switcher, LoggerInterface $logger, QueueWorkerManagerInterface $queue_manager, TimeInterface $time = NULL, ?array $queue_config = NULL) {
    $this->moduleHandler = $module_handler;
    $this->lock = $lock;
    $this->queueFactory = $queue_factory;
    $this->state = $state;
    $this->accountSwitcher = $account_switcher;
    $this->logger = $logger;
    $this->queueManager = $queue_manager;
    if (!isset($time)) {
      @trigger_error('Calling ' . __METHOD__ . '() without the $time argument is deprecated in drupal:10.1.0 and will be required in drupal:11.0.0. See https://www.drupal.org/node/3343743', E_USER_DEPRECATED);
      $time = \Drupal::service('datetime.time');
    }
    $this->time = $time;
    if (!isset($queue_config)) {
      @trigger_error('Calling ' . __METHOD__ . '() without the $queue_config argument is deprecated in drupal:10.1.0 and will be required in drupal:11.0.0. See https://www.drupal.org/node/3343743', E_USER_DEPRECATED);
      $queue_config = \Drupal::getContainer()->getParameter('queue.config');
    }
  public function __construct(
    protected ModuleHandlerInterface $moduleHandler,
    protected LockBackendInterface $lock,
    protected QueueFactory $queueFactory,
    protected StateInterface $state,
    protected AccountSwitcherInterface $accountSwitcher,
    protected LoggerInterface $logger,
    protected QueueWorkerManagerInterface $queueManager,
    protected TimeInterface $time,
    array $queue_config,
  ) {
    $this->queueConfig = $queue_config + [
      'suspendMaximumWait' => 30.0,
    ];
+10 −10
Original line number Diff line number Diff line
@@ -61,13 +61,13 @@ protected function setUp(): void {
      ->method('acquire')
      ->willReturn(TRUE);
    $this->cronConstructorArguments = [
      'module_handler' => $this->createMock(ModuleHandlerInterface::class),
      'moduleHandler' => $this->createMock(ModuleHandlerInterface::class),
      'lock' => $lock,
      'queue_factory' => $this->createMock(QueueFactory::class),
      'queueFactory' => $this->createMock(QueueFactory::class),
      'state' => $this->createMock(StateInterface::class),
      'account_switcher' => $this->createMock(AccountSwitcherInterface::class),
      'accountSwitcher' => $this->createMock(AccountSwitcherInterface::class),
      'logger' => $this->createMock(LoggerInterface::class),
      'queue_manager' => $this->createMock(QueueWorkerManagerInterface::class),
      'queueManager' => $this->createMock(QueueWorkerManagerInterface::class),
      'time' => $this->createMock(TimeInterface::class),
      'queue_config' => [],
    ];
@@ -125,8 +125,8 @@ protected function setUp(): void {
   */
  public function testSuspendQueue(): void {
    [
      'queue_factory' => $queueFactory,
      'queue_manager' => $queueManager,
      'queueFactory' => $queueFactory,
      'queueManager' => $queueManager,
      'time' => $time,
    ] = $this->cronConstructorArguments;

@@ -230,8 +230,8 @@ public function testSuspendQueueThreshold(float $threshold, float $suspendQueueD
      'suspendMaximumWait' => $threshold,
    ];
    [
      'queue_factory' => $queueFactory,
      'queue_manager' => $queueManager,
      'queueFactory' => $queueFactory,
      'queueManager' => $queueManager,
    ] = $this->cronConstructorArguments;

    $cron = $this->getMockBuilder(Cron::class)
@@ -307,8 +307,8 @@ public static function providerSuspendQueueThreshold(): array {
   */
  public function testSuspendQueueOrder(): void {
    [
      'queue_factory' => $queueFactory,
      'queue_manager' => $queueManager,
      'queueFactory' => $queueFactory,
      'queueManager' => $queueManager,
      'time' => $time,
    ] = $this->cronConstructorArguments;