Commit 5eb37a70 authored by Gábor Hojtsy's avatar Gábor Hojtsy
Browse files

Issue #3223453 by Gábor Hojtsy: Check for uses of deprecated and obsolete...

Issue #3223453 by Gábor Hojtsy: Check for uses of deprecated and obsolete projects based on the lifecycle info file key
parent 53f052a2
......@@ -397,6 +397,31 @@ final class DeprecationAnalyzer {
$result['data']['totals']['upgrade_status_split']['declared_ready'] = FALSE;
}
// @todo
// Change values to ExtensionLifecycle class constants once at least
// Drupal 9.3 is required.
if (!empty($info['lifecycle'])) {
$link = !empty($info['lifecycle_link']) ? $info['lifecycle_link'] : 'https://www.drupal.org/node/3215042';
if ($info['lifecycle'] == 'deprecated') {
$result['data']['files'][$error_path]['messages'][] = [
'message' => "This extension is deprecated. Don't use it. See $link.",
'line' => 0,
];
$result['data']['totals']['errors']++;
$result['data']['totals']['file_errors']++;
$result['data']['totals']['upgrade_status_split']['declared_ready'] = FALSE;
}
elseif ($info['lifecycle'] == 'obsolete') {
$result['data']['files'][$error_path]['messages'][] = [
'message' => "This extension is obsolete. Obsolete extensions are usually uninstalled automatically when not needed anymore. You only need to do something about this if the uninstallation was unsuccesful. See $link.",
'line' => 0,
];
$result['data']['totals']['errors']++;
$result['data']['totals']['file_errors']++;
$result['data']['totals']['upgrade_status_split']['declared_ready'] = FALSE;
}
}
} catch (InvalidDataTypeException $e) {
$result['data']['files'][$error_path]['messages'][] = [
'message' => 'Parse error. ' . $e->getMessage(),
......
......@@ -760,6 +760,29 @@ MARKUP
]
];
// Check for deprecated or obsolete core extensions.
$class = 'no-known-error';
$requirement = $this->t('None installed.');
$deprecated_or_obsolete = $this->projectCollector->collectCoreDeprecatedAndObsoleteExtensions();
if (!empty($deprecated_or_obsolete)) {
$class = 'known-error';
$status = FALSE;
$requirement = join(', ', $deprecated_or_obsolete);
}
$build['data']['#rows'][] = [
'class' => [$class],
'data' => [
'requirement' => [
'class' => 'requirement-label',
'data' => $this->t('Deprecated or obsolete core extensions installed. These will be removed in the next major version.'),
],
'status' => [
'data' => $requirement,
'class' => 'status-info',
],
]
];
// Save the overall status indicator in the build array. It will be
// popped off later to be used in the summary table.
$build['status'] = $status;
......
......@@ -335,6 +335,29 @@ class ProjectCollector {
return $projects;
}
/**
* Collect core modules that are installed and obsolete or deprecated.
*
* @return array
* An associated array of extension names keyed by extension machine names.
*/
public function collectCoreDeprecatedAndObsoleteExtensions() {
$deprecated_or_obsolete = [];
$modules = $this->moduleExtensionList->getList();
$themes = $this->themeExtensionList->getList();
$profiles = $this->profileExtensionList->getList();
$extensions = array_merge($modules, $themes, $profiles);
unset($modules, $themes, $profiles);
/** @var \Drupal\Core\Extension\Extension $extension */
foreach ($extensions as $key => $extension) {
if ($extension->origin === 'core' && !empty($extension->info['lifecycle']) && in_array($extension->info['lifecycle'], ['deprecated', 'obsolete'])) {
$deprecated_or_obsolete[$key] = $extension->info['name'];
}
}
return $deprecated_or_obsolete;
}
/**
* Finds topmost extension for each extension and keeps only that.
*
......
name: 'Upgrade status test deprecated'
type: module
description: 'Support module for upgrade status module testing.'
package: Testing
version: VERSION
core_version_requirement: ^8 || ^9 || ^10
lifecycle: deprecated
lifecycle_link: https://drupal.org/project/upgrade_status
name: 'Upgrade status test obsolete'
type: module
description: 'Support module for upgrade status module testing.'
package: Testing
version: VERSION
core_version_requirement: ^8 || ^9 || ^10
lifecycle: obsolete
lifecycle_link: https://drupal.org/project/upgrade_status
......@@ -27,6 +27,8 @@ class UpgradeStatusAnalyzeTest extends UpgradeStatusTestBase {
$this->assertTrue($key_value->has('upgrade_status_test_twig'));
$this->assertTrue($key_value->has('upgrade_status_test_theme'));
$this->assertTrue($key_value->has('upgrade_status_test_library'));
$this->assertTrue($key_value->has('upgrade_status_test_deprecated'));
$this->assertTrue($key_value->has('upgrade_status_test_obsolete'));
// The project upgrade_status_test_submodules_a shouldn't have scan result,
// because it's a submodule of 'upgrade_status_test_submodules',
......@@ -202,6 +204,20 @@ class UpgradeStatusAnalyzeTest extends UpgradeStatusTestBase {
$this->assertNotEmpty($report);
$this->assertEquals(2, $report['data']['totals']['file_errors']);
$this->assertCount(2, $report['data']['files']);
$report = $key_value->get('upgrade_status_test_deprecated');
$this->assertNotEmpty($report);
$this->assertEquals(1, $report['data']['totals']['file_errors']);
$this->assertCount(1, $report['data']['files']);
$file = reset($report['data']['files']);
$this->assertEquals("This extension is deprecated. Don't use it. See https://drupal.org/project/upgrade_status.", $file['messages'][0]['message']);
$report = $key_value->get('upgrade_status_test_obsolete');
$this->assertNotEmpty($report);
$this->assertEquals(1, $report['data']['totals']['file_errors']);
$this->assertCount(1, $report['data']['files']);
$file = reset($report['data']['files']);
$this->assertEquals("This extension is obsolete. Obsolete extensions are usually uninstalled automatically when not needed anymore. You only need to do something about this if the uninstallation was unsuccesful. See https://drupal.org/project/upgrade_status.", $file['messages'][0]['message']);
}
}
......@@ -30,6 +30,8 @@ abstract class UpgradeStatusTestBase extends BrowserTestBase {
'upgrade_status_test_twig',
'upgrade_status_test_library',
'upgrade_status_test_library_exception',
'upgrade_status_test_deprecated',
'upgrade_status_test_obsolete',
];
/**
......@@ -56,6 +58,8 @@ abstract class UpgradeStatusTestBase extends BrowserTestBase {
'scan[data][list][upgrade_status_test_theme_functions]' => TRUE,
'scan[data][list][upgrade_status_test_library]' => TRUE,
'scan[data][list][upgrade_status_test_library_exception]' => TRUE,
'scan[data][list][upgrade_status_test_deprecated]' => TRUE,
'scan[data][list][upgrade_status_test_obsolete]' => TRUE,
'collaborate[data][list][upgrade_status_test_contrib_error]' => TRUE,
($this->getDrupalCoreMajorVersion() < 9 ? 'relax' : 'collaborate') . '[data][list][upgrade_status]' => TRUE,
($this->getDrupalCoreMajorVersion() < 9 ? 'relax' : 'collaborate') . '[data][list][upgrade_status_test_contrib_9_compatible]' => TRUE,
......
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