Commit 668f597c authored by catch's avatar catch
Browse files

Issue #3123376 by swatichouhan012, johndevman, longwave, xjm:...

Issue #3123376 by swatichouhan012, johndevman, longwave, xjm: update_fix_incompatibility() is (theoretically) dead code, but is also theoretically dangerous
parent d105f450
Loading
Loading
Loading
Loading
+0 −30
Changes for core/includes/update.inc: 0 added lines, 30 removed lines.
Original line number Diff line number Diff line
@@ -9,38 +9,8 @@
 */

use Drupal\Component\Graph\Graph;
use Drupal\Core\Update\UpdateKernel;
use Drupal\Core\Utility\Error;

/**
 * Disables any extensions that are incompatible with the current core version.
 *
 * @deprecated in Drupal 8.8.4 and is removed from Drupal 9.0.0.
 *
 * @see https://www.drupal.org/node/3026100
 */
function update_fix_compatibility() {
  @trigger_error(__FUNCTION__ . '() is deprecated in Drupal 8.8.4 and will be removed before Drupal 9.0.0. There is no replacement. See https://www.drupal.org/node/3026100', E_USER_DEPRECATED);
  // Fix extension objects if the update is being done via Drush 8. In non-Drush
  // environments this will already be fixed by the UpdateKernel this point.
  UpdateKernel::fixSerializedExtensionObjects(\Drupal::getContainer());

  $extension_config = \Drupal::configFactory()->getEditable('core.extension');
  $save = FALSE;
  foreach (['module', 'theme'] as $type) {
    foreach ($extension_config->get($type) as $name => $weight) {
      if (update_check_incompatibility($name, $type)) {
        $extension_config->clear("$type.$name");
        $save = TRUE;
      }
    }
  }
  if ($save) {
    $extension_config->set('module', module_config_sort($extension_config->get('module')));
    $extension_config->save();
  }
}

/**
 * Tests the compatibility of a module or theme.
 */
+0 −53
Changes for core/tests/Drupal/KernelTests/Core/Update/CompatibilityFixTest.php: 0 added lines, 53 removed lines.
Original line number Diff line number Diff line
<?php

namespace Drupal\KernelTests\Core\Update;

use Drupal\KernelTests\KernelTestBase;

/**
 * Tests that extensions that are incompatible with the current core version are disabled.
 *
 * @group Update
 * @group legacy
 */
class CompatibilityFixTest extends KernelTestBase {

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

  protected function setUp(): void {
    parent::setUp();
    require_once $this->root . '/core/includes/update.inc';
  }

  /**
   * @expectedDeprecation update_fix_compatibility() is deprecated in Drupal 8.8.4 and will be removed before Drupal 9.0.0. There is no replacement. See https://www.drupal.org/node/3026100
   */
  public function testFixCompatibility() {
    $extension_config = \Drupal::configFactory()->getEditable('core.extension');

    // Add an incompatible/non-existent module to the config.
    $modules = $extension_config->get('module');
    $modules['incompatible_module'] = 0;
    $extension_config->set('module', $modules);
    $modules = $extension_config->get('module');
    $this->assertTrue(in_array('incompatible_module', array_keys($modules)), 'Added incompatible/non-existent module to the config.');

    // Add an incompatible/non-existent theme to the config.
    $themes = $extension_config->get('theme');
    $themes['incompatible_theme'] = 0;
    $extension_config->set('theme', $themes);
    $themes = $extension_config->get('theme');
    $this->assertTrue(in_array('incompatible_theme', array_keys($themes)), 'Added incompatible/non-existent theme to the config.');

    // Fix compatibility.
    update_fix_compatibility();
    $modules = $extension_config->get('module');
    $this->assertFalse(in_array('incompatible_module', array_keys($modules)), 'Fixed modules compatibility.');
    $themes = $extension_config->get('theme');
    $this->assertFalse(in_array('incompatible_theme', array_keys($themes)), 'Fixed themes compatibility.');
  }

}