I have a nodetype containing both a multi-valued filefield and a multi-valued emvideo field.
And I have a media-mover configuration that:
(a) harvests all the files in the multi-valued filefield
(b) uploads the files to youtube
(c) saves the url's to the newly-created youtube videos in the emvideo field.
My question is about deleting files. If the user deletes a file from the multi-valued filefield, then I also need to: (a) delete the corresponding emvideo field and (b) delete the youtube video itself.
I am currently planning to do this in hook_nodeapi. But I was wondering ... does media_mover have a better way to keep the emfield in synch with its corresponding filefield, so that when the filefield is deleted, the corresponding emfield is deleted as well?
| Comment | File | Size | Author |
|---|---|---|---|
| #15 | mm_emfield.diff | 137 bytes | kobnim |
| #5 | media_mover_api.module.patch | 3.68 KB | kobnim |
| #5 | mm_emfield.module.patch | 819 bytes | kobnim |
Comments
Comment #1
arthurf commentedMedia Mover does support this kind of deleting, however it sounds like you might need to throw in a bit more (and hopefully contribute it back!). I will say that the deletion handling is better in 6.2.x but that is probably not helpful.
There is some code in media_mover_api_node_update() (called on node update) that could be adapated for use by cck and/or emfield. It's not great code, but it would do the trick.
As per node delete, media_mover_api_node_files_delete($node) gets called on node delete. This will call back to the delete functions in hook_media_mover.
mm_emfield does have a function mm_emfield_node_file_delete() but this is not implemented correctly from the looks of it. It is only removing the data from the field rather than from youtube.
So what needs to happen is pretty much what you had planned- catch the file deletion with nodeapi by verifing that all the MM files that exist for this node still exist on this node- media_mover_api_node_update() is an example of how to do this. You could probably contact the maintainer of mm_youtube and ask them to add the delete function there, or just add it to emfield.
I'd be thrilled if media_mover_api_node_update() could be abstracted to handle drupal attached files and cck files.
As a side node, this is way easier on D7 because there are things like hook_file_delete()
Comment #2
kobnim commentedHi Arthur,
You mention:
When do you expect to have an alpha release of 6.2.x? I'm wondering if it might be better to wait, and make my code changes to the 6.2 version.
Comment #3
kobnim commentedHi again,
If I am understanding the code correctly, it looks like the function media_mover_api_node_update($node) invokes
media_mover_api_file_delete_call()when a node attachment has been deleted, but not when a filefield has been deleted.
In particular, when a filefield has just been deleted:
(a)
$node->media_moveris not set.(b)
$node->files[$mm_file['fid']]->removeis not setI can see how to fix (a), by an explicit call to
media_mover_api_node_files_fetch($node->nid)But I am at a loss for how to address (b), i.e. how to tell in hook_nodeapi that a filefield has just been deleted. Any suggestions?
Comment #4
kobnim commentedNever mind. I think I figured out how to handle deleted filefields, using hook_file_references.
Comment #5
kobnim commentedI modified media_mover_api.module and mm_emfield.module, so that when a filefield is deleted, the corresponding emfield is deleted as well.
The changes are in the attached patch files, and were created using "diff". Will that work for you?
Also, if you would like an explanation of the changes, just let me know.
Comment #6
kobnim commentedP.S. I submitted a feature request to media_youtube, to add a 'delete' clause to its media_mover hook.
See http://drupal.org/node/981058
Comment #7
arthurf commentedI'm shooting for a beta release by the first of the year. I'm not sure this is possible, but it seems enough people are filing bug reports that a somewhat usable release should be possible.
Comment #8
arthurf commented@kobnim - as per your patch (yes diff is the way to do it, using cvs diff is even better because then it's tracked against the version you're using) - most of this looks fine. A questions about moving the functionality from $op = 'update' to $op = 'presave' I'm not totally sure if this is the right thing to do. My main concern when I chose to do it with 'update' was the case when a module might get called after media mover- in this case media mover would never know when to delete the file- well maybe on a secondary save. Perhaps I'm wrong here, but that was my thinking anyway.
Otherwise this looks good and I'll commit it. It'd be great to look at mm_node on the 6.2.x branch and implement this there as well.
Comment #9
kobnim commentedThe reason for switching from 'update' to 'presave' is that I was not able to modify the node from within $op = 'update'. After struggling with this for a while, I went back to the hook_nodeapi documentation and found this:
So it seems node_save() is called before $op = "update".
Before switching to $op = "presave", I tried making an explicit call to node_save() from within $op = "update". But that caused an error: "node was modified by another user and could not be saved"
Do you have any suggestions for an alternate approach?
Comment #10
zuriwest commented@kobnim,
Would you mind to share how you got Media Mover and Save to Youtube working with multi-value filefield and embedded video field?
Please describe how you configured filefield(s) and embedded video field(s) for your content type and how you setup the Media Mover Configuration.
Your help is much appreciated!
Comment #11
zuriwest commentedComment #12
kobnim commented@zuriwest
I created a node type containing:
- multi-valued filefield
- multi-valued emvideo field
Then a created a media-mover configuration:
- harvest: harvest files from this filefield
- process: upload the harvested files to youtube
- complete: save result (link to youtube video) in an emfield
When cron runs, media-mover will harvest all of the as-yet-unharvested videos from this filefield, upload them to youtube, and then save the youtube links to the emfield.
Comment #13
kobnim commentedHi Arthur,
Just checking back to see how you would like to handle the proposed patch. (See my comment #9 above.)
Thanks
Comment #14
kobnim commentedSee here for a patch to media_mover_api_node_update() that does not require any changes to hook_nodeapi or mm_emfield.module: http://drupal.org/node/1478246
Comment #15
kobnim commentedHere is a patch for what I believe is a different bug in mm_emfield. The function mm_emfield_node_file_delete() hard-codes the verb to 'complete', rather than looking up the verb in $configuration.
The patch replaces:
if ($url = $file['complete_file']) {With:
Comment #16
kobnim commentedForgot to change category to "bug report" in previous comment.
Comment #17
arthurf commentedCommitted to dev branch