/**
 * Submit and publish the scheduled revision.
 */
function ers_entity_schedule_full_form_submit($form, &$form_state) {
  $entity_type = $form_state['entity_type'];
  $entity = $form_state['entity'];
  list($entity_id, $revision_id, $bundle) = entity_extract_ids($entity_type, $entity);

  ers_entity_schedule_form_submit($form, $form_state, $entity_type, $entity);

  $handler = ers_entity_plugin_get_handler($entity_type);
  $handler->update_entity_schedule($entity, $entity->ers_new_schedule, $form_state['new_revision_id']);

  // If this was an immediate publication we have to update the entity state
  // as well.
  if ($entity->ers_new_schedule <= time()) {
    $entity->ers_retain_draft = TRUE;
    $handler->update_entity_state($entity);

    // We also need to make sure this gets saved later so that the published
    // flag is correct in this case.
    if ($handler->supports_publishing_flag) {
      ers_set_entity_saved($entity_type, $entity_id, $entity);
    }

  }
}

The entity that gets saved into drupal_static() comes from form values, and misses any properties that would have been added by hook_field_load(). This causes a problem in the following case:

Original entity has no file attachments.

File attachment is added and the node saved.

file_field_attach_update() expects $entity->original to have been populated by hook_field_load() (in the case of file module this means adding the data from the {file_managed} table, but it's not. This in turn causes the file_field_delete_file() call to trigger PHP errors since it's looking for properties not set on the object.

A field_attach_load() call on the $entity might be enough.

CommentFileSizeAuthor
#1 ers_file_field_2038157-1.patch437 bytescatch

Comments

catch’s picture

Status: Active » Needs review
StatusFileSize
new437 bytes

Here's a patch.

File field arguably shouldn't expect the file values themselves to be loaded, but this solves it on the ERS side.

catch’s picture

Status: Needs review » Needs work

Patch is wrong - it allows filefield to delete the files, but we don't actually want those files deleted!