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