Part of #1696224: Remove system_settings_form()
update_settings() uses system_settings_form() and needs to use system_config_form().

Files: 
CommentFileSizeAuthor
#21 config-update.21.patch32.39 KBn3or
PASSED: [[SimpleTest]]: [MySQL] 39,775 pass(es). View
#21 interdiff.txt507 bytesn3or
#18 config-update.18.patch32.46 KBn3or
PASSED: [[SimpleTest]]: [MySQL] 39,772 pass(es). View
#18 interdiff.txt1.36 KBn3or
#16 config-update.16.patch32.46 KBn3or
PASSED: [[SimpleTest]]: [MySQL] 39,768 pass(es). View
#16 interdiff.txt2.57 KBn3or
#15 config-update.15.patch32.45 KBn3or
PASSED: [[SimpleTest]]: [MySQL] 39,779 pass(es). View
#15 interdiff.txt2.56 KBn3or
#13 config-update.13.patch31.49 KBn3or
PASSED: [[SimpleTest]]: [MySQL] 39,773 pass(es). View
#13 interdiff.txt1.04 KBn3or
#10 config-update.10.patch31.36 KBn3or
FAILED: [[SimpleTest]]: [MySQL] 39,633 pass(es), 1 fail(s), and 0 exception(s). View
#10 interdiff.txt1.83 KBn3or
#7 config-update.7.patch32.2 KBn3or
FAILED: [[SimpleTest]]: [MySQL] 39,406 pass(es), 135 fail(s), and 134 exception(s). View
#7 interdiff.txt24.63 KBn3or
#3 config-update.3.patch22.51 KBn3or
FAILED: [[SimpleTest]]: [MySQL] 39,775 pass(es), 0 fail(s), and 4 exception(s). View
#3 interdiff.txt329 bytesn3or
#2 config-update.2.patch22.06 KBn3or
FAILED: [[SimpleTest]]: [MySQL] Failed to run tests: PHP Fatal error encountered during run_tests.sh. See review log for details.. View

Comments

n3or’s picture

Title: Convert simpletest settings to configuration system » Convert update settings to configuration system

Title.

n3or’s picture

Status: Active » Needs review
FileSize
22.06 KB
FAILED: [[SimpleTest]]: [MySQL] Failed to run tests: PHP Fatal error encountered during run_tests.sh. See review log for details.. View

The main update module should be fully converted now. (Upgrade path, yml-file, replacement of variable_*(), naming of configuration options ..)

I removed the constants "UPDATE_MAX_FETCH_TIME" and "UPDATE_MAX_FETCH_ATTEMPTS" (update.module). They were used as variable_get default values only. I set their numeric values as default in update.settings.yml, so they are redundant.

