Commit f4a86801 authored by omkar podey's avatar omkar podey Committed by Ted Bowman
Browse files

Issue #3321256 by omkar.podey, tedbow, Wim Leers: Fix race condition in...

Issue #3321256 by omkar.podey, tedbow, Wim Leers: Fix race condition in \Drupal\automatic_updates_test_cron\Enabler
parent 685ba03a
Loading
Loading
Loading
Loading
+31 −1
Original line number Diff line number Diff line
@@ -7,7 +7,9 @@

declare(strict_types = 1);

use Drupal\automatic_updates\CronUpdater;
use Drupal\automatic_updates\Validation\StatusCheckRequirements;
use Drupal\system\SystemManager;

/**
 * Implements hook_uninstall().
@@ -24,7 +26,19 @@ function automatic_updates_requirements($phase) {
    // Check that site is ready to perform automatic updates.
    /** @var \Drupal\automatic_updates\Validation\StatusCheckRequirements $status_check_requirement */
    $status_check_requirement = \Drupal::classResolver(StatusCheckRequirements::class);
    return $status_check_requirement->getRequirements();
    $requirements = $status_check_requirement->getRequirements();

    // Check that site has cron updates enabled or not.
    // @todo Remove in https://www.drupal.org/project/automatic_updates/issues/3284443
    if (\Drupal::configFactory()->get('automatic_updates.settings')->get('cron') !== CronUpdater::DISABLED) {
      $requirements['automatic_updates_cron'] = [
        'title' => t('Cron installs updates automatically'),
        'severity' => SystemManager::REQUIREMENT_WARNING,
        'value' => t('Enabled. This is NOT an officially supported feature of the Automatic Updates module at this time. Use at your own risk.'),
      ];
    }

    return $requirements;
  }
}

@@ -38,3 +52,19 @@ function automatic_updates_update_9001(): void {
  $key_value->rename('readiness_validation_last_run', 'status_check_last_run');
  $key_value->rename('readiness_check_timestamp', 'status_check_timestamp');
}

/**
 * Sets cron setting to \Drupal\automatic_updates\CronUpdater::DISABLED.
 *
 * This is necessary until TUF support is available on drupal.org. This used to
 * be hardcoded, but that caused complex race conditions in tests. Hence, it is
 * now just configured.
 *
 * @see automatic_updates_requirements()
 * @see https://www.drupal.org/project/automatic_updates/issues/3284443
 */
function automatic_updates_update_9002(): void {
  /** @var \Drupal\Core\Config\Config $config */
  $config = \Drupal::service('config.factory')->getEditable('automatic_updates.settings');
  $config->set('cron', CronUpdater::DISABLED)->save();
}
+5 −0
Original line number Diff line number Diff line
@@ -16,6 +16,11 @@ use Drupal\Tests\automatic_updates_extensions\Kernel\AutomaticUpdatesExtensionsK
 */
class UpdateReleaseValidatorTest extends AutomaticUpdatesExtensionsKernelTestBase {

  /**
   * {@inheritdoc}
   */
  protected static $modules = ['automatic_updates'];

  /**
   * Data provider for testPreCreateException().
   *
+1 −1
Original line number Diff line number Diff line
cron: security
cron: disable
allow_core_minor_updates: false
status_check_mail: errors_only
+0 −12
Original line number Diff line number Diff line
@@ -26,15 +26,6 @@ use Symfony\Component\HttpFoundation\Response;
 */
class CronUpdater extends Updater {

  /**
   * Whether or not cron updates are hard-disabled.
   *
   * @var bool
   *
   * @todo Remove this when TUF integration is stable.
   */
  private static $disabled = TRUE;

  /**
   * All automatic updates are disabled.
   *
@@ -337,9 +328,6 @@ class CronUpdater extends Updater {
   *     during cron.
   */
  final public function getMode(): string {
    if (self::$disabled) {
      return static::DISABLED;
    }
    $mode = $this->configFactory->get('automatic_updates.settings')->get('cron');
    return $mode ?: CronUpdater::SECURITY;
  }
+4 −0
Original line number Diff line number Diff line
@@ -7,6 +7,8 @@
 * @todo Move into automatic_updates when TUF integration is stable.
 */

declare(strict_types=1);

use Drupal\package_manager\ProjectInfo;
use Drupal\automatic_updates\CronUpdater;
use Drupal\Core\Extension\ExtensionVersion;
@@ -15,6 +17,8 @@ use Drupal\update\ProjectSecurityData;

/**
 * Implements hook_form_FORM_ID_alter() for 'update_settings' form.
 *
 * @todo Move to automatic_updates in https://www.drupal.org/i/3322361
 */
function automatic_updates_test_cron_form_update_settings_alter(array &$form, FormStateInterface $form_state, string $form_id) {
  $project_info = new ProjectInfo('drupal');
Loading