hook_update

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);
  }
}
Syndicate content