Commit 5df20ac4 authored by catch's avatar catch

Issue #2338167 by alexpott, rbmboogie: Update ProjectInfo class to reflect...

Issue #2338167 by alexpott, rbmboogie: Update ProjectInfo class to reflect changes to extension system
parent 8ce356a3
......@@ -19,9 +19,8 @@ class ProjectInfo {
/**
* Populates an array of project data.
*
* @todo https://www.drupal.org/node/2338167 update class since extensions can
* no longer be hidden, enabled or disabled. Additionally, base themes have
* to be installed for sub themes to work.
* @todo https://www.drupal.org/node/2553909 update class since extensions can
* no longer be disabled.
*
* This iterates over a list of the installed modules or themes and groups
* them by project and status. A few parts of this function assume that
......@@ -29,10 +28,12 @@ class ProjectInfo {
* modules or themes are being processed (there is a setting to control if
* disabled code should be included in the Available updates report or not),
* those are only processed after $projects has been populated with
* information about the enabled code. 'Hidden' modules are always ignored.
* 'Hidden' themes are ignored only if they have no enabled sub-themes.
* This function also records the latest change time on the .info.yml
* files for each module or theme, which is important data which is used when
* information about the enabled code. 'Hidden' modules and themes are
* ignored if they are not installed. 'Hidden' Modules and themes in the
* "Testing" package are ignored regardless of installation status.
*
* This function also records the latest change time on the .info.yml files
* for each module or theme, which is important data which is used when
* deciding if the available update data should be invalidated.
*
* @param array $projects
......@@ -50,25 +51,8 @@ class ProjectInfo {
*/
function processInfoList(array &$projects, array $list, $project_type, $status, array $additional_whitelist = array()) {
foreach ($list as $file) {
// A disabled or hidden base theme of an enabled sub-theme still has all
// of its code run by the sub-theme, so we include it in our "enabled"
// projects list.
if ($status && !empty($file->sub_themes)) {
foreach ($file->sub_themes as $key => $name) {
// Build a list of installed sub-themes.
if ($list[$key]->status) {
$file->installed_sub_themes[$key] = $name;
}
}
// If the theme is uninstalled and there are no installed subthemes, we
// should ignore this base theme for the installed case. If the site is
// trying to display uninstalled themes, we'll catch it then.
if (!$file->status && empty($file->installed_sub_themes)) {
continue;
}
}
// Otherwise, just add projects of the proper status to our list.
elseif ($file->status != $status) {
// Just projects with a matching status should be listed.
if ($file->status != $status) {
continue;
}
......@@ -77,9 +61,15 @@ function processInfoList(array &$projects, array $list, $project_type, $status,
continue;
}
// Skip if it's a hidden module or hidden theme without installed
// sub-themes.
if (!empty($file->info['hidden']) && empty($file->installed_sub_themes)) {
// Skip if it's a hidden project and the project is not installed.
if (!empty($file->info['hidden']) && empty($status)) {
continue;
}
// Skip if it's a hidden project and the project is a test project. Tests
// should use hook_system_info_alter() to test ProjectInfo's
// functionality.
if (!empty($file->info['hidden']) && isset($file->info['package']) && $file->info['package'] == 'Testing') {
continue;
}
......@@ -120,25 +110,10 @@ function processInfoList(array &$projects, array $list, $project_type, $status,
else {
$project_display_type = $project_type;
}
if (empty($status) && empty($file->installed_sub_themes)) {
if (empty($status)) {
// If we're processing disabled modules or themes, append a suffix.
// However, we don't do this to a base theme with installed
// subthemes, since we treat that case as if it is installed.
$project_display_type .= '-disabled';
}
// Add a list of sub-themes that "depend on" the project and a list of base
// themes that are "required by" the project.
if ($project_name == 'drupal') {
// Drupal core is always required, so this extra info would be noise.
$sub_themes = array();
$base_themes = array();
}
else {
// Add list of installed sub-themes.
$sub_themes = !empty($file->installed_sub_themes) ? $file->installed_sub_themes : array();
// Add list of base themes.
$base_themes = !empty($file->base_themes) ? $file->base_themes : array();
}
if (!isset($projects[$project_name])) {
// Only process this if we haven't done this project, since a single
// project can have multiple modules or themes.
......@@ -151,8 +126,6 @@ function processInfoList(array &$projects, array $list, $project_type, $status,
'includes' => array($file->getName() => $file->info['name']),
'project_type' => $project_display_type,
'project_status' => $status,
'sub_themes' => $sub_themes,
'base_themes' => $base_themes,
);
}
elseif ($projects[$project_name]['project_type'] == $project_display_type) {
......@@ -164,12 +137,6 @@ function processInfoList(array &$projects, array $list, $project_type, $status,
$projects[$project_name]['includes'][$file->getName()] = $file->info['name'];
$projects[$project_name]['info']['_info_file_ctime'] = max($projects[$project_name]['info']['_info_file_ctime'], $file->info['_info_file_ctime']);
$projects[$project_name]['datestamp'] = max($projects[$project_name]['datestamp'], $file->info['datestamp']);
if (!empty($sub_themes)) {
$projects[$project_name]['sub_themes'] += $sub_themes;
}
if (!empty($base_themes)) {
$projects[$project_name]['base_themes'] += $base_themes;
}
}
elseif (empty($status)) {
// If we have a project_name that matches, but the project_display_type
......
......@@ -66,6 +66,7 @@ function testNoReleasesAvailable() {
* Tests the basic functionality of a contrib module on the status report.
*/
function testUpdateContribBasic() {
$project_link = \Drupal::l(t('AAA Update test'), Url::fromUri('http://example.com/project/aaa_update_test'));
$system_info = array(
'#all' => array(
'version' => '8.0.0',
......@@ -87,7 +88,30 @@ function testUpdateContribBasic() {
$this->assertText(t('Up to date'));
$this->assertRaw('<h3>' . t('Modules') . '</h3>');
$this->assertNoText(t('Update available'));
$this->assertRaw(\Drupal::l(t('AAA Update test'), Url::fromUri('http://example.com/project/aaa_update_test')), 'Link to aaa_update_test project appears.');
$this->assertRaw($project_link, 'Link to aaa_update_test project appears.');
// Since aaa_update_test is installed the fact it is hidden and in the
// Testing package means it should not appear.
$system_info['aaa_update_test']['hidden'] = TRUE;
$this->config('update_test.settings')->set('system_info', $system_info)->save();
$this->refreshUpdateStatus(
array(
'drupal' => '0.0',
'aaa_update_test' => '1_0',
)
);
$this->assertNoRaw($project_link, 'Link to aaa_update_test project does not appear.');
// A hidden and installed project not in the Testing package should appear.
$system_info['aaa_update_test']['package'] = 'aaa_update_test';
$this->config('update_test.settings')->set('system_info', $system_info)->save();
$this->refreshUpdateStatus(
array(
'drupal' => '0.0',
'aaa_update_test' => '1_0',
)
);
$this->assertRaw($project_link, 'Link to aaa_update_test project appears.');
}
/**
......
......@@ -51,10 +51,6 @@ interface UpdateManagerInterface {
* 'theme'.
* - project_status: This indicates if the project is enabled and will
* always be TRUE, as the function only returns enabled projects.
* - sub_themes: If the project is a theme it contains an associative array
* of all sub-themes.
* - base_themes: If the project is a theme it contains an associative array
* of all base-themes.
*
* @see update_process_project_info()
* @see update_calculate_project_data()
......
......@@ -21,8 +21,6 @@
* - data: The data about an extra item.
* - includes: The projects within the project.
* - disabled: The currently disabled projects in the project.
* - base_themes: The base themes supplied by the project.
* - sub_themes: The subthemes supplied by the project.
*
* @see template_preprocess_update_project_status()
*
......@@ -105,18 +103,4 @@
Includes: {{ includes|placeholder }}
{% endtrans %}
{% endif %}
{% if base_themes %}
{% set basethemes = base_themes|join(', ') %}
{% trans %}
Depends on: {{ basethemes }}
{% endtrans %}
{% endif %}
{% if sub_themes %}
{% set subthemes = sub_themes|join(', ') %}
{% trans %}
Required by: {{ subthemes|placeholder }}
{% endtrans %}
{% endif %}
</div>
......@@ -183,7 +183,7 @@ function update_theme() {
'file' => 'update.report.inc',
),
'update_project_status' => array(
'variables' => array('project' => array(), 'includes_status' => array()),
'variables' => array('project' => array()),
'file' => 'update.report.inc',
),
// We are using template instead of '#type' => 'table' here to keep markup
......
......@@ -39,24 +39,12 @@ function template_preprocess_update_report(&$variables) {
$variables['no_updates_message'] = _update_no_data();
}
$status = array();
// Create an array of status values keyed by module or theme name, since
// we'll need this while generating the report if we have to cross reference
// anything (e.g. subthemes which have base themes missing an update).
foreach ($data as $project) {
foreach ($project['includes'] as $key => $name) {
$status[$key] = $project['status'];
}
}
$rows = array();
foreach ($data as $project) {
$project_status = array(
'#theme' => 'update_project_status',
'#project' => $project,
'#includes_status' => $status,
);
// Build project rows.
......@@ -120,14 +108,10 @@ function template_preprocess_update_report(&$variables) {
* @param array $variables
* An associative array containing:
* - project: An array of information about the project.
* - includes_status: An array of sub-project statuses where the keys are the
* shortnames of each project and the values are UPDATE_* integer constants
* as defined in update.module.
*/
function template_preprocess_update_project_status(&$variables) {
// Storing by reference because we are sorting the project values.
$project = &$variables['project'];
$includes_status = $variables['includes_status'];
// Set the project title and URL.
$variables['title'] = (isset($project['title'])) ? $project['title'] : $project['name'];
......@@ -249,42 +233,6 @@ function template_preprocess_update_project_status(&$variables) {
}
}
if (!empty($project['base_themes'])) {
asort($project['base_themes']);
$base_themes = array();
foreach ($project['base_themes'] as $base_key => $base_theme) {
switch ($includes_status[$base_key]) {
case UPDATE_NOT_SECURE:
$base_status_label = t('Security update required!');
break;
case UPDATE_REVOKED:
$base_status_label = t('Revoked!');
break;
case UPDATE_NOT_SUPPORTED:
$base_status_label = t('Not supported!');
break;
default:
$base_status_label = '';
}
if ($base_status_label) {
$base_themes[] = t('%base_theme (!base_label)', array(
'%base_theme' => $base_theme,
'!base_label' => $base_status_label,
));
}
else {
$base_themes[] = drupal_placeholder($base_theme);
}
}
$variables['base_themes'] = $base_themes;
}
if (!empty($project['sub_themes'])) {
sort($project['sub_themes']);
$variables['sub_themes'] = $project['sub_themes'];
}
// Set the project status details.
$status_label = NULL;
switch ($project['status']) {
......
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