You are here

function scald_update_7006 in Scald: Media Management made easy 7

Migrate {scald_context_type_transcoder} into {scald_context_config}.

File

./scald.install, line 517

Code

function scald_update_7006() {
  drupal_load('module', 'scald');
  $schema_scald_context_config = array(
    'description' => 'Context configuration.',
    'fields' => array(
      'context' => array(
        'description' => 'The Scald Context slug for a Scald Context. Fk {scald_contexts}.context',
        'type' => 'varchar',
        'length' => SCALD_SLUG_MAX_LENGTH,
        'not null' => TRUE,
      ),
      'transcoder' => array(
        'description' => 'A serialized array of transcoder per format.',
        'type' => 'blob',
        'size' => 'big',
        'not null' => TRUE,
        'serialize' => TRUE,
        'object default' => array(),
      ),
    ),
    'primary key' => array(
      'context',
    ),
    'export' => array(
      'key' => 'context',
      'key name' => 'Context',
      'primary key' => 'context',
      'identifier' => 'context_config',
      'export type string' => 'ctools_type',
      'api' => array(
        'owner' => 'scald',
        'api' => 'context_config',
        'minimum_version' => 1,
        'current_version' => 1,
      ),
    ),
  );
  db_create_table('scald_context_config', $schema_scald_context_config);
  $contexts = array();
  $result = db_select('scald_context_type_transcoder', 's')
    ->fields('s')
    ->execute();
  while ($row = $result
    ->fetchAssoc()) {

    // Let's make the update simple: there is no multiple format settings now.
    $contexts[$row['context']]['transcoder'][$row['type']]['*'] = $row['transcoder'];
  }
  foreach ($contexts as $context => $config) {
    db_insert('scald_context_config')
      ->fields(array(
      'context' => $context,
      'transcoder' => serialize($config['transcoder']),
    ))
      ->execute();
  }
  db_drop_table('scald_context_type_transcoder');
}