This patch isn`t complete! I will add "update_test_*" and "update_script_*" transformation in next patch version.

n3or’s picture

FileSize
329 bytes
22.51 KB
FAILED: [[SimpleTest]]: [MySQL] 39,775 pass(es), 0 fail(s), and 4 exception(s). View

Forgot to add yml-file.

Status: Needs review » Needs work

The last submitted patch, config-update.3.patch, failed testing.

sun’s picture

+++ b/core/modules/update/config/update.settings.yml

The indentation for nested keys should be 4 spaces... :-/

+++ b/core/modules/update/config/update.settings.yml
@@ -0,0 +1,12 @@
+  fetch_url: ''
...
+  max_fetch_attempts: '2'
+  max_fetch_time: '5'

Would it make sense to put all the fetch settings into a separate 'fetch' key on the top-level? E.g.:

fetch:
    url: ''
    max_attempts: '2'
    timeout: '5'
+++ b/core/modules/update/config/update.settings.yml
@@ -0,0 +1,12 @@
+  disabled: '0'

+++ b/core/modules/update/update.settings.inc
@@ -27,22 +28,22 @@ function update_settings($form) {
     '#title' => t('Check for updates of disabled modules and themes'),
...
+    '#default_value' => $config->get('check.disabled'),

Wow, I was horribly mistaken when I first saw this key and wanted to suggest to change it into 'enabled'...

Let's rename this into 'check.disabled_extensions'

+++ b/core/modules/update/config/update.settings.yml
@@ -0,0 +1,12 @@
+  frequency: '1'

+++ b/core/modules/update/update.fetch.inc
@@ -177,7 +178,7 @@ function _update_process_fetch_task($project) {
+  $frequency = $update_config->get('check.frequency');
   $cid = 'available_releases::' . $project_name;
   _update_cache_set($cid, $available, $now + (60 * 60 * 24 * $frequency));

I had to look up what this key means. Possible alternatives:

check.interval
check.interval_days
check.expire
check.expire_days

All not really ideal, better suggestions welcome.

+++ b/core/modules/update/config/update.settings.yml
@@ -0,0 +1,12 @@
+  emails: {}

+++ b/core/modules/update/update.fetch.inc
@@ -353,7 +357,7 @@ function _update_cron_notify() {
+    $notify_list = $update_config->get('notification.emails');
...
       foreach ($notify_list as $target) {

This seems to be a simple array, so the empty syntax is []

+++ b/core/modules/update/update.fetch.inc
@@ -185,7 +186,7 @@ function _update_process_fetch_task($project) {
   // Whether this worked or not, we did just (try to) check for updates.
-  variable_set('update_last_check', $now);
+  $update_config->set('check.executed', $now)->save();

This variable is "state", not configuration, and thus we should leave it alone.

+++ b/core/modules/update/update.fetch.inc
@@ -328,7 +329,9 @@ function _update_build_fetch_url($project, $site_key = '') {
 function _update_get_fetch_url_base($project) {
-  return isset($project['info']['project status url']) ? $project['info']['project status url'] : variable_get('update_fetch_url', UPDATE_DEFAULT_URL);
+  $config_url = config('update.settings')->get('check.fetch_url');
+  $default_url = !empty($config_url) ? $config_url : UPDATE_DEFAULT_URL;
+  return isset($project['info']['project status url']) ? $project['info']['project status url'] : $default_url;

Let's use a if/else control structure instead of the ternary operator here, so we do not need to load the config object if $project contains a URL already.

+++ b/core/modules/update/update.settings.inc
@@ -12,11 +12,12 @@
+function update_settings($form, $form_state) {

&$form_state always needs to be taken by reference.

+++ b/core/modules/update/update.settings.inc
@@ -106,23 +101,21 @@ function update_settings_validate($form, &$form_state) {
 function update_settings_submit($form, $form_state) {
...
+
+  unset($form_state['notify_emails']);
+  unset($form_state['values']['update_notify_emails']);

I do not understand why this was added? Can we revert it? :)

n3or’s picture

Thank you!

I had to look up what this key means. Possible alternatives:

check.interval
check.interval_days
check.expire
check.expire_days

All not really ideal, better suggestions welcome.

What about something like "check.repeat_interval"?

I do not understand why this was added? Can we revert it? :)

I assumed this code from the original code. Can I remove it? I wasn't sure about that.

n3or’s picture

FileSize
24.63 KB
32.2 KB
FAILED: [[SimpleTest]]: [MySQL] 39,406 pass(es), 135 fail(s), and 134 exception(s). View

Made changes suggested by sun and converted update_test and update_test_script.

n3or’s picture

Status: Needs work » Needs review
sun’s picture

Status: Needs review » Needs work
+++ b/core/includes/update.inc
@@ -345,9 +345,10 @@ function update_module_add_to_system($modules = array()) {
 function update_fix_d8_requirements() {
...
-  if (drupal_get_installed_schema_version('system') < 8000 && !variable_get('update_d8_requirements', FALSE)) {
+  $update_config = config('update.settings');
+  if (drupal_get_installed_schema_version('system') < 8000 && !$update_config->get('d8_requirements')) {
     // @todo: Make critical, first-run changes to the database here.
-    variable_set('update_d8_requirements', TRUE);
+    $update_config->get('d8_requirements', TRUE)->save();
   }

Unfortunately, I overlooked this... this is also state, and/or something we need to resolve differently... let's just revert all the affected code back to variables... :-/

+++ b/core/modules/system/tests/modules/update_script_test/config/update_script_test.settings.yml
@@ -0,0 +1 @@
\ No newline at end of file

+++ b/core/modules/update/tests/modules/update_test/config/update_test.settings.yml
@@ -0,0 +1,3 @@
\ No newline at end of file

...

+++ b/core/modules/update/config/update.settings.yml
@@ -0,0 +1,12 @@
+advanced_project_settings: {}

+++ b/core/modules/update/update.api.php
@@ -83,7 +83,7 @@ function hook_update_projects_alter(&$projects) {
 function hook_update_status_alter(&$projects) {
-  $settings = variable_get('update_advanced_project_settings', array());
+  $settings = config('update.settings')->get('advanced_project_settings');

oh! This key doesn't really exist -- the code you've changed belongs to an example hook implementation in the API documentation for Update module. Let's remove the key from the config file, but keep the change to the example hook code :)

n3or’s picture

FileSize
1.83 KB
31.36 KB
FAILED: [[SimpleTest]]: [MySQL] 39,633 pass(es), 1 fail(s), and 0 exception(s). View

#9 fixed.

n3or’s picture

Status: Needs work » Needs review

..

sun’s picture

Status: Needs review » Needs work

Excellent work. Almost done!

+++ b/core/modules/update/update.install
@@ -77,20 +77,6 @@ function update_install() {
-    'update_last_check',
-    'update_last_email_notification',

We need to re-introduce two variable_del()s for these two state variables. Ideally, along with a

// @todo D8: Convert to new state storage.
n3or’s picture

Status: Needs work » Needs review
FileSize
1.04 KB
31.49 KB
PASSED: [[SimpleTest]]: [MySQL] 39,773 pass(es). View
alexpott’s picture

Status: Needs review » Needs work

Great patch! Couple of minor nitpicks...

+++ b/core/modules/update/tests/modules/update_test/update_test.moduleundefined
@@ -42,7 +42,7 @@ function update_test_menu() {
 /**
  * Implements hook_system_info_alter().
  *
- * Checks the 'update_test_system_info' variable and sees if we need to alter
+ * Checks the 'system_info' setting and sees if we need to alter
  * the system info for the given $file based on the setting. The setting is
  * expected to be a nested associative array. If the key '#all' is defined, its
  * subarray will include .info keys and values for all modules and themes on the

This comment needs to be re-jigged so that each line uses as much of the 80 chars as possible and it should say "Checks the 'update_test.settings:system_info' configuration and..."

+++ b/core/modules/update/tests/modules/update_test/update_test.moduleundefined
@@ -64,7 +64,7 @@ function update_test_system_info_alter(&$info, $file) {
 /**
  * Implements hook_update_status_alter().
  *
- * Checks the 'update_test_update_status' variable and sees if we need to alter
+ * Checks the 'update_status' setting and sees if we need to alter
  * the update status for the given project based on the setting. The setting is
  * expected to be a nested associative array. If the key '#all' is defined, its

As above

n3or’s picture

Status: Needs work » Needs review
FileSize
2.56 KB
32.45 KB
PASSED: [[SimpleTest]]: [MySQL] 39,779 pass(es). View

#14 done! :)

n3or’s picture

FileSize
2.57 KB
32.46 KB
PASSED: [[SimpleTest]]: [MySQL] 39,768 pass(es). View

Refers to #14, forgot to replace "setting" by "configuration". Interdiff refers to patch #13.

aspilicious’s picture

Status: Needs review » Needs work
+++ b/core/modules/update/tests/modules/update_test/update_test.moduleundefined
@@ -42,13 +42,13 @@
+ * theme short name ($file->name) and the subarrays contain settings just for ¶

trailing whitespace

+++ b/core/modules/update/tests/modules/update_test/update_test.moduleundefined
@@ -64,12 +64,13 @@
+ * is defined, its subarray will include .info keys and values for all modules ¶

trailing whitespace

Almost every text editor/ide has options to trim trailing whitespaces on save. It makes your life easier ;)

26 days to next Drupal core point release.

n3or’s picture

FileSize
1.36 KB
32.46 KB
PASSED: [[SimpleTest]]: [MySQL] 39,772 pass(es). View

Argh! Thank you, found and activated this option :)

n3or’s picture

Status: Needs work » Needs review
sun’s picture

Status: Needs review » Needs work

99.9% done! :)

+++ b/core/modules/update/update.install
@@ -157,3 +147,19 @@ function _update_requirement_check($project, $type) {
+function update_update_8000() {
+  update_variables_to_config('update.settings', array(
+    'update_advanced_project_settings' => 'advanced_project_settings',

Let's also remove the variable of the example hook implementation from the module update :)

n3or’s picture

FileSize
507 bytes
32.39 KB
PASSED: [[SimpleTest]]: [MySQL] 39,775 pass(es). View
n3or’s picture

Status: Needs work » Needs review
sun’s picture

Status: Needs review » Reviewed & tested by the community

Awesome!

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 8.x, including the .yml file. Win! :-)

Thanks everyone.

Automatically closed -- issue fixed for 2 weeks with no activity.