function deploy_uuid_nodeapi in Deploy - Content Staging 6
Implementation of hook_nodeapi(),
This mostly relates to managing the mapped nid->uuid mapping. There is some non-uuid-related code below, which I decided to keep in this module anyways for the purposes of code organization.
When a node is deployed, it needs its changed property maintained from one server to the next. Otherwise there can be situations where the live server thinks it has a newer version than staging, when in fact it doesn't. This situation can be exacerbated by time zone differences between the two servers. This is why we jump through all the hoops below in order to save the existing changed timestamp from the pushed in node to save back into the record later. I will write a more detailed explanation of the how/why of this later.
File
- modules/
deploy_uuid/ deploy_uuid.module, line 271 - Deployment UUID management
Code
function deploy_uuid_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {
//watchdog($op, print_r($node, TRUE));
static $node_deploy = FALSE;
static $deploy_changed = FALSE;
switch ($op) {
// Get the uuid into the node object (if present.)
case 'load':
$uuid = db_result(db_query("SELECT uuid FROM {node_uuid} WHERE nid = %d", $node->nid));
if ($uuid) {
return array(
'uuid' => $uuid,
);
}
break;
case 'prepare':
if ($node->deploy) {
$node_deploy = TRUE;
}
break;
case 'presave':
if ($node_deploy) {
$deploy_changed = $node->changed;
}
break;
// Make sure that a new entry gets made in the node_uuid table when new content
// is added.
case 'insert':
if ($node->uuid) {
db_query("INSERT INTO {node_uuid} (nid, uuid) VALUES (%d, '%s')", $node->nid, $node->uuid);
}
else {
db_query("INSERT INTO {node_uuid} (nid, uuid) VALUES (%d, '%s')", $node->nid, deploy_uuid_create_uuid());
}
if ($deploy_changed) {
db_query("UPDATE {node} SET changed = %d WHERE nid = %d", $deploy_changed, $node->nid);
}
break;
case 'update':
if ($deploy_changed) {
db_query("UPDATE {node} SET changed = %d WHERE nid = %d", $deploy_changed, $node->nid);
}
break;
// Clean up node_uuid table when content is deleted.
case 'delete':
db_query("DELETE FROM {node_uuid} WHERE nid = %d", $node->nid);
break;
}
}