If both the referenced node and the referer node are added to a deployment plan by the user, how does the system know to deploy the referenced node first?

More explicitly how does a) happen in the commented code below?

  // For each of these nodes, if they're not already in the plan,
  // add them and dependency check them.
  foreach ($nids as $nid) {
    // If this node is already in the deployment plan then either
    // a) it was added by the user and will get checked down the line or
    // b) it was added through dependency checks and its already been
    // dealt with. So we just move on in this case.
    if (!deploy_item_is_in_plan($pid, 'node', $nid)) { 

Comments

gdd’s picture

Title: Inconsistency in nodereference_deploy.module » Support circual references
Category: support » feature

Circular references are not supported. I have a patch to manage this for a client but it is really rough. It will take some time to turn into something committable.

pokadan’s picture

Title: Support circual references » Support circular references

Hi, I understand circular references are tough to implement(I wouldn't want to do have to do it..) but I'm not sure this issue fits in this category.

I was just poking about how you make sure node B gets deployed before A if A has a nodereference to B (A->B) and both A and B are added to the deployment plan by the user, and not by node_deploy_check callbacks.

Is there something I've not understood about the module, perhaps.

gdd’s picture

Title: Support circular references » Nodereference weighting can break when users add nodes by hand
Category: feature » bug

Oh I see what you're saying. Yeah that won't work, that's a bug :/

Of course the user could just add A and B would get pulled in automatically.

pokadan’s picture

What's the best way to this? I would create a remove from plan procedure, use that to remove the item from plan and then add it back with the appropriate weight.

Is that how you would do it? Is there a better way?

pokadan’s picture

I'm doing this right now:

foreach ($nids as $nid) {
        // If this node is already in the deployment plan then either
        // a) it was added by the user and will get checked down the line or
        // b) it was added through dependency checks and its already been
        // dealt with. So we just move on in this case.
        if (deploy_item_is_in_plan($pid, 'node', $nid)) {
            //remove it
            deploy_remove_item_from_plan($pid, 'node', $nid);
        }
        // Does this node exist on the remote server?
        $remote_key = deploy_get_remote_key(deploy_uuid_get_node_uuid($nid), 'node');

        // If it doesn't exist or the local version is newer, add it to the deployment plan,
        // with a weight of min(weight) - 1, and then run dependency checking on it
        $plan_node = node_load($nid);
        if ($plan_node && (!$remote_key || $remote_key['changed'] < $plan_node->changed)) {
            deploy_add_to_plan($pid, 'node', $plan_node->type .': '. $plan_node->title, $plan_node->nid, deploy_get_min_weight($pid)-1, DEPLOY_NODE_GROUP_WEIGHT);
        }
        if($plan_node)  module_invoke_all('node_deploy_check', $plan_node);

    }

Two things have changed in the code:
1)If the node is there in the deployment plan I remove it and then re-add it with proper weighting.
2)If the $node loads(it usually does, so I guess always..) run a dependency check on it. This is to prevent the situation where
A->B->C where info in C has changed but because B is unchanged, dependency check ends there.

awaiting any feedback..

johannesdr’s picture

Hi, I am trying to solve the same problem.
I was thinking about making a function that would compare the weights of the current node and the referenced node and that moves the referenced node before the node when needed.
Something like deploy_get_item_weight_in_plan($pid, $nid) and deploy_set_item_weight_in_plan($pid, $nid, $newweight).
But I guess that it is a lot easier to remove the referenced node and add it again. I will test it and let you know what I find.

Note that the same problem occurs with translations. When the translation is added before the original node, the translations are not linked.

johannesdr’s picture

Status: Active » Needs review
StatusFileSize
new3.01 KB

It looks like poka_dan's solution works.
I have made a patch with the changes and will do some more testing.

johannesdr’s picture

StatusFileSize
new5.29 KB

I added the same check for translations.

johannesdr’s picture

FYI, I noticed the same problem with taxonomy terms.
The terms are not added in the right order, and as a result the hyerarchy will be lost.
Because the parents do not yet exist.
You can use the same solution to fix it in taxonomy_deploy_check_taxonomy.

Never mind, this sould be solved by taxonomy_deploy_deploy_check_cleanup. But for some reason it doesn't work anymore. Probbably a local problem in my setup.

dixon_’s picture

Title: Nodereference weighting can break when users add nodes by hand » Weight between items will break deployment if dependencies are added by hand in wrong order
Priority: Normal » Major
Status: Needs review » Needs work
Issue tags: +beta blocker

We have a general problem in the Deploy module here, not checking for this. It concerns not only nodereferences, but all items with dependencies added manually, basically.

I would like to solve this for all items and dependencies currently in Deploy. But also, trying to get the 6.x-1.x branch out the door, I would like to solve it the easiest way possible and oversee this properly in 7.x-2.x.

It's definitely a beta blocker, since many deployment errors probably could lead back to this. Here is one marked as duplicate: #642834: Translated node lose their relationships when deployed

dixon_’s picture

To help version 6.x-1.x move forward, please see this issue: #526936: Find best way to proceeding with 6.x-1.x and more specifically this comment: http://drupal.org/node/526936#comment-4931548