Update core 8.3.0

This commit is contained in:
Rob Davies 2017-04-13 15:53:35 +01:00
parent da7a7918f8
commit cd7a898e66
6144 changed files with 132297 additions and 87747 deletions

View file

@ -44,9 +44,9 @@ class UpdateController extends ControllerBase {
* A build array with the update status of projects.
*/
public function updateStatus() {
$build = array(
$build = [
'#theme' => 'update_report'
);
];
if ($available = update_get_available(TRUE)) {
$this->moduleHandler()->loadInclude('update', 'compare.inc');
$build['#data'] = update_calculate_project_data($available);
@ -59,15 +59,15 @@ class UpdateController extends ControllerBase {
*/
public function updateStatusManually() {
$this->updateManager->refreshUpdateData();
$batch = array(
'operations' => array(
array(array($this->updateManager, 'fetchDataBatch'), array()),
),
$batch = [
'operations' => [
[[$this->updateManager, 'fetchDataBatch'], []],
],
'finished' => 'update_fetch_data_finished',
'title' => t('Checking available update data'),
'progress_message' => t('Trying to check available update data ...'),
'error_message' => t('Error checking available update data.'),
);
];
batch_set($batch);
return batch_process('admin/reports/updates');
}

View file

@ -79,41 +79,41 @@ class UpdateManagerInstall extends FormBase {
return $form;
}
$form['help_text'] = array(
$form['help_text'] = [
'#prefix' => '<p>',
'#markup' => $this->t('You can find <a href=":module_url">modules</a> and <a href=":theme_url">themes</a> on <a href=":drupal_org_url">drupal.org</a>. The following file extensions are supported: %extensions.', array(
'#markup' => $this->t('You can find <a href=":module_url">modules</a> and <a href=":theme_url">themes</a> on <a href=":drupal_org_url">drupal.org</a>. The following file extensions are supported: %extensions.', [
':module_url' => 'https://www.drupal.org/project/modules',
':theme_url' => 'https://www.drupal.org/project/themes',
':drupal_org_url' => 'https://www.drupal.org',
'%extensions' => archiver_get_extensions(),
)),
]),
'#suffix' => '</p>',
);
];
$form['project_url'] = array(
$form['project_url'] = [
'#type' => 'url',
'#title' => $this->t('Install from a URL'),
'#description' => $this->t('For example: %url', array('%url' => 'http://ftp.drupal.org/files/projects/name.tar.gz')),
);
'#description' => $this->t('For example: %url', ['%url' => 'http://ftp.drupal.org/files/projects/name.tar.gz']),
];
$form['information'] = array(
$form['information'] = [
'#prefix' => '<strong>',
'#markup' => $this->t('Or'),
'#suffix' => '</strong>',
);
];
$form['project_upload'] = array(
$form['project_upload'] = [
'#type' => 'file',
'#title' => $this->t('Upload a module or theme archive to install'),
'#description' => $this->t('For example: %filename from your local computer', array('%filename' => 'name.tar.gz')),
);
'#description' => $this->t('For example: %filename from your local computer', ['%filename' => 'name.tar.gz']),
];
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
$form['actions'] = ['#type' => 'actions'];
$form['actions']['submit'] = [
'#type' => 'submit',
'#button_type' => 'primary',
'#value' => $this->t('Install'),
);
];
return $form;
}
@ -136,12 +136,12 @@ class UpdateManagerInstall extends FormBase {
if ($form_state->getValue('project_url')) {
$local_cache = update_manager_file_get($form_state->getValue('project_url'));
if (!$local_cache) {
drupal_set_message($this->t('Unable to retrieve Drupal project from %url.', array('%url' => $form_state->getValue('project_url'))), 'error');
drupal_set_message($this->t('Unable to retrieve Drupal project from %url.', ['%url' => $form_state->getValue('project_url')]), 'error');
return;
}
}
elseif ($_FILES['files']['name']['project_upload']) {
$validators = array('file_validate_extensions' => array(archiver_get_extensions()));
$validators = ['file_validate_extensions' => [archiver_get_extensions()]];
if (!($finfo = file_save_upload('project_upload', $validators, NULL, 0, FILE_EXISTS_REPLACE))) {
// Failed to upload the file. file_save_upload() calls
// drupal_set_message() on failure.
@ -170,7 +170,7 @@ class UpdateManagerInstall extends FormBase {
// MODULE/) and others list an actual file (i.e., MODULE/README.TXT).
$project = strtok($files[0], '/\\');
$archive_errors = $this->moduleHandler->invokeAll('verify_update_archive', array($project, $local_cache, $directory));
$archive_errors = $this->moduleHandler->invokeAll('verify_update_archive', [$project, $local_cache, $directory]);
if (!empty($archive_errors)) {
drupal_set_message(array_shift($archive_errors), 'error');
// @todo: Fix me in D8: We need a way to set multiple errors on the same
@ -204,20 +204,20 @@ class UpdateManagerInstall extends FormBase {
}
if (!$project_title) {
drupal_set_message($this->t('Unable to determine %project name.', array('%project' => $project)), 'error');
drupal_set_message($this->t('Unable to determine %project name.', ['%project' => $project]), 'error');
}
if ($updater->isInstalled()) {
drupal_set_message($this->t('%project is already installed.', array('%project' => $project_title)), 'error');
drupal_set_message($this->t('%project is already installed.', ['%project' => $project_title]), 'error');
return;
}
$project_real_location = drupal_realpath($project_location);
$arguments = array(
$arguments = [
'project' => $project,
'updater_name' => get_class($updater),
'local_url' => $project_real_location,
);
];
// This process is inherently difficult to test therefore use a state flag.
$test_authorize = FALSE;
@ -232,7 +232,7 @@ class UpdateManagerInstall extends FormBase {
if (fileowner($project_real_location) == fileowner($this->sitePath) && !$test_authorize) {
$this->moduleHandler->loadInclude('update', 'inc', 'update.authorize');
$filetransfer = new Local($this->root);
$response = call_user_func_array('update_authorize_run_install', array_merge(array($filetransfer), $arguments));
$response = call_user_func_array('update_authorize_run_install', array_merge([$filetransfer], $arguments));
if ($response instanceof Response) {
$form_state->setResponse($response);
}

View file

@ -64,13 +64,13 @@ class UpdateManagerUpdate extends FormBase {
public function buildForm(array $form, FormStateInterface $form_state) {
$this->moduleHandler->loadInclude('update', 'inc', 'update.manager');
$last_markup = array(
$last_markup = [
'#theme' => 'update_last_check',
'#last' => $this->state->get('update.last_check') ?: 0,
);
$form['last_check'] = array(
];
$form['last_check'] = [
'#markup' => drupal_render($last_markup),
);
];
if (!_update_manager_check_backends($form, 'update')) {
return $form;
@ -78,9 +78,9 @@ class UpdateManagerUpdate extends FormBase {
$available = update_get_available(TRUE);
if (empty($available)) {
$form['message'] = array(
$form['message'] = [
'#markup' => $this->t('There was a problem getting update information. Try again later.'),
);
];
return $form;
}
@ -91,11 +91,11 @@ class UpdateManagerUpdate extends FormBase {
// manual updates, such as core). Then, each subarray is an array of
// projects of that type, indexed by project short name, and containing an
// array of data for cells in that project's row in the appropriate table.
$projects = array();
$projects = [];
// This stores the actual download link we're going to update from for each
// project in the form, regardless of if it's enabled or disabled.
$form['project_downloads'] = array('#tree' => TRUE);
$form['project_downloads'] = ['#tree' => TRUE];
$this->moduleHandler->loadInclude('update', 'inc', 'update.compare');
$project_data = update_calculate_project_data($available);
foreach ($project_data as $name => $project) {
@ -134,25 +134,25 @@ class UpdateManagerUpdate extends FormBase {
$recommended_version .= '<div title="{{ major_update_warning_title }}" class="update-major-version-warning">{{ major_update_warning_text }}</div>';
}
$recommended_version = array(
$recommended_version = [
'#type' => 'inline_template',
'#template' => $recommended_version,
'#context' => array(
'#context' => [
'release_version' => $recommended_release['version'],
'release_link' => $recommended_release['release_link'],
'project_title' => $this->t('Release notes for @project_title', array('@project_title' => $project['title'])),
'project_title' => $this->t('Release notes for @project_title', ['@project_title' => $project['title']]),
'major_update_warning_title' => $this->t('Major upgrade warning'),
'major_update_warning_text' => $this->t('This update is a major version update which means that it may not be backwards compatible with your currently running version. It is recommended that you read the release notes and proceed at your own risk.'),
'release_notes' => $this->t('Release notes'),
),
);
],
];
// Create an entry for this project.
$entry = array(
$entry = [
'title' => $project_name,
'installed_version' => $project['existing_version'],
'recommended_version' => array('data' => $recommended_version),
);
'recommended_version' => ['data' => $recommended_version],
];
switch ($project['status']) {
case UPDATE_NOT_SECURE:
@ -181,11 +181,11 @@ class UpdateManagerUpdate extends FormBase {
}
// Use the project title for the tableselect checkboxes.
$entry['title'] = array('data' => array(
$entry['title'] = ['data' => [
'#title' => $entry['title'],
'#markup' => $entry['title'],
));
$entry['#attributes'] = array('class' => array('update-' . $type));
]];
$entry['#attributes'] = ['class' => ['update-' . $type]];
// Drupal core needs to be upgraded manually.
$needs_manual = $project['project_type'] == 'core';
@ -198,15 +198,15 @@ class UpdateManagerUpdate extends FormBase {
unset($entry['#weight']);
$attributes = $entry['#attributes'];
unset($entry['#attributes']);
$entry = array(
$entry = [
'data' => $entry,
) + $attributes;
] + $attributes;
}
else {
$form['project_downloads'][$name] = array(
$form['project_downloads'][$name] = [
'#type' => 'value',
'#value' => $recommended_release['download_link'],
);
];
}
// Based on what kind of project this is, save the entry into the
@ -230,62 +230,62 @@ class UpdateManagerUpdate extends FormBase {
}
if (empty($projects)) {
$form['message'] = array(
$form['message'] = [
'#markup' => $this->t('All of your projects are up to date.'),
);
];
return $form;
}
$headers = array(
'title' => array(
$headers = [
'title' => [
'data' => $this->t('Name'),
'class' => array('update-project-name'),
),
'class' => ['update-project-name'],
],
'installed_version' => $this->t('Installed version'),
'recommended_version' => $this->t('Recommended version'),
);
];
if (!empty($projects['enabled'])) {
$form['projects'] = array(
$form['projects'] = [
'#type' => 'tableselect',
'#header' => $headers,
'#options' => $projects['enabled'],
);
];
if (!empty($projects['disabled'])) {
$form['projects']['#prefix'] = '<h2>' . $this->t('Enabled') . '</h2>';
}
}
if (!empty($projects['disabled'])) {
$form['disabled_projects'] = array(
$form['disabled_projects'] = [
'#type' => 'tableselect',
'#header' => $headers,
'#options' => $projects['disabled'],
'#weight' => 1,
'#prefix' => '<h2>' . $this->t('Disabled') . '</h2>',
);
];
}
// If either table has been printed yet, we need a submit button and to
// validate the checkboxes.
if (!empty($projects['enabled']) || !empty($projects['disabled'])) {
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
$form['actions'] = ['#type' => 'actions'];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this->t('Download these updates'),
);
];
}
if (!empty($projects['manual'])) {
$prefix = '<h2>' . $this->t('Manual updates required') . '</h2>';
$prefix .= '<p>' . $this->t('Updates of Drupal core are not supported at this time.') . '</p>';
$form['manual_updates'] = array(
$form['manual_updates'] = [
'#type' => 'table',
'#header' => $headers,
'#rows' => $projects['manual'],
'#prefix' => $prefix,
'#weight' => 120,
);
];
}
return $form;
@ -311,29 +311,29 @@ class UpdateManagerUpdate extends FormBase {
*/
public function submitForm(array &$form, FormStateInterface $form_state) {
$this->moduleHandler->loadInclude('update', 'inc', 'update.manager');
$projects = array();
foreach (array('projects', 'disabled_projects') as $type) {
$projects = [];
foreach (['projects', 'disabled_projects'] as $type) {
if (!$form_state->isValueEmpty($type)) {
$projects = array_merge($projects, array_keys(array_filter($form_state->getValue($type))));
}
}
$operations = array();
$operations = [];
foreach ($projects as $project) {
$operations[] = array(
$operations[] = [
'update_manager_batch_project_get',
array(
[
$project,
$form_state->getValue(array('project_downloads', $project)),
),
);
$form_state->getValue(['project_downloads', $project]),
],
];
}
$batch = array(
$batch = [
'title' => $this->t('Downloading updates'),
'init_message' => $this->t('Preparing to download selected updates'),
'operations' => $operations,
'finished' => 'update_manager_download_batch_finished',
'file' => drupal_get_path('module', 'update') . '/update.manager.inc',
);
];
batch_set($batch);
}

View file

@ -91,23 +91,23 @@ class UpdateReady extends FormBase {
return $form;
}
$form['backup'] = array(
$form['backup'] = [
'#prefix' => '<strong>',
'#markup' => $this->t('Back up your database and site before you continue. <a href=":backup_url">Learn how</a>.', array(':backup_url' => 'https://www.drupal.org/node/22281')),
'#markup' => $this->t('Back up your database and site before you continue. <a href=":backup_url">Learn how</a>.', [':backup_url' => 'https://www.drupal.org/node/22281']),
'#suffix' => '</strong>',
);
];
$form['maintenance_mode'] = array(
$form['maintenance_mode'] = [
'#title' => $this->t('Perform updates with site in maintenance mode (strongly recommended)'),
'#type' => 'checkbox',
'#default_value' => TRUE,
);
];
$form['actions'] = array('#type' => 'actions');
$form['actions']['submit'] = array(
$form['actions'] = ['#type' => 'actions'];
$form['actions']['submit'] = [
'#type' => 'submit',
'#value' => $this->t('Continue'),
);
];
return $form;
}
@ -126,7 +126,7 @@ class UpdateReady extends FormBase {
// Make sure the Updater registry is loaded.
drupal_get_updaters();
$updates = array();
$updates = [];
$directory = _update_manager_extract_directory();
$projects = $_SESSION['update_manager_update_projects'];
@ -137,11 +137,11 @@ class UpdateReady extends FormBase {
$project_location = $directory . '/' . $project;
$updater = Updater::factory($project_location, $this->root);
$project_real_location = drupal_realpath($project_location);
$updates[] = array(
$updates[] = [
'project' => $project,
'updater_name' => get_class($updater),
'local_url' => $project_real_location,
);
];
}
// If the owner of the last directory we extracted is the same as the
@ -164,7 +164,7 @@ class UpdateReady extends FormBase {
// The page title must be passed here to ensure it is initially used
// when authorize.php loads for the first time with the FTP/SSH
// credentials form.
system_authorized_init('update_authorize_run_update', __DIR__ . '/../../update.authorize.inc', array($updates), $this->t('Update manager'));
system_authorized_init('update_authorize_run_update', __DIR__ . '/../../update.authorize.inc', [$updates], $this->t('Update manager'));
$form_state->setRedirectUrl(system_authorized_get_url());
}
}

View file

@ -14,11 +14,11 @@ class FileTransferAuthorizeFormTest extends UpdateTestBase {
*
* @var array
*/
public static $modules = array('update', 'update_test');
public static $modules = ['update', 'update_test'];
protected function setUp() {
parent::setUp();
$admin_user = $this->drupalCreateUser(array('administer modules', 'administer software updates', 'administer site configuration'));
$admin_user = $this->drupalCreateUser(['administer modules', 'administer software updates', 'administer site configuration']);
$this->drupalLogin($admin_user);
// Create a local cache so the module is not downloaded from drupal.org.

View file

@ -18,30 +18,30 @@ class UpdateContribTest extends UpdateTestBase {
*
* @var array
*/
public static $modules = array('update_test', 'update', 'aaa_update_test', 'bbb_update_test', 'ccc_update_test');
public static $modules = ['update_test', 'update', 'aaa_update_test', 'bbb_update_test', 'ccc_update_test'];
protected function setUp() {
parent::setUp();
$admin_user = $this->drupalCreateUser(array('administer site configuration'));
$admin_user = $this->drupalCreateUser(['administer site configuration']);
$this->drupalLogin($admin_user);
}
/**
* Tests when there is no available release data for a contrib module.
*/
function testNoReleasesAvailable() {
$system_info = array(
'#all' => array(
public function testNoReleasesAvailable() {
$system_info = [
'#all' => [
'version' => '8.0.0',
),
'aaa_update_test' => array(
],
'aaa_update_test' => [
'project' => 'aaa_update_test',
'version' => '8.x-1.0',
'hidden' => FALSE,
),
);
],
];
$this->config('update_test.settings')->set('system_info', $system_info)->save();
$this->refreshUpdateStatus(array('drupal' => '0.0', 'aaa_update_test' => 'no-releases'));
$this->refreshUpdateStatus(['drupal' => '0.0', 'aaa_update_test' => 'no-releases']);
$this->drupalGet('admin/reports/updates');
// Cannot use $this->standardTests() because we need to check for the
// 'No available releases found' string.
@ -60,24 +60,24 @@ class UpdateContribTest extends UpdateTestBase {
/**
* Tests the basic functionality of a contrib module on the status report.
*/
function testUpdateContribBasic() {
public function testUpdateContribBasic() {
$project_link = \Drupal::l(t('AAA Update test'), Url::fromUri('http://example.com/project/aaa_update_test'));
$system_info = array(
'#all' => array(
$system_info = [
'#all' => [
'version' => '8.0.0',
),
'aaa_update_test' => array(
],
'aaa_update_test' => [
'project' => 'aaa_update_test',
'version' => '8.x-1.0',
'hidden' => FALSE,
),
);
],
];
$this->config('update_test.settings')->set('system_info', $system_info)->save();
$this->refreshUpdateStatus(
array(
[
'drupal' => '0.0',
'aaa_update_test' => '1_0',
)
]
);
$this->standardTests();
$this->assertText(t('Up to date'));
@ -90,10 +90,10 @@ class UpdateContribTest extends UpdateTestBase {
$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.');
@ -101,10 +101,10 @@ class UpdateContribTest extends UpdateTestBase {
$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.');
}
@ -122,40 +122,40 @@ class UpdateContribTest extends UpdateTestBase {
* if you sort alphabetically by module name (which is the order we see things
* inside system_rebuild_module_data() for example).
*/
function testUpdateContribOrder() {
public function testUpdateContribOrder() {
// We want core to be version 8.0.0.
$system_info = array(
'#all' => array(
$system_info = [
'#all' => [
'version' => '8.0.0',
),
],
// All the rest should be visible as contrib modules at version 8.x-1.0.
// aaa_update_test needs to be part of the "CCC Update test" project,
// which would throw off the report if we weren't properly sorting by
// the project names.
'aaa_update_test' => array(
'aaa_update_test' => [
'project' => 'ccc_update_test',
'version' => '8.x-1.0',
'hidden' => FALSE,
),
],
// This should be its own project, and listed first on the report.
'bbb_update_test' => array(
'bbb_update_test' => [
'project' => 'bbb_update_test',
'version' => '8.x-1.0',
'hidden' => FALSE,
),
],
// This will contain both aaa_update_test and ccc_update_test, and
// should come after the bbb_update_test project.
'ccc_update_test' => array(
'ccc_update_test' => [
'project' => 'ccc_update_test',
'version' => '8.x-1.0',
'hidden' => FALSE,
),
);
],
];
$this->config('update_test.settings')->set('system_info', $system_info)->save();
$this->refreshUpdateStatus(array('drupal' => '0.0', '#all' => '1_0'));
$this->refreshUpdateStatus(['drupal' => '0.0', '#all' => '1_0']);
$this->standardTests();
// We're expecting the report to say all projects are up to date.
$this->assertText(t('Up to date'));
@ -184,37 +184,37 @@ class UpdateContribTest extends UpdateTestBase {
/**
* Tests that subthemes are notified about security updates for base themes.
*/
function testUpdateBaseThemeSecurityUpdate() {
public function testUpdateBaseThemeSecurityUpdate() {
// @todo https://www.drupal.org/node/2338175 base themes have to be
// installed.
// Only install the subtheme, not the base theme.
\Drupal::service('theme_handler')->install(array('update_test_subtheme'));
\Drupal::service('theme_handler')->install(['update_test_subtheme']);
// Define the initial state for core and the subtheme.
$system_info = array(
$system_info = [
// We want core to be version 8.0.0.
'#all' => array(
'#all' => [
'version' => '8.0.0',
),
],
// Show the update_test_basetheme
'update_test_basetheme' => array(
'update_test_basetheme' => [
'project' => 'update_test_basetheme',
'version' => '8.x-1.0',
'hidden' => FALSE,
),
],
// Show the update_test_subtheme
'update_test_subtheme' => array(
'update_test_subtheme' => [
'project' => 'update_test_subtheme',
'version' => '8.x-1.0',
'hidden' => FALSE,
),
);
],
];
$this->config('update_test.settings')->set('system_info', $system_info)->save();
$xml_mapping = array(
$xml_mapping = [
'drupal' => '0.0',
'update_test_subtheme' => '1_0',
'update_test_basetheme' => '1_1-sec',
);
];
$this->refreshUpdateStatus($xml_mapping);
$this->assertText(t('Security update required!'));
$this->assertRaw(\Drupal::l(t('Update test base theme'), Url::fromUri('http://example.com/project/update_test_basetheme')), 'Link to the Update test base theme project appears.');
@ -226,7 +226,7 @@ class UpdateContribTest extends UpdateTestBase {
* @todo https://www.drupal.org/node/2338175 extensions can not be hidden and
* base themes have to be installed.
*/
function testUpdateShowDisabledThemes() {
public function testUpdateShowDisabledThemes() {
$update_settings = $this->config('update.settings');
// Make sure all the update_test_* themes are disabled.
$extension_config = $this->config('core.extension');
@ -238,38 +238,38 @@ class UpdateContribTest extends UpdateTestBase {
$extension_config->save();
// Define the initial state for core and the test contrib themes.
$system_info = array(
$system_info = [
// We want core to be version 8.0.0.
'#all' => array(
'#all' => [
'version' => '8.0.0',
),
],
// The update_test_basetheme should be visible and up to date.
'update_test_basetheme' => array(
'update_test_basetheme' => [
'project' => 'update_test_basetheme',
'version' => '8.x-1.1',
'hidden' => FALSE,
),
],
// The update_test_subtheme should be visible and up to date.
'update_test_subtheme' => array(
'update_test_subtheme' => [
'project' => 'update_test_subtheme',
'version' => '8.x-1.0',
'hidden' => FALSE,
),
);
],
];
// When there are contributed modules in the site's file system, the
// total number of attempts made in the test may exceed the default value
// of update_max_fetch_attempts. Therefore this variable is set very high
// to avoid test failures in those cases.
$update_settings->set('fetch.max_attempts', 99999)->save();
$this->config('update_test.settings')->set('system_info', $system_info)->save();
$xml_mapping = array(
$xml_mapping = [
'drupal' => '0.0',
'update_test_subtheme' => '1_0',
'update_test_basetheme' => '1_1-sec',
);
];
$base_theme_project_link = \Drupal::l(t('Update test base theme'), Url::fromUri('http://example.com/project/update_test_basetheme'));
$sub_theme_project_link = \Drupal::l(t('Update test subtheme'), Url::fromUri('http://example.com/project/update_test_subtheme'));
foreach (array(TRUE, FALSE) as $check_disabled) {
foreach ([TRUE, FALSE] as $check_disabled) {
$update_settings->set('check.disabled_extensions', $check_disabled)->save();
$this->refreshUpdateStatus($xml_mapping);
// In neither case should we see the "Themes" heading for installed
@ -291,25 +291,25 @@ class UpdateContribTest extends UpdateTestBase {
/**
* Tests updates with a hidden base theme.
*/
function testUpdateHiddenBaseTheme() {
public function testUpdateHiddenBaseTheme() {
module_load_include('compare.inc', 'update');
// Install the subtheme.
\Drupal::service('theme_handler')->install(array('update_test_subtheme'));
\Drupal::service('theme_handler')->install(['update_test_subtheme']);
// Add a project and initial state for base theme and subtheme.
$system_info = array(
$system_info = [
// Hide the update_test_basetheme.
'update_test_basetheme' => array(
'update_test_basetheme' => [
'project' => 'update_test_basetheme',
'hidden' => TRUE,
),
],
// Show the update_test_subtheme.
'update_test_subtheme' => array(
'update_test_subtheme' => [
'project' => 'update_test_subtheme',
'hidden' => FALSE,
),
);
],
];
$this->config('update_test.settings')->set('system_info', $system_info)->save();
$projects = \Drupal::service('update.manager')->getProjects();
$theme_data = \Drupal::service('theme_handler')->rebuildThemeData();
@ -322,38 +322,38 @@ class UpdateContribTest extends UpdateTestBase {
/**
* Makes sure that if we fetch from a broken URL, sane things happen.
*/
function testUpdateBrokenFetchURL() {
$system_info = array(
'#all' => array(
public function testUpdateBrokenFetchURL() {
$system_info = [
'#all' => [
'version' => '8.0.0',
),
'aaa_update_test' => array(
],
'aaa_update_test' => [
'project' => 'aaa_update_test',
'version' => '8.x-1.0',
'hidden' => FALSE,
),
'bbb_update_test' => array(
],
'bbb_update_test' => [
'project' => 'bbb_update_test',
'version' => '8.x-1.0',
'hidden' => FALSE,
),
'ccc_update_test' => array(
],
'ccc_update_test' => [
'project' => 'ccc_update_test',
'version' => '8.x-1.0',
'hidden' => FALSE,
),
);
],
];
$this->config('update_test.settings')->set('system_info', $system_info)->save();
// Ensure that the update information is correct before testing.
$this->drupalGet('admin/reports/updates');
$xml_mapping = array(
$xml_mapping = [
'drupal' => '0.0',
'aaa_update_test' => '1_0',
'bbb_update_test' => 'does-not-exist',
'ccc_update_test' => '1_0',
);
];
$this->refreshUpdateStatus($xml_mapping);
$this->assertText(t('Up to date'));
@ -386,33 +386,33 @@ class UpdateContribTest extends UpdateTestBase {
* hook_update_status_alter() to try to mark this as missing a security
* update, then assert if we see the appropriate warnings on the right pages.
*/
function testHookUpdateStatusAlter() {
public function testHookUpdateStatusAlter() {
$update_test_config = $this->config('update_test.settings');
$update_admin_user = $this->drupalCreateUser(array('administer site configuration', 'administer software updates'));
$update_admin_user = $this->drupalCreateUser(['administer site configuration', 'administer software updates']);
$this->drupalLogin($update_admin_user);
$system_info = array(
'#all' => array(
$system_info = [
'#all' => [
'version' => '8.0.0',
),
'aaa_update_test' => array(
],
'aaa_update_test' => [
'project' => 'aaa_update_test',
'version' => '8.x-1.0',
'hidden' => FALSE,
),
);
],
];
$update_test_config->set('system_info', $system_info)->save();
$update_status = array(
'aaa_update_test' => array(
$update_status = [
'aaa_update_test' => [
'status' => UPDATE_NOT_SECURE,
),
);
],
];
$update_test_config->set('update_status', $update_status)->save();
$this->refreshUpdateStatus(
array(
[
'drupal' => '0.0',
'aaa_update_test' => '1_0',
)
]
);
$this->drupalGet('admin/reports/updates');
$this->assertRaw('<h3>' . t('Modules') . '</h3>');
@ -421,7 +421,7 @@ class UpdateContribTest extends UpdateTestBase {
// Visit the reports page again without the altering and make sure the
// status is back to normal.
$update_test_config->set('update_status', array())->save();
$update_test_config->set('update_status', [])->save();
$this->drupalGet('admin/reports/updates');
$this->assertRaw('<h3>' . t('Modules') . '</h3>');
$this->assertNoText(t('Security update required!'));
@ -433,7 +433,7 @@ class UpdateContribTest extends UpdateTestBase {
$this->assertText(t('Security update'));
// Turn the altering back off and visit the Update manager UI.
$update_test_config->set('update_status', array())->save();
$update_test_config->set('update_status', [])->save();
$this->drupalGet('admin/modules/update');
$this->assertNoText(t('Security update'));
}

View file

@ -21,7 +21,7 @@ class UpdateCoreTest extends UpdateTestBase {
protected function setUp() {
parent::setUp();
$admin_user = $this->drupalCreateUser(array('administer site configuration', 'administer modules', 'administer themes'));
$admin_user = $this->drupalCreateUser(['administer site configuration', 'administer modules', 'administer themes']);
$this->drupalLogin($admin_user);
$this->drupalPlaceBlock('local_actions_block');
}
@ -33,23 +33,23 @@ class UpdateCoreTest extends UpdateTestBase {
* The version.
*/
protected function setSystemInfo($version) {
$setting = array(
'#all' => array(
$setting = [
'#all' => [
'version' => $version,
),
);
],
];
$this->config('update_test.settings')->set('system_info', $setting)->save();
}
/**
* Tests the Update Manager module when no updates are available.
*/
function testNoUpdatesAvailable() {
foreach (array(0, 1) as $minor_version) {
foreach (array(0, 1) as $patch_version) {
foreach (array('-alpha1', '-beta1', '') as $extra_version) {
public function testNoUpdatesAvailable() {
foreach ([0, 1] as $minor_version) {
foreach ([0, 1] as $patch_version) {
foreach (['-alpha1', '-beta1', ''] as $extra_version) {
$this->setSystemInfo("8.$minor_version.$patch_version" . $extra_version);
$this->refreshUpdateStatus(array('drupal' => "$minor_version.$patch_version" . $extra_version));
$this->refreshUpdateStatus(['drupal' => "$minor_version.$patch_version" . $extra_version]);
$this->standardTests();
$this->assertText(t('Up to date'));
$this->assertNoText(t('Update available'));
@ -63,16 +63,16 @@ class UpdateCoreTest extends UpdateTestBase {
/**
* Tests the Update Manager module when one normal update is available.
*/
function testNormalUpdateAvailable() {
public function testNormalUpdateAvailable() {
$this->setSystemInfo('8.0.0');
// Ensure that the update check requires a token.
$this->drupalGet('admin/reports/updates/check');
$this->assertResponse(403, 'Accessing admin/reports/updates/check without a CSRF token results in access denied.');
foreach (array(0, 1) as $minor_version) {
foreach (array('-alpha1', '-beta1', '') as $extra_version) {
$this->refreshUpdateStatus(array('drupal' => "$minor_version.1" . $extra_version));
foreach ([0, 1] as $minor_version) {
foreach (['-alpha1', '-beta1', ''] as $extra_version) {
$this->refreshUpdateStatus(['drupal' => "$minor_version.1" . $extra_version]);
$this->standardTests();
$this->drupalGet('admin/reports/updates');
$this->clickLink(t('Check manually'));
@ -130,12 +130,12 @@ class UpdateCoreTest extends UpdateTestBase {
/**
* Tests the Update Manager module when a major update is available.
*/
function testMajorUpdateAvailable() {
foreach (array(0, 1) as $minor_version) {
foreach (array(0, 1) as $patch_version) {
foreach (array('-alpha1', '-beta1', '') as $extra_version) {
public function testMajorUpdateAvailable() {
foreach ([0, 1] as $minor_version) {
foreach ([0, 1] as $patch_version) {
foreach (['-alpha1', '-beta1', ''] as $extra_version) {
$this->setSystemInfo("8.$minor_version.$patch_version" . $extra_version);
$this->refreshUpdateStatus(array('drupal' => '9'));
$this->refreshUpdateStatus(['drupal' => '9']);
$this->standardTests();
$this->drupalGet('admin/reports/updates');
$this->clickLink(t('Check manually'));
@ -156,10 +156,10 @@ class UpdateCoreTest extends UpdateTestBase {
/**
* Tests the Update Manager module when a security update is available.
*/
function testSecurityUpdateAvailable() {
foreach (array(0, 1) as $minor_version) {
public function testSecurityUpdateAvailable() {
foreach ([0, 1] as $minor_version) {
$this->setSystemInfo("8.$minor_version.0");
$this->refreshUpdateStatus(array('drupal' => "$minor_version.2-sec"));
$this->refreshUpdateStatus(['drupal' => "$minor_version.2-sec"]);
$this->standardTests();
$this->assertNoText(t('Up to date'));
$this->assertNoText(t('Update available'));
@ -174,20 +174,20 @@ class UpdateCoreTest extends UpdateTestBase {
/**
* Ensures proper results where there are date mismatches among modules.
*/
function testDatestampMismatch() {
$system_info = array(
'#all' => array(
public function testDatestampMismatch() {
$system_info = [
'#all' => [
// We need to think we're running a -dev snapshot to see dates.
'version' => '8.1.0-dev',
'datestamp' => time(),
),
'block' => array(
],
'block' => [
// This is 2001-09-09 01:46:40 GMT, so test for "2001-Sep-".
'datestamp' => '1000000000',
),
);
],
];
$this->config('update_test.settings')->set('system_info', $system_info)->save();
$this->refreshUpdateStatus(array('drupal' => 'dev'));
$this->refreshUpdateStatus(['drupal' => 'dev']);
$this->assertNoText(t('2001-Sep-'));
$this->assertText(t('Up to date'));
$this->assertNoText(t('Update available'));
@ -197,13 +197,13 @@ class UpdateCoreTest extends UpdateTestBase {
/**
* Checks that running cron updates the list of available updates.
*/
function testModulePageRunCron() {
public function testModulePageRunCron() {
$this->setSystemInfo('8.0.0');
$this->config('update.settings')
->set('fetch.url', Url::fromRoute('update_test.update_test')->setAbsolute()->toString())
->save();
$this->config('update_test.settings')
->set('xml_map', array('drupal' => '0.0'))
->set('xml_map', ['drupal' => '0.0'])
->save();
$this->cronRun();
@ -214,14 +214,14 @@ class UpdateCoreTest extends UpdateTestBase {
/**
* Checks the messages at admin/modules when the site is up to date.
*/
function testModulePageUpToDate() {
public function testModulePageUpToDate() {
$this->setSystemInfo('8.0.0');
// Instead of using refreshUpdateStatus(), set these manually.
$this->config('update.settings')
->set('fetch.url', Url::fromRoute('update_test.update_test')->setAbsolute()->toString())
->save();
$this->config('update_test.settings')
->set('xml_map', array('drupal' => '0.0'))
->set('xml_map', ['drupal' => '0.0'])
->save();
$this->drupalGet('admin/reports/updates');
@ -235,14 +235,14 @@ class UpdateCoreTest extends UpdateTestBase {
/**
* Checks the messages at admin/modules when an update is missing.
*/
function testModulePageRegularUpdate() {
public function testModulePageRegularUpdate() {
$this->setSystemInfo('8.0.0');
// Instead of using refreshUpdateStatus(), set these manually.
$this->config('update.settings')
->set('fetch.url', Url::fromRoute('update_test.update_test')->setAbsolute()->toString())
->save();
$this->config('update_test.settings')
->set('xml_map', array('drupal' => '0.1'))
->set('xml_map', ['drupal' => '0.1'])
->save();
$this->drupalGet('admin/reports/updates');
@ -256,14 +256,14 @@ class UpdateCoreTest extends UpdateTestBase {
/**
* Checks the messages at admin/modules when a security update is missing.
*/
function testModulePageSecurityUpdate() {
public function testModulePageSecurityUpdate() {
$this->setSystemInfo('8.0.0');
// Instead of using refreshUpdateStatus(), set these manually.
$this->config('update.settings')
->set('fetch.url', Url::fromRoute('update_test.update_test')->setAbsolute()->toString())
->save();
$this->config('update_test.settings')
->set('xml_map', array('drupal' => '0.2-sec'))
->set('xml_map', ['drupal' => '0.2-sec'])
->save();
$this->drupalGet('admin/reports/updates');
@ -295,8 +295,8 @@ class UpdateCoreTest extends UpdateTestBase {
/**
* Tests the Update Manager module when the update server returns 503 errors.
*/
function testServiceUnavailable() {
$this->refreshUpdateStatus(array(), '503-error');
public function testServiceUnavailable() {
$this->refreshUpdateStatus([], '503-error');
// Ensure that no "Warning: SimpleXMLElement..." parse errors are found.
$this->assertNoText('SimpleXMLElement');
$this->assertUniqueText(t('Failed to get available update data for one project.'));
@ -305,13 +305,13 @@ class UpdateCoreTest extends UpdateTestBase {
/**
* Tests that exactly one fetch task per project is created and not more.
*/
function testFetchTasks() {
$projecta = array(
public function testFetchTasks() {
$projecta = [
'name' => 'aaa_update_test',
);
$projectb = array(
];
$projectb = [
'name' => 'bbb_update_test',
);
];
$queue = \Drupal::queue('update_fetch_tasks');
$this->assertEqual($queue->numberOfItems(), 0, 'Queue is empty');
update_create_fetch_task($projecta);
@ -331,14 +331,14 @@ class UpdateCoreTest extends UpdateTestBase {
/**
* Checks language module in core package at admin/reports/updates.
*/
function testLanguageModuleUpdate() {
public function testLanguageModuleUpdate() {
$this->setSystemInfo('8.0.0');
// Instead of using refreshUpdateStatus(), set these manually.
$this->config('update.settings')
->set('fetch.url', Url::fromRoute('update_test.update_test')->setAbsolute()->toString())
->save();
$this->config('update_test.settings')
->set('xml_map', array('drupal' => '0.1'))
->set('xml_map', ['drupal' => '0.1'])
->save();
$this->drupalGet('admin/reports/updates');
@ -349,7 +349,7 @@ class UpdateCoreTest extends UpdateTestBase {
* Ensures that the local actions appear.
*/
public function testLocalActions() {
$admin_user = $this->drupalCreateUser(array('administer site configuration', 'administer modules', 'administer software updates', 'administer themes'));
$admin_user = $this->drupalCreateUser(['administer site configuration', 'administer modules', 'administer software updates', 'administer themes']);
$this->drupalLogin($admin_user);
$this->drupalGet('admin/modules');

View file

@ -14,7 +14,7 @@ class UpdateDeleteFileIfStaleTest extends UpdateTestBase {
*
* @var array
*/
public static $modules = array('update');
public static $modules = ['update'];
/**
* {@inheritdoc}
@ -26,7 +26,7 @@ class UpdateDeleteFileIfStaleTest extends UpdateTestBase {
/**
* Tests the deletion of stale files.
*/
function testUpdateDeleteFileIfStale() {
public function testUpdateDeleteFileIfStale() {
$file_name = file_unmanaged_save_data($this->randomMachineName());
$this->assertNotNull($file_name);

View file

@ -63,7 +63,7 @@ abstract class UpdateTestBase extends WebTestBase {
protected function refreshUpdateStatus($xml_map, $url = 'update-test') {
// Tell the Update Manager module to fetch from the URL provided by
// update_test module.
$this->config('update.settings')->set('fetch.url', Url::fromUri('base:' . $url, array('absolute' => TRUE))->toString())->save();
$this->config('update.settings')->set('fetch.url', Url::fromUri('base:' . $url, ['absolute' => TRUE])->toString())->save();
// Save the map for UpdateTestController::updateTest() to use.
$this->config('update_test.settings')->set('xml_map', $xml_map)->save();
// Manually check the update status.

View file

@ -18,11 +18,11 @@ class UpdateUploadTest extends UpdateTestBase {
*
* @var array
*/
public static $modules = array('update', 'update_test');
public static $modules = ['update', 'update_test'];
protected function setUp() {
parent::setUp();
$admin_user = $this->drupalCreateUser(array('administer modules', 'administer software updates', 'administer site configuration'));
$admin_user = $this->drupalCreateUser(['administer modules', 'administer software updates', 'administer site configuration']);
$this->drupalLogin($admin_user);
}
@ -39,23 +39,23 @@ class UpdateUploadTest extends UpdateTestBase {
// emits a notice in strict mode.
$imageTestFiles = $this->drupalGetTestFiles('image');
$invalidArchiveFile = reset($imageTestFiles);
$edit = array(
$edit = [
'files[project_upload]' => $invalidArchiveFile->uri,
);
];
// This also checks that the correct archive extensions are allowed.
$this->drupalPostForm('admin/modules/install', $edit, t('Install'));
$this->assertText(t('Only files with the following extensions are allowed: @archive_extensions.', array('@archive_extensions' => archiver_get_extensions())), 'Only valid archives can be uploaded.');
$this->assertText(t('Only files with the following extensions are allowed: @archive_extensions.', ['@archive_extensions' => archiver_get_extensions()]), 'Only valid archives can be uploaded.');
$this->assertUrl('admin/modules/install');
// Check to ensure an existing module can't be reinstalled. Also checks that
// the archive was extracted since we can't know if the module is already
// installed until after extraction.
$validArchiveFile = __DIR__ . '/../../tests/aaa_update_test.tar.gz';
$edit = array(
$edit = [
'files[project_upload]' => $validArchiveFile,
);
];
$this->drupalPostForm('admin/modules/install', $edit, t('Install'));
$this->assertText(t('@module_name is already installed.', array('@module_name' => 'AAA Update test')), 'Existing module was extracted and not reinstalled.');
$this->assertText(t('@module_name is already installed.', ['@module_name' => 'AAA Update test']), 'Existing module was extracted and not reinstalled.');
$this->assertUrl('admin/modules/install');
// Ensure that a new module can be extracted and installed.
@ -64,16 +64,16 @@ class UpdateUploadTest extends UpdateTestBase {
$installedInfoFilePath = $this->container->get('update.root') . '/' . $moduleUpdater::getRootDirectoryRelativePath() . '/update_test_new_module/update_test_new_module.info.yml';
$this->assertFalse(file_exists($installedInfoFilePath), 'The new module does not exist in the filesystem before it is installed with the Update Manager.');
$validArchiveFile = __DIR__ . '/../../tests/update_test_new_module/8.x-1.0/update_test_new_module.tar.gz';
$edit = array(
$edit = [
'files[project_upload]' => $validArchiveFile,
);
];
$this->drupalPostForm('admin/modules/install', $edit, t('Install'));
// Check that submitting the form takes the user to authorize.php.
$this->assertUrl('core/authorize.php');
$this->assertTitle('Update manager | Drupal');
// Check for a success message on the page, and check that the installed
// module now exists in the expected place in the filesystem.
$this->assertRaw(t('Installed %project_name successfully', array('%project_name' => 'update_test_new_module')));
$this->assertRaw(t('Installed %project_name successfully', ['%project_name' => 'update_test_new_module']));
$this->assertTrue(file_exists($installedInfoFilePath), 'The new module exists in the filesystem after it is installed with the Update Manager.');
// Ensure the links are relative to the site root and not
// core/authorize.php.
@ -98,27 +98,27 @@ class UpdateUploadTest extends UpdateTestBase {
$this->assertEqual($info['version'], '8.x-1.0');
// Enable the module.
$this->drupalPostForm('admin/modules', array('modules[Testing][update_test_new_module][enable]' => TRUE), t('Install'));
$this->drupalPostForm('admin/modules', ['modules[update_test_new_module][enable]' => TRUE], t('Install'));
// Define the update XML such that the new module downloaded above needs an
// update from 8.x-1.0 to 8.x-1.1.
$update_test_config = $this->config('update_test.settings');
$system_info = array(
'update_test_new_module' => array(
$system_info = [
'update_test_new_module' => [
'project' => 'update_test_new_module',
),
);
],
];
$update_test_config->set('system_info', $system_info)->save();
$xml_mapping = array(
$xml_mapping = [
'update_test_new_module' => '1_1',
);
];
$this->refreshUpdateStatus($xml_mapping);
// Run the updates for the new module.
$this->drupalPostForm('admin/reports/updates/update', array('projects[update_test_new_module]' => TRUE), t('Download these updates'));
$this->drupalPostForm(NULL, array('maintenance_mode' => FALSE), t('Continue'));
$this->drupalPostForm('admin/reports/updates/update', ['projects[update_test_new_module]' => TRUE], t('Download these updates'));
$this->drupalPostForm(NULL, ['maintenance_mode' => FALSE], t('Continue'));
$this->assertText(t('Update was completed successfully.'));
$this->assertRaw(t('Installed %project_name successfully', array('%project_name' => 'update_test_new_module')));
$this->assertRaw(t('Installed %project_name successfully', ['%project_name' => 'update_test_new_module']));
// Parse the info file again to check that the module has been updated to
// 8.x-1.1.
@ -129,7 +129,7 @@ class UpdateUploadTest extends UpdateTestBase {
/**
* Ensures that archiver extensions are properly merged in the UI.
*/
function testFileNameExtensionMerging() {
public function testFileNameExtensionMerging() {
$this->drupalGet('admin/modules/install');
// Make sure the bogus extension supported by update_test.module is there.
$this->assertPattern('/file extensions are supported:.*update-test-extension/', "Found 'update-test-extension' extension.");
@ -140,15 +140,15 @@ class UpdateUploadTest extends UpdateTestBase {
/**
* Checks the messages on update manager pages when missing a security update.
*/
function testUpdateManagerCoreSecurityUpdateMessages() {
$setting = array(
'#all' => array(
public function testUpdateManagerCoreSecurityUpdateMessages() {
$setting = [
'#all' => [
'version' => '8.0.0',
),
);
],
];
$this->config('update_test.settings')
->set('system_info', $setting)
->set('xml_map', array('drupal' => '0.2-sec'))
->set('xml_map', ['drupal' => '0.2-sec'])
->save();
$this->config('update.settings')
->set('fetch.url', Url::fromRoute('update_test.update_test')->setAbsolute()->toString())

View file

@ -62,7 +62,7 @@ class UpdateFetcher implements UpdateFetcherInterface {
$data = '';
try {
$data = (string) $this->httpClient
->get($url, array('headers' => array('Accept' => 'text/xml')))
->get($url, ['headers' => ['Accept' => 'text/xml']])
->getBody();
}
catch (RequestException $exception) {

View file

@ -7,6 +7,26 @@ namespace Drupal\update;
*/
interface UpdateFetcherInterface {
/**
* Project's status cannot be checked.
*/
const NOT_CHECKED = -1;
/**
* No available update data was found for project.
*/
const UNKNOWN = -2;
/**
* There was a failure fetching available update data for this project.
*/
const NOT_FETCHED = -3;
/**
* We need to (re)fetch available update data for this project.
*/
const FETCH_PENDING = -4;
/**
* Returns the base of the URL to fetch available update data for a project.
*

View file

@ -91,7 +91,7 @@ class UpdateManager implements UpdateManagerInterface {
$this->keyValueStore = $key_value_expirable_factory->get('update');
$this->themeHandler = $theme_handler;
$this->availableReleasesTempStore = $key_value_expirable_factory->get('update_available_releases');
$this->projects = array();
$this->projects = [];
}
/**
@ -151,11 +151,11 @@ class UpdateManager implements UpdateManagerInterface {
* {@inheritdoc}
*/
public function projectStorage($key) {
$projects = array();
$projects = [];
// On certain paths, we should clear the data and recompute the projects for
// update status of the site to avoid presenting stale information.
$route_names = array(
$route_names = [
'update.theme_update',
'system.modules_list',
'system.theme_install',
@ -169,12 +169,12 @@ class UpdateManager implements UpdateManagerInterface {
'update.manual_status',
'update.confirmation_page',
'system.themes_page',
);
];
if (in_array(\Drupal::routeMatch()->getRouteName(), $route_names)) {
$this->keyValueStore->delete($key);
}
else {
$projects = $this->keyValueStore->get($key, array());
$projects = $this->keyValueStore->get($key, []);
}
return $projects;
}
@ -198,10 +198,10 @@ class UpdateManager implements UpdateManagerInterface {
if ($item = $this->updateProcessor->claimQueueItem()) {
if ($this->updateProcessor->processFetchTask($item->data)) {
$context['results']['updated']++;
$context['message'] = $this->t('Checked available update data for %title.', array('%title' => $item->data['info']['name']));
$context['message'] = $this->t('Checked available update data for %title.', ['%title' => $item->data['info']['name']]);
}
else {
$context['message'] = $this->t('Failed to check available update data for %title.', array('%title' => $item->data['info']['name']));
$context['message'] = $this->t('Failed to check available update data for %title.', ['%title' => $item->data['info']['name']]);
$context['results']['failures']++;
}
$context['sandbox']['progress']++;

View file

@ -7,6 +7,31 @@ namespace Drupal\update;
*/
interface UpdateManagerInterface {
/**
* Project is missing security update(s).
*/
const NOT_SECURE = 1;
/**
* Current release has been unpublished and is no longer available.
*/
const REVOKED = 2;
/**
* Current release is no longer supported by the project maintainer.
*/
const NOT_SUPPORTED = 3;
/**
* Project has a new release available, but it is not a security release.
*/
const NOT_CURRENT = 4;
/**
* Project is up to date.
*/
const CURRENT = 5;
/**
* Fetches an array of installed and enabled projects.
*

View file

@ -104,8 +104,8 @@ class UpdateProcessor implements UpdateProcessorInterface {
$this->availableReleasesTempStore = $key_value_expirable_factory->get('update_available_releases');
$this->stateStore = $state_store;
$this->privateKey = $private_key;
$this->fetchTasks = array();
$this->failed = array();
$this->fetchTasks = [];
$this->failed = [];
}
/**
@ -151,7 +151,7 @@ class UpdateProcessor implements UpdateProcessorInterface {
$max_fetch_attempts = $this->updateSettings->get('fetch.max_attempts');
$success = FALSE;
$available = array();
$available = [];
$site_key = Crypt::hmacBase64($base_url, $this->privateKey->get());
$fetch_url_base = $this->updateFetcher->getFetchBaseUrl($project);
$project_name = $project['name'];
@ -219,23 +219,23 @@ class UpdateProcessor implements UpdateProcessorInterface {
if (!isset($xml->short_name)) {
return NULL;
}
$data = array();
$data = [];
foreach ($xml as $k => $v) {
$data[$k] = (string) $v;
}
$data['releases'] = array();
$data['releases'] = [];
if (isset($xml->releases)) {
foreach ($xml->releases->children() as $release) {
$version = (string) $release->version;
$data['releases'][$version] = array();
$data['releases'][$version] = [];
foreach ($release->children() as $k => $v) {
$data['releases'][$version][$k] = (string) $v;
}
$data['releases'][$version]['terms'] = array();
$data['releases'][$version]['terms'] = [];
if ($release->terms) {
foreach ($release->terms->children() as $term) {
if (!isset($data['releases'][$version]['terms'][(string) $term->name])) {
$data['releases'][$version]['terms'][(string) $term->name] = array();
$data['releases'][$version]['terms'][(string) $term->name] = [];
}
$data['releases'][$version]['terms'][(string) $term->name][] = (string) $term->value;
}

View file

@ -59,42 +59,42 @@ class UpdateSettingsForm extends ConfigFormBase implements ContainerInjectionInt
public function buildForm(array $form, FormStateInterface $form_state) {
$config = $this->config('update.settings');
$form['update_check_frequency'] = array(
$form['update_check_frequency'] = [
'#type' => 'radios',
'#title' => t('Check for updates'),
'#default_value' => $config->get('check.interval_days'),
'#options' => array(
'#options' => [
'1' => t('Daily'),
'7' => t('Weekly'),
),
],
'#description' => t('Select how frequently you want to automatically check for new releases of your currently installed modules and themes.'),
);
];
$form['update_check_disabled'] = array(
$form['update_check_disabled'] = [
'#type' => 'checkbox',
'#title' => t('Check for updates of uninstalled modules and themes'),
'#default_value' => $config->get('check.disabled_extensions'),
);
];
$notification_emails = $config->get('notification.emails');
$form['update_notify_emails'] = array(
$form['update_notify_emails'] = [
'#type' => 'textarea',
'#title' => t('Email addresses to notify when updates are available'),
'#rows' => 4,
'#default_value' => implode("\n", $notification_emails),
'#description' => t('Whenever your site checks for available updates and finds new releases, it can notify a list of users via email. Put each address on a separate line. If blank, no emails will be sent.'),
);
];
$form['update_notification_threshold'] = array(
$form['update_notification_threshold'] = [
'#type' => 'radios',
'#title' => t('Email notification threshold'),
'#default_value' => $config->get('notification.threshold'),
'#options' => array(
'#options' => [
'all' => t('All newer versions'),
'security' => t('Only security updates'),
),
'#description' => t('You can choose to send email only if a security update is available, or to be notified about all newer versions. If there are updates available of Drupal core or any of your installed modules and themes, your site will always print a message on the <a href=":status_report">status report</a> page, and will also display an error message on administration pages if there is a security update.', array(':status_report' => $this->url('system.status')))
);
],
'#description' => t('You can choose to send email only if a security update is available, or to be notified about all newer versions. If there are updates available of Drupal core or any of your installed modules and themes, your site will always print a message on the <a href=":status_report">status report</a> page, and will also display an error message on administration pages if there is a security update.', [':status_report' => $this->url('system.status')])
];
return parent::buildForm($form, $form_state);
}
@ -105,8 +105,8 @@ class UpdateSettingsForm extends ConfigFormBase implements ContainerInjectionInt
public function validateForm(array &$form, FormStateInterface $form_state) {
$form_state->set('notify_emails', []);
if (!$form_state->isValueEmpty('update_notify_emails')) {
$valid = array();
$invalid = array();
$valid = [];
$invalid = [];
foreach (explode("\n", trim($form_state->getValue('update_notify_emails'))) as $email) {
$email = trim($email);
if (!empty($email)) {
@ -122,10 +122,10 @@ class UpdateSettingsForm extends ConfigFormBase implements ContainerInjectionInt
$form_state->set('notify_emails', $valid);
}
elseif (count($invalid) == 1) {
$form_state->setErrorByName('update_notify_emails', $this->t('%email is not a valid email address.', array('%email' => reset($invalid))));
$form_state->setErrorByName('update_notify_emails', $this->t('%email is not a valid email address.', ['%email' => reset($invalid)]));
}
else {
$form_state->setErrorByName('update_notify_emails', $this->t('%emails are not valid email addresses.', array('%emails' => implode(', ', $invalid))));
$form_state->setErrorByName('update_notify_emails', $this->t('%emails are not valid email addresses.', ['%emails' => implode(', ', $invalid)]));
}
}