You are here

function scald_admin_contexts_form_submit in Scald: Media Management made easy 6

Same name and namespace in other branches
  1. 7 includes/scald.admin.inc \scald_admin_contexts_form_submit()

Submit handler for Scald Contexts admin settings form.

Updated values are written directly back to the database and then the Scald Configuration Object is rebuilt from the db.

File

./scald.admin.inc, line 368

Code

function scald_admin_contexts_form_submit($form, &$form_state) {
  foreach ($form_state['values'] as $key => $value) {
    switch (substr($key, -5)) {

      // Parseability
      case '_pars':
        db_query("\n            UPDATE\n              {scald_contexts}\n            SET\n              parseable = %d\n            WHERE\n              context = '%s'\n          ", $value, substr($key, 0, -5));
        break;

      // end '_pars'
      // Transcoders
      case '_type':
        list($context, $type) = split('@', substr($key, 0, -5));
        list($transcoder, $file_format) = split('@', $value);
        if ($value == '@none') {
          db_query("DELETE FROM {scald_context_type_transcoder} WHERE context = '%s' AND type = '%s'", $context, $type);
        }
        else {
          db_query("\n              INSERT INTO\n                {scald_context_type_transcoder}\n              SET\n                context     = '%s',\n                type        = '%s',\n                file_format = '%s',\n                transcoder  = '%s'\n              ON DUPLICATE KEY\n                UPDATE\n                  file_format  = '%s',\n                  transcoder   = '%s'\n            ", $context, $type, $file_format, $transcoder, $file_format, $transcoder);
        }
        break;
    }
  }

  // The transcoders associated to the contexts might have change. In this case,
  // all the output that we keep in the cache is invalid, which means that we'll
  // need to regenerate it.
  $config_old = variable_get('scald_config', 0);
  $old = $config_old->contexts;
  scald_config_rebuild('contexts');
  $config_new = variable_get('scald_config', 0);
  $new = $config_new->contexts;
  $changed = FALSE;
  foreach ($new as $name => $context) {

    // If the "Make parseable" checkbox was ticked, the atoms needs to be
    // re-rendered.
    if ($new[$name]['parseable'] != $old[$name]['parseable']) {
      $changed = TRUE;
    }

    // Find out if there's a change in the transcoders, which would imply that
    // the atom needs to be rerendered too.
    foreach ($new[$name]['type_format'] as $type => $format) {
      if ($new[$name]['type_format'][$type]['transcoder'] != $old[$name]['type_format'][$type]['transcoder']) {
        $changed = TRUE;
      }
    }
  }

  // If a change was found, clear the cache.
  if ($changed) {
    cache_clear_all('*', 'cache_scald', TRUE);
  }
}