You are here

function emfield_update_6005 in Embedded Media Field 6.3

Same name and namespace in other branches
  1. 6 emfield.install \emfield_update_6005()
  2. 6.2 emfield.install \emfield_update_6005()

Add a provider data version column to existing fields.

File

./emfield.install, line 91
This is the emfield.module's install, configuration, and removal file.

Code

function emfield_update_6005() {
  $ret = array();
  include_once drupal_get_path('module', 'content') . '/includes/content.admin.inc';

  // Build a list of fields that need data updating.
  $fields = array();
  foreach (content_types_install() as $type_name => $type_fields) {
    foreach ($type_fields as $field) {
      if (in_array($field['module'], array(
        'emvideo',
        'emimage',
        'emaudio',
      ))) {

        // We only process a given field once.
        $fields[$field['field_name']] = $field;
        $ret[] = array(
          'query' => t('Added provider data version to the %field field.', array(
            '%field' => $field['field_name'],
          )),
          'success' => TRUE,
        );
      }
    }
  }

  // Update database storage.
  foreach ($fields as $field) {
    $new_field = $field;
    unset($field['version']);
    content_alter_db($field, $new_field);
    $ret[] = array(
      'query' => t('Add duration to the %field field.', array(
        '%field' => $field['field_name'],
      )),
      'success' => TRUE,
    );
  }
  content_clear_type_cache(TRUE);
  content_associate_fields('emvideo');
  content_associate_fields('emaudio');
  content_associate_fields('emimage');

  // Build a batch that grabs the duration for each video field.
  $batch = array(
    'title' => t('Importing provider data.'),
    'operations' => array(),
    'file' => drupal_get_path('module', 'emvideo') . '/emfield.install',
  );
  $old_data_keys = array(
    'archive' => 'emvideo_archive_version',
    'bliptv' => 'emvideo_bliptv_data_version',
    'google' => 'emvideo_data_version',
    'myspace' => 'emvideo_myspace_version',
    'ustream' => 'ustream_api_version',
    'ustreamlive' => 'ustreamlive_api_version',
    'yahoomusic' => 'emvideo_yahoomusic_version',
    'youtube' => 'emvideo_youtube_version',
    '8tracks' => 'emaudio_8tracks',
    'brightcove3' => 'emvideo_brightcove3_version',
    'flickr_sets' => 'emvideo_data_version',
    'hulu' => 'emvideo_hulu_version',
  );
  foreach ($fields as $field_name => $field) {
    $batch['operations'][] = array(
      '_emfield_update_fix_data',
      array(
        $field,
        array(),
        $old_data_keys,
      ),
    );
    $ret[] = array(
      'query' => t('Retrieved current provider data for the %field field.', array(
        '%field' => $field['field_name'],
      )),
      'success' => TRUE,
    );
  }
  batch_set($batch);

  // Clear caches.
  cache_clear_all('*', content_cache_tablename(), TRUE);
  cache_clear_all('*', 'cache', TRUE);
  return $ret;
}