diff --git a/core/includes/common.inc b/core/includes/common.inc index d3a4c55..14e4357 100644 --- a/core/includes/common.inc +++ b/core/includes/common.inc @@ -4814,9 +4814,9 @@ function drupal_get_hash_salt() { * The private key. */ function drupal_get_private_key() { - if (!($key = variable_get('drupal_private_key', 0))) { + if (!($key = state()->get('system.private_key'))) { $key = drupal_hash_base64(drupal_random_bytes(55)); - variable_set('drupal_private_key', $key); + state()->set('system.private_key', $key); } return $key; } diff --git a/core/includes/update.inc b/core/includes/update.inc index b39eadb..bf11562 100644 --- a/core/includes/update.inc +++ b/core/includes/update.inc @@ -400,6 +400,12 @@ function update_prepare_d8_bootstrap() { $theme_config->save(); $disabled_themes->save(); + // Migrate the private key to state. This is used to create the token for + // the upgrade batch so needs to be be done before the upgrade has begun. + update_variables_to_state(array( + 'drupal_private_key' => 'system.private_key', + )); + // Update the dynamic include paths that might be used before running the // proper update functions. update_prepare_stored_includes(); diff --git a/core/modules/system/lib/Drupal/system/Tests/Upgrade/StateSystemUpgradePathTest.php b/core/modules/system/lib/Drupal/system/Tests/Upgrade/StateSystemUpgradePathTest.php index 4fb1f68..ffa786f 100644 --- a/core/modules/system/lib/Drupal/system/Tests/Upgrade/StateSystemUpgradePathTest.php +++ b/core/modules/system/lib/Drupal/system/Tests/Upgrade/StateSystemUpgradePathTest.php @@ -59,6 +59,10 @@ public function testSystemVariableUpgrade() { 'value' => 'kdm95qppDDlyZrcUOx453YwQqDA4DNmxi4VQcxzFU9M', 'variable_name' => 'cron_key', ); + $expected_state['system.private_key'] = array( + 'value' => 'G38mKqASKus8VGMkMzVuXImYbzspCQ1iRT2iEZpMYmQ', + 'variable_name' => 'drupal_private_key', + ); $expected_state['tracker.index_nid'] = array( 'value' => 0, 'variable_name' => 'tracker_index_nid', diff --git a/core/modules/system/tests/upgrade/drupal-7.state.system.database.php b/core/modules/system/tests/upgrade/drupal-7.state.system.database.php index a6f47ef..605ca5c 100644 --- a/core/modules/system/tests/upgrade/drupal-7.state.system.database.php +++ b/core/modules/system/tests/upgrade/drupal-7.state.system.database.php @@ -48,6 +48,10 @@ ->fields(array('value' => serialize('kdm95qppDDlyZrcUOx453YwQqDA4DNmxi4VQcxzFU9M'))) ->execute(); db_merge('variable') + ->key(array('name' => 'drupal_private_key')) + ->fields(array('value' => serialize('G38mKqASKus8VGMkMzVuXImYbzspCQ1iRT2iEZpMYmQ'))) + ->execute(); +db_merge('variable') ->key(array('name' => 'node_cron_comments_scale')) ->fields(array('value' => serialize(1.0 / 1000))) ->execute();