CommentFileSizeAuthor
#3 2289639-3.patch4.69 KBl0ke

Comments

matthiasm11’s picture

I can confirm the issue on media_browser_plus 7.x-3.0-beta3 in combination with webforms 7.x-3.20.

matthiasm11’s picture

Fixed issue by adding a condition for webform uploads in media_browser_plus.file.inc:

/**
 * @file
 * File entity specific hooks.
 */

/**
 * Implements hook_field_attach_presave().
 */
function media_browser_plus_file_presave($entity) {
  // File may not be part of a webform upload. // THIS LINE WAS ADDED
  if (module_exists('webform') && strpos($entity->uri, "public://webform") !== 0 && strpos($entity->uri, "private://webform") !== 0) { // THIS LINE WAS ADDED
    // Set appropriate default folder if necessary.
    if (empty($entity->field_folder[LANGUAGE_NONE][0]['tid'])) {
      $root = media_browser_plus_get_media_root_folder();
      $entity->field_folder[LANGUAGE_NONE] = array(array('tid' => $root->tid));
    }

    // Ensure file is stored in the appropriate folder.
    $folder = taxonomy_term_load($entity->field_folder[LANGUAGE_NONE][0]['tid']);
    $new_path = file_stream_wrapper_uri_normalize(file_uri_scheme($entity->uri) . '://' . media_browser_plus_construct_dir_path($folder) . '/' . basename($entity->uri));
    // Only move file if necessary.
    if ($entity->uri !== $new_path) {
      media_browser_plus_move_file($folder->tid, $entity, FILE_EXISTS_RENAME, FALSE);
    }
  } // THIS LINE WAS ADDED
}

l0ke’s picture

StatusFileSize
new4.69 KB

I faced the same issue and another solution is to define webform scheme and use it instead of public. Don't think this is relevant to the latest webform version, but for 7.x-3.20 you can use this patch. The patch is out of scope of MBP module, the point is just to share a solution.

spasmody’s picture

Issue summary: View changes

I tried both solutions, i.e. MBP patch by matthiasm11 and webform patch by lokeoke but unsuccessfully.
I use MBP 7.x-3.0-beta3+27-dev , Media 7.x-2.0-beta1 and webform 7x-7.10. Does anyone has a solution ?

gambry’s picture

This is a more general issue, affecting every module trying to save a file with file_save_data() in a specific folder (it works if the folder is the scheme root).

I'm having this problem with gmap module, saving the markers in public://js/gmap_markers.js but media_browser_plus overwrites the uri to public://gmap_markers.js.

The point is if there isn't a term on the entity AND uri != the scheme root (so it's a specific folder) media_browser_plus should not change it, leaving the module original settings.

gambry’s picture

I created a patch in the issue "Modules should be able to bypass media file processing" which should help this problem too.

Basically when there isn't a specified field_folder term and there is a default folder ("webform" in your case), it returns immediately without running the MBP actions.

socialnicheguru’s picture

Status: Active » Needs work
gambry’s picture

Status: Needs work » Needs review
Issue tags: +Novice

Wondering why Needs Work. As mentioned on #6 The patch committed from #2252223 should solve the issue.
I see more appropriate Needs Review (+ tagging it as Novice as reviewing is trivial as testing Webform file upload).

l0ke’s picture

Status: Needs review » Fixed

Ok, #2252223: Modules should be able to bypass media file processing is fixed long time ago, and it does make things work.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.