I'm using workbench_moderation in a fairly default set up. After embedding a newly uploaded file in the body field using media_wysiwyg and saving a draft, the file usage is 2. After editing the draft and saving, the file usage is now 4, even though there is only one revision. The more times the page is edited the higher the file usage goes.

There is a condition in _media_wysiwyg_filter_add_file_usage_from_fields() that looks wrong. It currently reads:

if (empty($entity->revision) && empty($entity->old_vid) && empty($entity->is_new) && ! empty($entity->original)) {}

If I change the first two empty() calls to !empty(), the new behavior is a bit better. The first save registers file usage twice, and the subsequent edits don't increase the file usage unless a new revision is created. Creating a new revision increases the usage by one, and deleting a revision decreases the usage by one. There is still the bug that the initial save adds 2 to the file usage.

Comments

mstrelan created an issue. See original summary.

mstrelan’s picture

On further investigation I am actually creating a new revision every time the page is saved, so I guess that part is correct. But the file usage is still being processed twice, and I believe that's due to workbench moderation triggering an update.

Adding this to the top of _media_wysiwyg_filter_add_file_usage_from_fields() stops the entity from being processed twice on the same page load.

<?php
  $processed =& drupal_static(__FUNCTION__);
  list($entity_id, $entity_vid, $entity_bundle) = entity_extract_ids($entity_type, $entity);
  if (isset($processed[$entity_type][$entity_id])) {
    return;
  }
  $processed[$entity_type][$entity_id] = TRUE;
?>

This is more generic than targeting workbench_moderation, because other modules could trigger a node update as well.

mstrelan’s picture

Chris Matthews’s picture

Status: Active » Closed (outdated)

Recent versions of media have resolved most of peoples concerns and is compatible with entity translation, multilingual and various advanced configurations. Due to the high volume of inactive and most often irrelevant issues we are Closing this as (outdated). If for whatever reason this issue is important to you AND you still have issues after checking the media recipe documentation, then let us know and we will review your concerns.

Otherwise, see the recipe documentation for how to configure media and for troubleshooting tips OR refer to the media_dev distribution if you want to see a working media setup.

As mentioned, feel free to make some noise in this issue if you still feel it is important to you or someone else.

Thanks,

Media team