private static function Nodes::processOne in Hook Update Deploy Tools 7
Validated Updates/Imports one page from the contents of an import file.
Parameters
string $node_import: The node object to import.
string $path: The path of the node to import/update.
Return value
array Contains the elements page, operation, and edit_link.
Throws
HudtException In the event of something that fails the import.
1 call to Nodes::processOne()
- Nodes::import in src/
Nodes.php - Performs the unique steps necessary to import node items from export files.
File
- src/
Nodes.php, line 184
Class
- Nodes
- Public method for changing nodes programatically.
Namespace
HookUpdateDeployToolsCode
private static function processOne($node_import, $path) {
// Determine if a node exists at that path.
$language = !empty($node_import->language) ? $node_import->language : LANGUAGE_NONE;
$node_existing = self::getNodeFromPath($path, $language);
$initial_vid = FALSE;
$msg_vars = array(
'@path' => $path,
'@language' => $language,
);
if (!empty($node_existing)) {
// A node already exists at this path. Update it.
$operation = t('Updated');
$op = 'update';
$initial_vid = $node_existing->vid;
$saved_node = self::updateExistingNode($node_import, $node_existing);
}
else {
// No node exists at this path, Check to see if the path is in use.
$exists = self::pathExists($path, $language);
if ($exists) {
// The path exists. Log and throw exception.
$message = "The path belongs to something that is not a node. Import of @language: @path failed.";
throw new HudtException($message, $msg_vars, WATCHDOG_ERROR, TRUE);
}
// Create one.
$operation = t('Created');
$op = 'create';
$saved_node = self::createNewNode($node_import);
}
$msg_vars['@operation'] = $operation;
$saved_path = !empty($saved_node->nid) ? drupal_lookup_path('alias', "node/{$saved_node->nid}", $saved_node->language) : FALSE;
// Begin validation.
// Case race. First to evaluate TRUE wins.
switch (TRUE) {
case empty($saved_node->nid):
// Save did not complete. No nid granted.
$message = '@operation of @language: @path failed: The saved node ended up with no nid.';
$valid = FALSE;
break;
case $saved_path !== $path:
// Path on newly saved node does not match the intended path.
$msg_vars['@savedpath'] = $saved_path;
$message = '@operation failure: The paths do not match. Intended Path: @path Saved Path: @savedpath';
$valid = FALSE;
break;
case $saved_node->title !== $node_import->title:
// Simple validation check to see if the saved title matches.
$msg_vars['@intended_title'] = $node_import->title;
$msg_vars['@saved_title'] = $saved_node->title;
$message = '@operation failure: The titles do not match. Intended title: @intended_title Saved Title: @saved_title';
$valid = FALSE;
break;
// @TODO Consider other node properties that could be validated without
// leading to false negatives.
default:
// Passed all the validations, likely it is valid.
$valid = TRUE;
}
if (!$valid) {
// Validation failed so perform rollback.
self::rollbackImport($op, $saved_node, $initial_vid);
throw new HudtException($message, $msg_vars, WATCHDOG_ERROR, TRUE);
}
$return = array(
'node' => $saved_node,
'operation' => "{$operation}: node/{$saved_node->nid}",
'edit_link' => "node/{$saved_node->nid}/edit",
);
return $return;
}