You are here

function panopoly_widgets_update_7003 in Panopoly Widgets 7

Implementation of hook_update_N().

Move video mediafield data into a file field.

File

./panopoly_widgets.install, line 145
An installation file for Panopoly Widgets

Code

function panopoly_widgets_update_7003(&$sandbox) {

  // Move data from 'field_video_video' to 'field_video_file' directly in the
  // database, so don't have to worry about APIs changing over time.
  $tables = array(
    'field_data_field_video_video' => 'field_data_field_video_file',
    'field_revision_field_video_video' => 'field_revision_field_video_file',
  );
  $fields = array(
    'entity_type',
    'bundle',
    'deleted',
    'entity_id',
    'revision_id',
    'language',
    'delta',
    'field_video_video_fid',
  );
  foreach ($tables as $old_table => $new_table) {
    $result = db_select($old_table, 'f')
      ->fields('f', $fields)
      ->execute();
    foreach ($result as $data) {
      $data = (array) $data;
      $data['field_video_file_display'] = 1;
      $data['field_video_file_fid'] = $data['field_video_video_fid'];
      unset($data['field_video_video_fid']);
      db_insert($new_table)
        ->fields($data)
        ->execute();
    }
  }

  // Finally, delete the field.
  field_delete_field('field_video_video');
}