When a node is created by UUID services UPDATE call, the uid property is not set properly.

The proposed solution (patch to follow) introduces a 'uuid_services_update_alter' hook to allow modules to add data to the entity being saved, and implements this on behalf of the node module.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

wodenx’s picture

Status: Active » Needs review
FileSize
851 bytes

Patch

aoturoa’s picture

Issue summary: View changes

This is correctly handled in the standard _node_resource_create() where the 'name' and 'language' are added inside the function. Now that uuid_service module uses _node_resource_update() instead, we can also add the missing values using the standard hook_entity_presave() function:

/**
 * Implements hook_entity_presave().
 */
function mymodule_entity_presave($entity, $type) {
  if ($type == 'node' && $entity->is_new && $entity->uuid_services) {
    if (empty($entity->uid)) {
      global $user;
      $entity->uid = $user->uid;
      $entity->name = $user->name;
    }
    if (!isset($entity->language)) {
      $entity->language = language_default('language');
    }
  }
}
skwashd’s picture

Status: Needs review » Needs work

I agree with aoturoa's suggestion.

recidive’s picture

Status: Needs work » Needs review
FileSize
1.04 KB

Changed to use hook_entity_presave().

  • recidive committed 081682d on 7.x-1.x
    Issue #2043273 by recidive: UUID services does not properly set node...
  • skwashd authored 7e8033c on 7.x-1.x
    Merge pull request #7 from recidive/fs/2043273
    
    Issue #2043273
    
skwashd’s picture

Status: Needs review » Fixed

Thanks for that patch. I've merged it. Closing

skwashd’s picture

Status: Fixed » Needs work

I realised after committing the change, that this logic belongs in node_entity_uuid_presave().

skwashd’s picture

skwashd’s picture

Status: Needs work » Needs review

The attached patch resolves the problem.

recidive’s picture

Status: Needs review » Reviewed & tested by the community
skwashd’s picture

Thanks for the review. Merging.

  • skwashd authored 26db0ca on 7.x-1.x
    Merge pull request #8 from skwashd/2043273
    
    Issue #2043273 by skwashd,...
  • skwashd committed caaff34 on 7.x-1.x
    Issue #2043273 by skwashd, recidive: Improve how UUID services sets the...
skwashd’s picture

Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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