function node_deploy_node in Deploy - Content Staging 6
Deploy a node.
Parameters
$node: Node object we are deploying.
Return value
The nid of the new node.
1 call to node_deploy_node()
- node_deploy in modules/
node_deploy/ node_deploy.module - Implementation of hook_deploy(),
File
- modules/
node_deploy/ node_deploy.module, line 125 - Deployment API which enables modules to deploy items between servers.
Code
function node_deploy_node($node) {
// Check remote node info. If the local node and the remote node
// have the same 'changed' value (indicating that no new local changes
// have been made) then just bail and don't bother going through the
// rest.
$remote_key = deploy_get_remote_key($node->uuid, 'node');
if ($node->changed <= $remote_key['changed']) {
return $remote_key['nid'];
}
$remote_nid = isset($remote_key['nid']) ? $remote_key['nid'] : NULL;
// If this node was translated from another node, then set the node's
// tnid properly as well.
if ($node->tnid) {
if ($node->tnid == $node->nid) {
$node->tnid = $remote_nid;
}
else {
$uuid = deploy_uuid_get_node_uuid($node->tnid);
$remote_key = deploy_get_remote_key($uuid, 'node');
$node->tnid = isset($remote_key['nid']) ? $remote_key['nid'] : NULL;
}
}
// When this gets submitted to services, it will be passed through
// drupal_execute() to be saved. The format drupal_execute() expects for
// a submitted node is much different than that created by node_load().
// So we jump through some neat FAPI hooks which get it all sorted out.
// This essentially drupal_get_form() without the render.
$form_id = $node->type . '_node_form';
$form_state = array(
'storage' => NULL,
'submitted' => FALSE,
'post' => '$_POST',
);
$form = drupal_retrieve_form($form_id, $form_state, $node);
drupal_prepare_form($form_id, $form, $form_state);
drupal_process_form($form_id, $form, $form_state);
$node = (object) $form_state['values'];
// Having gotten all the dependencies (supposedly) already deployed based
// on the weight sorting in deploy.module, it should be "easy" now to replace
// all our linked ids with their remote equivalents and go.
// Node author. don't bother checking the remote key if it is admin or anonymous
if ($node->uid > 1) {
$remote_key = deploy_get_remote_key(deploy_uuid_get_user_uuid($node->uid), 'users');
$node->uid = $remote_key['uid'];
}
// Taxonomy handling.
//
// Taxonomy comes to us like this:
// [taxonomy] => Array (
// [<vid>] => Array (
// [<tid>] => <tid>,
// )
// [<vid>] => Array (
// [<tid>] => <tid>,
// [<tid>] => <tid>,
// )
// [tags] => Array (
// [<vid>] => term1, term2
// [<vid>] => term1, term2
// )
// )
//
// except for tags which come like this
//
// This is the transformed array that we will assign to the node object
// when we're done.
if (!empty($node->taxonomy)) {
$taxonomy = array();
// This is the cache array for vocabularies.
$vocabularies = array();
foreach ($node->taxonomy as $vid => $terms) {
// Tags are handled differently for some reason, so they have
// an exception here.
if ($vid == 'tags') {
$taxonomy['tags'] = array();
foreach ($terms as $vid => $tags) {
$remote_data = deploy_get_remote_key(deploy_uuid_get_vocabulary_uuid($vid), 'vocabulary');
$remote_vid = $remote_data['vid'];
$taxonomy['tags'][$remote_vid] = $tags;
}
}
else {
$remote_data = deploy_get_remote_key(deploy_uuid_get_vocabulary_uuid($vid), 'vocabulary');
$remote_vid = $remote_data['vid'];
$taxonomy[$remote_vid] = array();
foreach ($terms as $tid) {
$uuid = deploy_uuid_get_term_uuid($tid);
$remote_data = deploy_get_remote_key(deploy_uuid_get_term_uuid($tid), 'term_data');
$tid = $remote_data['tid'];
$taxonomy[$remote_vid][$tid] = $tid;
}
}
}
$node->taxonomy = $taxonomy;
}
// add this flag because on the other side, there's some special stuff
// done in nodeapi specifically related to deployed nodes vs non-deployed
$node->deploy = TRUE;
// this is getting set unintentionally causing all node bodies to break before
// the first character and I'm not sure why yet. Hammer solution in play.
unset($node->teaser_js);
// We add the remote_nid to the node here so that when we invoke the node_deploy
// hook, other modules have this extra information in case they need it.
$node->remote_nid = $remote_nid;
// Now let all the modules that extend node make their own adjustments
foreach (module_implements('node_deploy') as $module) {
$function = $module . '_node_deploy';
$function($node);
}
// Finally set the node's ID to match the remote nid
if (isset($node->remote_nid)) {
$node->nid = $node->remote_nid;
}
else {
unset($node->nid);
}
// We don't need this anymore.
unset($node->remote_nid);
// And we're off.
$nid = deploy_send(array(
'node.save',
), array(
$node,
));
return $nid;
}