Import a Media Mover config with an update hook

Media Mover 6.1 has cut and paste style import/export functionality, but no real obvious way to run a config from code or import a config from a file. To solve the problem of deploying a configuration to another environment, I came up with this function that I use in update hooks:

 
function modulename_import($config_filename) {
  if (module_exists('media_mover_api')) {
    $config_code = file_get_contents(drupal_get_path('module', 'modulename') . '/' . $config_filename . '.mm');
 
    // evaluate imported code
    ob_start();
    eval($config_code);
    ob_end_clean();
 
    // create a cache id
    $id = time();
 
    // Store the configuration
    cache_set("media_mover_config_$id", $configuration, 'cache');
    $form_state = array();
    $add_config_form = media_mover_api_add_config_form(array(),$id);
 
    // use form_builder to populate form_state
    form_builder('media_mover_api_add_config_form', $add_config_form, $form_state);
    media_mover_api_add_config_form_submit($add_config_form, $form_state);
  }
}

And here's an example of how you'd use it in an update hook:

/**
 * Add media mover configs
 */

function modulename_update_6004() {
  // Add new configs
  modulename_import('image_nodes');
}

So that assumes you've put the function above in a module called "modulename" and within that directory you have the file "image_nodes.mm" that contains the exported config object.

If this approach feels dirty to you, congratulations, you're sane. I've already written proper Features support with ctools in Media Mover 6.2, but I highly doubt this will be backported into the 6.1 branch. Until 6.2 is ready for me to put it in production, this is will have to do :)