function nodereference_node_deploy_check in Deploy - Content Staging 6
Implementation of hook_node_deploy_check().
Used to manage deployment dependencies
Parameters
$nid: Unique identifier of the nodereference we're trying to deploy
File
- modules/
nodereference_deploy/ nodereference_deploy.module, line 64 - Deployment module for nodereferences
Code
function nodereference_node_deploy_check($node) {
// pid of the plan we're deploying
$pid = variable_get('deploy_pid', 0);
// Get an array of all the nodereference fields in the system
$nodereference_fields = nodereference_deploy_get_nodereference_fields();
// This will be an array of the nids of all fields our node
// references
$nids = array();
// Roll through all the possible nodereference fields. If it exists
// in the node, then roll through its values and add them to $nids
// (unless they were already added previously and are not the node
// whose dependencies are currently being checked).
foreach ($nodereference_fields as $field) {
if (property_exists($node, $field)) {
foreach ($node->{$field} as $nodereference) {
if (!empty($nodereference['nid']) && !in_array($nodereference['nid'], $nids) && $nodereference['nid'] != $node->nid) {
$nids[] = $nodereference['nid'];
}
}
}
}
// 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)) {
// 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);
module_invoke_all('node_deploy_check', $plan_node);
}
}
}
}