You are here

function recipe_update_7000 in Recipe 7

Same name and namespace in other branches
  1. 7.2 recipe.install \recipe_update_7000()

Adds description column to the recipe table.

File

./recipe.install, line 277
Install, update and uninstall functions for the recipe module.

Code

function recipe_update_7000() {

  // Add the new description property to the recipe table.
  db_add_field('recipe', 'description', array(
    'type' => 'text',
  ));

  // Copy the value from the body field created by drupal7 conversion.
  $query = db_select('field_data_body', 'fdb');
  $query
    ->innerJoin('node', 'n', 'n.vid = fdb.revision_id');
  $query
    ->fields('fdb', array(
    'entity_type',
    'bundle',
    'entity_id',
    'revision_id',
    'body_value',
  ))
    ->fields('n', array(
    'nid',
    'type',
    'status',
    'comment',
    'promote',
    'sticky',
    'language',
  ))
    ->condition('n.type', 'recipe')
    ->orderBy('fdb.revision_id', 'ASC');
  $recipes = $query
    ->execute();
  foreach ($recipes as $recipe) {
    db_update('recipe')
      ->fields(array(
      'description' => $recipe->body_value,
    ))
      ->condition('nid', $recipe->nid)
      ->execute();
  }

  // Unbind body field from the recipe node type.
  $field = field_info_field('body');
  $instance = field_info_instance('node', 'body', 'recipe');
  if (!empty($field)) {
    field_delete_instance($instance, FALSE);
  }
}