Commit d029eeb5 authored by webchick's avatar webchick

Issue #1810880 by Albert Volkman, vijaycs85, barbun, alexpott: Convert...

Issue #1810880 by Albert Volkman, vijaycs85, barbun, alexpott: Convert update_last_check() and update_last_email_notification() variables to CMI system.
parent cda3ffb1
......@@ -1236,6 +1236,35 @@ function update_variables_to_config($config_name, array $variable_map) {
db_delete('variable')->condition('name', array_keys($variable_map), 'IN')->execute();
}
/**
* Updates 7.x variables to state records.
*
* Provides a generalized method to migrate variables from 7.x to 8.x's
* state() system.
*
* @param array $variable_map
* An associative array that maps old variables names to new state record
* names; e.g.:
* @code
* array('old_variable' => 'extension.new_name')
* @endcode
* This would migrate the value contained in variable name 'old_variable' into
* the state item 'extension.new_name'.
* Non-existing variables and variables with NULL values are omitted.
*/
function update_variables_to_state(array $variable_map) {
foreach ($variable_map as $variable_name => $state_name) {
if (NULL !== $value = update_variable_get($variable_name)) {
state()->set($state_name, $value);
}
}
// Delete the migrated variables.
db_delete('variable')
->condition('name', array_keys($variable_map))
->execute();
}
/**
* Helper function to update entities with uuid.
*
......
<?php
/**
* @file
* Definition of Drupal\system\Tests\Upgrade\StateSystemUpgradePathTest.
*/
namespace Drupal\system\Tests\Upgrade;
/**
* Tests upgrade of system variables.
*/
class StateSystemUpgradePathTest extends UpgradePathTestBase {
public static function getInfo() {
return array(
'name' => 'State system upgrade test',
'description' => 'Tests upgrade of system variables to the state system.',
'group' => 'Upgrade path',
);
}
public function setUp() {
$this->databaseDumpFiles = array(
drupal_get_path('module', 'system') . '/tests/upgrade/drupal-7.bare.standard_all.database.php.gz',
drupal_get_path('module', 'system') . '/tests/upgrade/drupal-7.state.system.database.php',
);
parent::setUp();
}
/**
* Tests upgrade of system variables to state system.
*/
public function testSystemVariableUpgrade() {
$this->assertTrue($this->performUpgrade(), 'The upgrade was completed successfully.');
$expected_state = array();
$expected_state['update.last_check'] = array(
'value' => 1304208000,
'variable_name' => 'update_last_check',
);
$expected_state['update.last_email_notification'] = array(
'value' => 1304208000,
'variable_name' => 'update_last_email_notification',
);
foreach ($expected_state as $name => $data) {
$this->assertIdentical(state()->get($name), $data['value']);
$deleted = !db_query('SELECT value FROM {variable} WHERE name = :name', array(':name' => $data['variable_name']))->fetchField();
$this->assertTrue($deleted, format_string('Variable !name has been deleted.', array('!name' => $data['variable_name'])));
}
}
}
<?php
/**
* @file
* Database additions for state system upgrade tests.
*
* This dump only contains data and schema components relevant for system
* functionality. The drupal-7.filled.bare.php file is imported before
* this dump, so the two form the database structure expected in tests
* altogether.
*/
// Update system settings to known values.
db_merge('variable')
->key(array('name' => 'update_last_check'))
->fields(array('value' => serialize(1304208000)))
->execute();
db_merge('variable')
->key(array('name' => 'update_last_email_notification'))
->fields(array('value' => serialize(1304208000)))
->execute();
......@@ -186,7 +186,7 @@ function _update_process_fetch_task($project) {
_update_cache_set('fetch_failures', $fail, $now + (60 * 5));
// Whether this worked or not, we did just (try to) check for updates.
variable_set('update_last_check', $now);
state()->set('update.last_check', $now);
// Now that we processed the fetch task for this project, clear out the
// record in {cache_update} for this task so we're willing to fetch again.
......@@ -378,7 +378,7 @@ function _update_cron_notify() {
// Track when the last mail was successfully sent to avoid sending
// too many e-mails.
if ($message['result']) {
variable_set('update_last_email_notification', REQUEST_TIME);
state()->set('update.last_email_notification', REQUEST_TIME);
}
}
}
......
......@@ -162,3 +162,16 @@ function update_update_8000() {
'update_notification_threshold' => 'notification.threshold',
));
}
/**
* Convert update_last_check, last_email_notification variables to state API.
*
* @ingroup config_upgrade
*/
function update_update_8001() {
$variable_map = array(
'update_last_check' => 'update.last_check',
'update_last_email_notification' => 'update.last_email_notification'
);
update_variables_to_state($variable_map);
}
......@@ -278,7 +278,7 @@ function update_manager_update_form($form, $form_state = array(), $context) {
*/
function theme_update_manager_update_form($variables) {
$form = $variables['form'];
$last = variable_get('update_last_check', 0);
$last = state()->get('update.last_check') ?: 0;
$output = theme('update_last_check', array('last' => $last));
$output .= drupal_render_children($form);
return $output;
......
......@@ -285,7 +285,8 @@ function update_cron() {
$update_config = config('update.settings');
$frequency = $update_config->get('check.interval_days');
$interval = 60 * 60 * 24 * $frequency;
if ((REQUEST_TIME - variable_get('update_last_check', 0)) > $interval) {
$last_check = state()->get('update.last_check') ?: 0;
if ((REQUEST_TIME - $last_check) > $interval) {
// If the configured update interval has elapsed, we want to invalidate
// the cached data for all projects, attempt to re-fetch, and trigger any
// configured notifications about the new status.
......@@ -297,7 +298,8 @@ function update_cron() {
// missing data, and if so, try to fetch the data.
update_get_available(TRUE);
}
if ((REQUEST_TIME - variable_get('update_last_email_notification', 0)) > $interval) {
$last_email_notice = state()->get('update.last_email_notification') ?: 0;
if ((REQUEST_TIME - $last_email_notice) > $interval) {
// If configured time between notifications elapsed, send email about
// updates possibly available.
module_load_include('inc', 'update', 'update.fetch');
......
......@@ -33,7 +33,7 @@ function update_status() {
function theme_update_report($variables) {
$data = $variables['data'];
$last = variable_get('update_last_check', 0);
$last = state()->get('update.last_check') ?: 0;
$output = theme('update_last_check', array('last' => $last));
if (!is_array($data)) {
......
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