Closed (fixed)
Project:
Migrate Extras
Version:
7.x-2.x-dev
Component:
Media
Priority:
Normal
Category:
Task
Assigned:
Reporter:
Created:
4 Jan 2011 at 10:15 UTC
Updated:
11 Mar 2012 at 22:50 UTC
Jump to comment: Most recent file
I'm in need of migrating our existing photo-database, and because we have various meta-data per photo (license, photographer etc), I thought I would use the Media module for storage because it allows for custom fields..
So my question is this: Is there any plans of adding a Media destination class? If there isn't, how do I set about creating one. I haven't started at looking at the internals of Media, but I'm thinking that it should be fairly similar to the File destination..
Also, if I created one, could it be bundled with a future version of Migrate – or would that introduce a unwanted dependency on the Media module?
| Comment | File | Size | Author |
|---|---|---|---|
| #33 | media_destination.patch | 5.16 KB | jerdavis |
| #29 | MigrateDestinationMedia-full.patch | 7.06 KB | jerdavis |
| #29 | MigrateDestinationMedia-only.patch | 15.73 KB | jerdavis |
| #19 | MigrateMediaFieldHandler.patch | 8.9 KB | mfb |
| #4 | fangelMigrateDestinationMedia.txt | 3.29 KB | fangel |
Comments
Comment #1
moshe weitzman commentedMike just added media module support to migrate_extras - http://drupal.org/cvs?commit=468544
Comment #2
fangel commentedWell, in that case, I'll just point out that migrate_extra's Media destination is broken (it doesn't support custom fields, for instance).
I've created a ticket (#1014496: Media destination doesn't support custom fields.) on the migrate_extras tracker..
Comment #3
mikeryanComment #4
fangel commentedOkay, I've gotten a slightly hack'ish version running now. It's able to import into Media entries with custom fields..
It's based on the file destination, except
$entityTypeis changed tomedia, and$bundleis set to a user-supplied parameter.Then the
importmethod, is copied from the file destination, because I needed to change a few key things:media_loadinstead offile_loadfile_saveandmedia_saveinstead of only justfile_saveI've asked the Media people (#1018290: API for creating Media instances) if there is a better API for adding media entries instead of the sequence of
file_saveandmedia_save..Notes
fidin your import - this will causefile_saveto try and update the fid, instead of creating a new with the specified fidstatusto the valueFILE_STATUS_PERMANENT-Morten
Comment #5
fangel commentedComment #6
fangel commentedAnd now that I've gotten my import into Media to work, I needed a Media field handler too.. So here's a very basic media field handler.
Notes:
fidvalues. You can't (yet) give it names of media entries and have them looked up.fid,title&dataproperties on the field.Update, Jan 26th: Added serialization to the
data-field if it's not already..Comment #7
mikeryanI've updated the media destination to set the entity type and bundle appropriately, and implemented fields() so the available fields are presented in the migrate UI. Actually saving the fields is still broken - see my comment on #1018290: API for creating Media instances.
Comment #8
fangel commentedAs I noted above (and as is implemented in my destination handler), if you call media_save after calling file_save and setting type, it works fine. I agree that this is.. annoying... so let's see what the Media guys come back with on the API question..
Also, what do you think of my proposed media-field handler? It should probably do what the file-field does in regards to uploads too, if given a path not a fid - but the fields has more info than fid - it has title + data (the latter is serialized - I've updated the code-sniplet to reflect this)
Comment #9
mikeryanOK, I've committed a fix to fields not being saved (added a complete() method to call media_save()).
On the media field handler, let's reuse the filefield implementation as much as possible. Is this workable?
Comment #10
fangel commentedI'll checkout your Media Destination on Monday (or possibly, but unlikely, tomorrow), and see if it works as intended (I have a 5000-file/2gb Media import to test it on)
In regards to the Media-field, then the FieldHandler just needs to return something like this
So perhaps it's better to first call FileFields' prepare()-method to get file-references (if the given value is the path to a file, not a fid) processed (but then what about media_save?), and then change add the optional title and data fields afterwards?
I'm semi-sure that the MediaField probably should increase the file_usage table too, but haven't completely looked into this yet.. It might be handled automatically by the Media modules field-processor.
All in all, I think it's a great idea to build upon FileField for the MediaField, but it needs a bit of thought and work to be perfect..
-Morten
Comment #11
fangel commentedOkay, just did a quick test of the updated
MigrateDestinationMedia. It works as intended, sets the fields and everything.One small comment is the order or arguments in
MigrateDestinationMedia::options. You will get a "strict"-warning, because the method-interface is different to the one from MigrationDestinationFile which your extend from. So instead, it should beThis way, the old interface is still applicable, and you wont get a "strict"-warning..
--
A second note, is that I had changed my own destination handler, so it removed a lot of the destination path from the imported image.
Say you have a import that gives you
$file->uri = '/Users/fangel/Sites/old_site/modules/..../library/0/0/0001.jpg';. Then I don't want the file's destination to be $copyDestination/Users/fangel/..., I want it to be $copyDestination/0001.jpg..I can't see why anything but the basename of the uri should be added to the $copyDestination before the file's copied? At least not without a way to turn toggle this behavior.. What's the use-case for this? It means everyone append the full path of the image into their destination path, which results in terribly ugly and long destination paths..
Comment #12
mikeryanI've fixed the options order, thanks.
basename won't work right if you have a situation like
http://example.com/images/2010/12/my_image.jpg
http://example.com/images/2011/01/my_image.jpg
It's not at all unusual in practice for basenames to be duplicated within the file hierarchy.
It seems to me we had something to trim a specified prefix from the URI - it must've been in a particular project, it would be worth generalizing in MigrateDestinationFile.
Comment #13
mikeryanOh, another (perhaps even better) reason to preserve the full path is to preserve the URL of the files, so when you move your old domain to the new server links still work as-is.
Comment #14
fangel commentedExcept, it's the full absolute path it gets imported as, not relative to the webroot.. So I e.g. the file /Users/fangel/Sites/xxx/.../001.jpg sits at /~fangel/xxx/.../001.jpg, relative to my webroot - which you wouldn't be able to tell programatically..
So either use basename and inform people that conflicts are BAD, and they should set their $copyDestination to i.e. public://migration-name, not leave it at public:// because that could cause conflicts
OR use some system to allow string-replacement afterwards (ie replace /Users/fangel/Sites with /~fangel)
But in anyway, this deserves a seperate issue, as it's related to the File destination in the Media module..
Comment #15
FrequenceBanane commentedso, how is it going with MigrateMediaFieldHandler ?
Comment #16
fangel commentedHi,
I don't know where Mike is with having a "official" Media field handler in Migrate Extra, as I haven't been looking at his progress for a while.
If you just need something quick-and-dirty, use the one I posted above (comment #6). I've been using that to import ~6k Media entities, and haven't had a issue with it yet.
-Morten
Comment #17
mfbsubscribe.. will be testing out migrate_extras + media soon.
Comment #18
mfbA couple things I noticed so far: 1) re: MigrateDestinationMedia, media module no longer has media entities, it just has file entities, and 2)
re: MigrateMediaFieldHandler, media fields are pretty similar to file fields, except that a media field contains a file object, while a file field contains a file array. So it won't be quite as simple as returning MigrateFileFieldHandler::prepare() as suggested in #9Nevermind, media fields have a file object when loaded but not when saved.Comment #19
mfbHere's a first stab at MigrateMediaFieldHandler. I couldn't reuse MigrateFileFieldHandler::buildFileArray() as is, but more code could be reused if buildFileArray() were broken up into pieces.
BTW, I think file_fast in MigrateFileFieldHandler is broken: there are a couple instances of
$fids[$source]which doesn't make sense as $source is an object.Comment #20
mikeryanI committed this from Amtrak the other day, and now realize the connection dropped before my reply went through... Testing was minimal, if any problems are found please open a new issue. Thanks!
Comment #22
jazzslider commentedHello!
Based on my experimentation with this functionality this afternoon, it looks as though the patch above was designed back when the Media module exposed its own media entities instead of just making the D7 core file entity fieldable (cf. #1086958: Switch from Media Entity to File Entity for a very extensive discussion of the issue; it was also briefly referenced in this thread at #18). My evidence is that migrate_extras/media.inc still attempts to make use of the media_save() function, which no longer exists.
Unfortunately I'm a bit new to the structure of all these modules, so I'm not entirely sure what would need to change here to ensure compatibility with Media's new approach …that is, although I'm sure that media_save() can no longer be used, I'm not sure that file_save() will be sufficient.
Does anyone have any ideas on this?
Thanks!
Adam
Comment #23
mikeryanFor some reason, I thought I had committed a patch dealing with the changes, but apparently not... OK, I will need to review this when I have time.
Thanks.
Comment #24
mfbyes MigrateDestinationMedia is broken as mentioned in #18. The patch above only dealt with MigrateMediaFieldHandler
Comment #25
Fidelix commentedSubscribing...
Comment #26
jerdavisAnyone put in any further work on this or tested the patch from #19?
Comment #27
alanburke commentedSubscribe
Comment #28
mikeryanI should be fixing this up within a couple of days.
Comment #29
jerdavisI started looking at this today and ended up pretty much starting from scratch. We needed a Media destination for migration, and that was not part of the previous update. I'm attaching two patches, one that replaces all of the media.inc functionality with just a working MigrateDestinationMedia plugin and a second which adds the working destination to the existing media.inc. I'm assuming the field handler will need refactoring as well, so I'll let you decide which to apply.
Comment #30
mikeryanLooked over your patch, and the condition of the field handler, and I think the Migrate module can support most of the need with just a little generalization: #1240928: META: Refactoring of file destination/field handlers.
Comment #31
mikeryanWell, as mentioned at #1240928: META: Refactoring of file destination/field handlers, I've made a couple of tweaks to the Migrate file handler support that were helpful, and I've just now pushed a new media.inc that should be semi-useful for the moment - at least it works for image files, although no luck with youtube references. I've concluded that the Migrate file handling needs some refactoring, but I'd like to get 2.2 released before tackling that.
Comment #32
jerdavisHi MIke,
Any hints on what you're seeing with Videos? Looks like we're running into the same thing. I'll check out your changes and see what I can do.
Jeremiah
Comment #33
jerdavisWell, I've hacked things up a bit to get it to work here for video. I'm attaching a patch.
Key things in this patch
1) Your updates to plugins/destinations/file.inc in Migrate module didn't include some key code from my previous patch that allow for migration of additional meta data into the file entity. Here's the relevant code from my modified prepare() method:
Second, to get videos importing I found I need to call API functions from file_entity and media modules in order to get a more well defined file object. Here's the relevant bit from my modified import() method:
Feels dirty, but it works in my limited testing. I'm sure there's a cleaner way to handle this, perhaps your re-write of the file handling will address it. Let me know if you have some thoughts on this.
Comment #34
mikeryanYes, that's the issue, media needs to do stuff where the file handler has firm control. I'm not going to spend time (of which I have none:-) trying to work around things as they are - I'm looking ahead to refactoring the file handlers, particularly with media in mind.
Comment #35
jerdavisHi MIke,
Sounds good - I'll keep posting updates here if we run into issues in our own migrations in case someone else needs a stop-gap solution.
Jeremiah
Comment #36
wusel commentedI use:
Drupal 7.10
Migrate 7.x-2.x-dev (2011-Dec-16)
Migrate Extras 7.x-2.x-dev (2011-Oct-26)
I get the error-message:
I hope, this error belongs to this issue.
Please help.
Thanks for this very excellent module!
Comment #37
pjcdawkins commentedwusel (#36):
I also get that error, it just seems to be because MigrateDestinationFile hasn't been written with easy extension in mind. It isn't important - just lower the error reporting level in your settings.php or in
admin/config/development/logging.Comment #38
wusel commentedThe error has not gone...
Comment #39
mikeryanPlease open distinct issues in the queue for distinct problems you see, let's not keep tacking everything media-related on to this issue.