function dynamic_background_context_update_7000 in Dynamic Background 7.2
Update stored data to use the new database tables.
File
- modules/
dynamic_background_context/ dynamic_background_context.install, line 18 - Installation and update functions for this module.
Code
function dynamic_background_context_update_7000() {
$images = variable_get('dynamic_background_images', array());
$result = db_select('context', 'c')
->fields('c', array(
'reactions',
'name',
))
->execute();
foreach ($result as $row) {
$new = array();
$data = unserialize($row->reactions);
if (isset($data['dynamic_background'])) {
foreach ($data['dynamic_background'] as $id => $background) {
// Create updated data structur for the context UI.
$new[$images[$id]['fid']]['selected'] = $background['selected'];
// Set active background for this context.
if ($background['selected']) {
dynamic_background_set_active($images[$id]['fid'], 'context', $row->name);
}
}
// Update the context configuration.
$data['dynamic_background'] = $new;
// Write data back to the database.
db_update('context')
->fields(array(
'reactions' => serialize($data),
))
->condition('name', $row->name)
->execute();
}
}
return FALSE;
}