function recipe_update_7205 in Recipe 7.2
Move recipe sources in {recipe}.source into the new field.
File
- ./
recipe.install, line 548 - Install, update and uninstall functions for the recipe module.
Code
function recipe_update_7205(&$sandbox) {
if (!isset($sandbox['progress'])) {
$sandbox['progress'] = 0;
$sandbox['current_nid'] = 0;
$sandbox['max'] = db_query('SELECT COUNT(DISTINCT nid) FROM {recipe} WHERE source IS NOT NULL')
->fetchField();
}
$query = db_select('recipe', 'r');
$query
->join('node', 'n', 'r.nid = n.nid');
$query
->fields('r', array(
'nid',
'source',
))
->fields('n', array(
'vid',
))
->condition('r.nid', $sandbox['current_nid'], '>')
->isNotNull('source')
->orderBy('nid', 'ASC')
->range(0, 100);
$recipes = $query
->execute();
foreach ($recipes as $recipe) {
db_insert('field_data_recipe_source')
->fields(array(
'entity_type' => 'node',
'bundle' => 'recipe',
'entity_id' => $recipe->nid,
'revision_id' => $recipe->vid,
'language' => LANGUAGE_NONE,
'delta' => 0,
'recipe_source_value' => $recipe->source,
'recipe_source_format' => 'filtered_html',
))
->execute();
$sandbox['progress']++;
$sandbox['current_nid'] = $recipe->nid;
}
$sandbox['#finished'] = empty($sandbox['max']) ? 1 : $sandbox['progress'] / $sandbox['max'];
}