This was a requirement for a project I was working on. Attached is a module that adds:

  1. Implementation of hook_deploy_entity that adds the $path to the entity prior to deployment on the Client (sending) side (it's not included by default)
  2. Implementation of hook_entity_uuid_save that updates the URL alias on the Server (receiving) side

There's also a bug somewhere in the UUID Services/Services/Path chain that end up with duplicate rows being created in the url_alias table if the $path['pid'] attribute is not set. There's a workaround for this in #2 that removes all but the oldest alias for a node (as far as I know, a node should only have one row in url_alias).

Please advise if there's a better place for this code to go, or if this will be included as part of deploy at some point. This approach worked for our requirements but if there's a better approach out there I'd love to hear (and help implement) it!

Comments

garethsprice’s picture

Status: Active » Needs review
aspilicious’s picture

Ok lets review this

/**
  * We don't want to carry the path ID between systems as it overwrites
  * the alias on the remote host.
  *
  * However, source seems to be ignored on the remote end.
  */
  unset($path['pid']);
  $entity->path = (object) $path;

I don't think that assumption is correct. We can pass everything with the entity. That "extra" information gets only used if we decide to use it. We just should take care of incorrect pid on the server side.

function deploy_node_paths_entity_uuid_save($entity, $entity_type) {
  if ($entity_type == 'node') {
    if (!empty($entity->path['alias'])) {
      $path = path_load('node/' . $entity->nid);

Hmm, is $entity->nid the nid from the source node or the server node. I hope the server one.
IF this is the nid from the server side node. $path would contain the server side path.

And the pid on the server side. Still don't see any reason why to unset pid than as it is unique on each side. And we only use the passed through alias to check if that one is changed.

So if we steal code from node_update_path this could be something like

if (!empty($path['pid']) && empty($path['alias'])) {
  path_delete($path['pid']);
}
// Only save a non-empty alias.
if (!empty($path['alias'])) {
  // Ensure fields for programmatic executions.
  $path['source'] = 'node/' . $node->nid;
  $path['language'] = isset($node->language) ? $node->language : LANGUAGE_NONE;
  path_save($path);
}

(in theory)

Will test this tomorow

aspilicious’s picture

Status: Needs review » Fixed

Url aliases are handled in this module: http://drupal.org/project/url_alias
At the moment it needs the patch I wrote in the issue queue of that module.

I hope this will be part of uuid soon.

dixon_’s picture

Status: Fixed » Closed (won't fix)

Yes, this should be solved over here: #1483824: UUID path module

nelsonko’s picture

Issue summary: View changes

I have just started using Deploy (in Drupal 7) and noted that the destination node has its URL Alias reset to "automatic alias" even if there was a custom one set before (and there is a custom one set in the source node as well). Can you clarify if this is the same issue, or a new different issue? What is the expected behavior in terms of URL path aliases on deploy? See also https://www.drupal.org/node/2570979