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);
}
}
A Drupal 6 CDN setup using Media Mover
After going through all the CDN options available for Drupal 6, I wasn't totally satisfied with any of them. My requirements were thus:
- Move user uploaded files to S3
- Rewrite image URL to S3/CloudFront IF the file has been moved
- Imagecache support
The CDN integration module seemed to be the most promising, but I wasn't crazy about patching core plus running a daemon to handle file processing/uploading. Most of the other approaches I saw all assume that the file exists on the CDN, which is an assumption I'd rather not make when dealing with user uploads.
Media Mover!
I was first introduced to Media Mover at the session at DrupalCon DC, and I've been anxious to use it ever since.