Achieve Releases the Media Update Module

Media Update

Achieve Internet has released a new Drupal 7 module named Media Update on Drupal.org. This module simplifies the process of updating media content by allowing replacement of existing files. To install the module, go to www.drupal.org/project/media_update.

Why the Media Update Module is Useful

Do you wish you had the ability to quickly and easily replace a media file in use at various locations on your site? The Media Update module gives you this functionality.

When maintaining websites with many media files, the Media module from drupal.org has become a staple for providing an easy way to upload and insert files into content. The Media module also makes it easy to upload a file one time, save it in a Library, and use it in multiple pieces of content on your site.
While the Media module improves the overall task of inserting and associating files, the process of replacing those files when they become outdated quickly becomes cumbersome. This is because you are forced to go into each piece of content that uses the file, delete the old media file, and add the new one.

Screen Shot - Media Update.png

Engineering Challenges of the Media Update Module

The Media module has plenty of positives, but the architecture doesn't really lend itself to easy updates. Because file types can be restricted at the field level and in context a particular file type may be expected, files should be updated only with files of the same type. For instance, because a particular field expects images - and therefore might have image formatting settings applied - we should, at the very least, not allow users to upload a YouTube video as a replacement for an image file.

The Media module is flexible and allows modules to seamlessly add additional upload mechanisms, media types, and browsing options. This is great for flexibility of content going into the system, but it makes the process of working backward - to restrict the type of upload - much more complex. To protect users, we limited what could be uploaded, and it presented numerous challenges.

The first challenge is that the type of media - for instance YouTube - is divorced from the uploading form. For instance, in the YouTube case, the upload form is in media_internet. Because there was no way to track this back from the file to the form, we added a simple hook to allow us to facilitate the process.  Our hook automatically identifies the proper upload form for media and media_internet based uploads, so any module using either of these base modules should work without issue. Any completely custom media implementation would need to create its own hook implementation to allow updates to occur.

The next challenge was that the upload forms themselves differed in naming convention, field name, and what was being uploaded. Media uploads are true file uploads, but media_internet only posts text. We leveraged our new hook described above to allow us to identify the necessary pieces of information, so our hook returns the proper form to render, the field name where a new file is located, and whether we should expect a standard field or a file. This allowed us to show an update form of the appropriate type and to check if new content has been posted. The type was important because, without it, we could not verify if new content had been posted.

The final challenge was only an issue when making file-based updates.  By default, the file upload system is not set up for updates, so we had to do a little magic to make this work. First, we utilized our hook above to identify when a file was being updated, then we needed to ensure that, rather than getting a new fid, after upload, our file received the fid of the original file, allowing the file to be updated rather than inserted.

Installation and Setup

Installing the Media Update module is as simple as downloading and enabling the module in Drupal.  We don't presently have any configuration options, and we're open to hearing what configuration options would make using Media Update easier or more powerful. When the module is enabled, you should immediately be able to begin replacing any existing media content.

Future Plans

We've done all we can with the current implementation of Media module, and we're going to continue to work on finding ways to help improve the Media module to make work like this easier in the future.   We plan to further test updating media files in new ways so that we can expand or better handle our current use cases.

We're confident that installing and using Media Update is nearly effortless. Feel free to give it a try and see if there's anything we missed or if you have any ideas for future enhancement.

To install the module, go to www.drupal.org/project/media_update.

Comments

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options