Commit 4a5e158d authored by Gábor Hojtsy's avatar Gábor Hojtsy
Browse files

Issue #3201156 by Gábor Hojtsy, andypost: Make Upgrade Status logic make sense on Drupal 9

parent 97f05234
{
"name": "drupal/upgrade_status",
"type": "drupal-module",
"description": "Review current status of known Drupal 9 incompatibilities on the site.",
"description": "Review Drupal major upgrade readiness of the environment and components of the site.",
"homepage": "http://drupal.org/project/upgrade_status",
"license": "GPL-2.0-or-later",
"require": {
......
......@@ -16,13 +16,6 @@ use Twig\Util\DeprecationCollector;
final class DeprecationAnalyzer {
/**
* The oldest supported core minor version.
*
* @var string
*/
const CORE_MINOR_OLDEST_SUPPORTED = '8.8';
/**
* Upgrade status scan result storage.
*
......@@ -447,7 +440,8 @@ final class DeprecationAnalyzer {
// Sum up the error based on the category it ended up in. Split the
// categories into two high level buckets needing attention now or
// later for Drupal 9 compatibility. Ignore Drupal 10 here.
// later for Drupal 9 compatibility. Issues in the 'ignore' category
// are intentionally not counted in either.
@$result['data']['totals']['upgrade_status_category'][$category]++;
if (in_array($category, ['safe', 'old', 'rector'])) {
@$result['data']['totals']['upgrade_status_split']['error']++;
......@@ -570,11 +564,11 @@ final class DeprecationAnalyzer {
// 8.6.0, so use that version number. Otherwise use the number from the
// message.
$version = '';
if (preg_match('!\\\\(Web|)TestBase. Deprecated in [Dd]rupal[ :]8.8.0 !', $error)) {
if (preg_match('!\\\\(Web|)TestBase. Deprecated in [Dd]rupal[ :]8\.8\.0 !', $error)) {
$version = '8.6.0';
$error .= " Replacement available from drupal:8.6.0.";
}
elseif (preg_match('!Deprecated (in|as of) [Dd]rupal[ :](8.\d)!', $error, $version_found)) {
elseif (preg_match('!Deprecated (in|as of) [Dd]rupal[ :](\d+\.\d)!', $error, $version_found)) {
$version = $version_found[2];
}
......@@ -589,7 +583,7 @@ final class DeprecationAnalyzer {
// If the found deprecation is older or equal to the oldest
// supported core version, it should be old enough to update
// either way.
if (version_compare($version, self::CORE_MINOR_OLDEST_SUPPORTED) <= 0) {
if (version_compare($version, ProjectCollector::getOldestSupportedMinor()) <= 0) {
$category = 'old';
}
// If the deprecation is not old and we are dealing with a contrib
......@@ -616,10 +610,12 @@ final class DeprecationAnalyzer {
$category = 'rector';
}
// If the deprecation is already for Drupal 10, put it in the ignore
// category. This overwrites any categorization before intentionally.
if (preg_match('!(will be|is) removed (before|from) [Dd]rupal[ :](10.\d)!', $error)) {
$category = 'ignore';
// If the deprecation is already for after the next Drupal major, put it in the
// ignore category. This overwrites any categorization before intentionally.
if (preg_match('!(will be|is) removed (before|from) [Dd]rupal[ :](\d+)\.!', $error, $version_removed)) {
if ($version_removed[3] > ProjectCollector::getDrupalCoreMajorVersion() + 1) {
$category = 'ignore';
}
}
return [$error, $category];
......
......@@ -512,4 +512,30 @@ class ProjectCollector {
return $parsed_constraints->matches($provider);
}
/**
* Return the oldest supported minor version for the current core major.
*
* @return string
* Oldest supported core version number.
*/
public static function getOldestSupportedMinor(): string {
$major = (int) \Drupal::VERSION;
switch ($major) {
case 8:
return '8.9';
case 9:
return '9.0';
}
}
/**
* Returns current core's major version.
*
* @return int
* Version converted to int.
*/
public static function getDrupalCoreMajorVersion(): int {
return (int) \Drupal::VERSION;
}
}
......@@ -10,7 +10,10 @@ use Drupal\Core\Controller\ControllerBase;
class UpgradeStatusTestContribErrorController extends ControllerBase {
public function content() {
upgrade_status_test_contrib_error_function();
upgrade_status_test_contrib_error_function_8_to_9();
upgrade_status_test_contrib_error_function_8_to_10();
upgrade_status_test_contrib_error_function_9_to_10();
upgrade_status_test_contrib_error_function_9_to_11();
}
}
<?php
/**
* Tests function deprecation detection.
* Tests function deprecation detection from Drupal 8 to 9.
*
* @deprecated in drupal:8.6.0 and is removed from drupal:9.0.0. Use the
* replacement instead.
*/
function upgrade_status_test_contrib_error_function() {
@trigger_error("upgrade_status_test_contrib_error_function() is deprecated in Drupal 8.6.0 and will be removed before Drupal 9.0.0. Use the replacement instead. See LINK", E_USER_DEPRECATED);
function upgrade_status_test_contrib_error_function_8_to_9() {
@trigger_error("upgrade_status_test_contrib_error_function_8_to_9() is deprecated in Drupal 8.6.0 and will be removed before Drupal 9.0.0. Use the replacement instead. See LINK", E_USER_DEPRECATED);
}
/**
* Tests function deprecation detection from Drupal 8 to 10.
*
* @deprecated in drupal:8.6.0 and is removed from drupal:10.0.0. Use the
* replacement instead.
*/
function upgrade_status_test_contrib_error_function_8_to_10() {
@trigger_error("upgrade_status_test_contrib_error_function_8_to_10() is deprecated in Drupal 8.6.0 and will be removed before Drupal 10.0.0. Use the replacement instead. See LINK", E_USER_DEPRECATED);
}
/**
* Tests function deprecation detection from Drupal 9 to 10.
*
* @deprecated in drupal:9.2.0 and is removed from drupal:10.0.0. Use the
* replacement instead.
*/
function upgrade_status_test_contrib_error_function_9_to_10() {
@trigger_error("upgrade_status_test_contrib_error_function_9_to_10() is deprecated in Drupal 9.2.0 and will be removed before Drupal 10.0.0. Use the replacement instead. See LINK", E_USER_DEPRECATED);
}
/**
* Tests function deprecation detection from Drupal 9 to 11.
*
* @deprecated in drupal:9.0.0 and is removed from drupal:11.0.0. Use the
* replacement instead.
*/
function upgrade_status_test_contrib_error_function_9_to_11() {
@trigger_error("upgrade_status_test_contrib_error_function_9_to_11() is deprecated in Drupal 9.0.0 and will be removed before Drupal 11.0.0. Use the replacement instead. See LINK", E_USER_DEPRECATED);
}
......@@ -10,7 +10,7 @@ use Drupal\Core\Controller\ControllerBase;
class UpgradeStatusTestErrorController extends ControllerBase {
public function content() {
upgrade_status_test_contrib_error_function();
upgrade_status_test_contrib_error_function_8_to_9();
}
}
......@@ -44,7 +44,7 @@ class UpgradeStatusAnalyzeTest extends UpgradeStatusTestBase {
$file = next($report['data']['files']);
$this->assertEquals('UpgradeStatusTestErrorController.php', basename(key($report['data']['files'])));
$message = $file['messages'][0];
$this->assertEquals("Call to deprecated function upgrade_status_test_contrib_error_function(). Deprecated in drupal:8.6.0 and is removed from drupal:9.0.0. Use the replacement instead.", $message['message']);
$this->assertEquals("Call to deprecated function upgrade_status_test_contrib_error_function_8_to_9(). Deprecated in drupal:8.6.0 and is removed from drupal:9.0.0. Use the replacement instead.", $message['message']);
$this->assertEquals(13, $message['line']);
$file = next($report['data']['files']);
$this->assertEquals('ExtendingClass.php', basename(key($report['data']['files'])));
......@@ -64,12 +64,25 @@ class UpgradeStatusAnalyzeTest extends UpgradeStatusTestBase {
$report = $key_value->get('upgrade_status_test_contrib_error');
$this->assertNotEmpty($report);
$this->assertEquals(2, $report['data']['totals']['file_errors']);
$this->assertEquals(5, $report['data']['totals']['file_errors']);
$this->assertCount(2, $report['data']['files']);
$file = reset($report['data']['files']);
$message = $file['messages'][0];
$this->assertEquals("Call to deprecated function upgrade_status_test_contrib_error_function(). Deprecated in drupal:8.6.0 and is removed from drupal:9.0.0. Use the replacement instead.", $message['message']);
$this->assertEquals("Call to deprecated function upgrade_status_test_contrib_error_function_8_to_9(). Deprecated in drupal:8.6.0 and is removed from drupal:9.0.0. Use the replacement instead.", $message['message']);
$this->assertEquals(13, $message['line']);
$this->assertEquals('old', $message['upgrade_status_category']);
$message = $file['messages'][1];
$this->assertEquals("Call to deprecated function upgrade_status_test_contrib_error_function_8_to_10(). Deprecated in drupal:8.6.0 and is removed from drupal:10.0.0. Use the replacement instead.", $message['message']);
$this->assertEquals(14, $message['line']);
$this->assertEquals($this->getDrupalCoreMajorVersion() < 9 ? 'ignore' : 'old', $message['upgrade_status_category']);
$message = $file['messages'][2];
$this->assertEquals("Call to deprecated function upgrade_status_test_contrib_error_function_9_to_10(). Deprecated in drupal:9.2.0 and is removed from drupal:10.0.0. Use the replacement instead.", $message['message']);
$this->assertEquals(15, $message['line']);
$this->assertEquals($this->getDrupalCoreMajorVersion() < 9 ? 'ignore' : 'later', $message['upgrade_status_category']);
$message = $file['messages'][3];
$this->assertEquals("Call to deprecated function upgrade_status_test_contrib_error_function_9_to_11(). Deprecated in drupal:9.0.0 and is removed from drupal:11.0.0. Use the replacement instead.", $message['message']);
$this->assertEquals(16, $message['line']);
$this->assertEquals('ignore', $message['upgrade_status_category']);
$report = $key_value->get('upgrade_status_test_twig');
$this->assertNotEmpty($report);
......
......@@ -58,12 +58,12 @@ class UpgradeStatusUiTest extends UpgradeStatusTestBase {
$this->assertEmpty($page->find('css', 'tr.upgrade_status_test_submodules_a'));
// Contrib test modules should show with results.
$this->assertSame('2 problems', strip_tags($page->find('css', 'tr.project-upgrade_status_test_contrib_error td.scan-result')->getHtml()));
$this->assertSame('5 problems', strip_tags($page->find('css', 'tr.project-upgrade_status_test_contrib_error td.scan-result')->getHtml()));
$this->assertSame('No problems found', strip_tags($page->find('css', 'tr.project-upgrade_status_test_contrib_no_error td.scan-result')->getHtml()));
// This contrib module has a different project name. Ensure the drupal.org link used that.
$this->assertSession()->linkByHrefExists('https://drupal.org/project/issues/upgrade_status_test_contributed_no_error?text=Drupal+9&status=All');
// Click the first '4 problems' link. Should be the contrib project.
// Click the first '4 problems' link. Should be the custom project.
$this->clickLink('4 problems');
$this->assertText('Upgrade status test error ' . \Drupal::VERSION);
$this->assertText('2 errors found. 2 warnings found.');
......
type: module
name: 'Upgrade Status'
description: 'Review Drupal 9 readiness of the environment and components of the site.'
description: 'Review Drupal major upgrade readiness of the environment and components of the site.'
configure: upgrade_status.report
package: Administration
core_version_requirement: ^8 || ^9
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment