You are here

public static function Nodes::updateExistingNode in Hook Update Deploy Tools 7

Create a node from the imported object.

Parameters

object $node: The node object from the import file.

object $node_existing: The node object for the existing node.

Return value

object The resulting node from node_save, broken free of reference to $node.

1 call to Nodes::updateExistingNode()
Nodes::processOne in src/Nodes.php
Validated Updates/Imports one page from the contents of an import file.

File

src/Nodes.php, line 354

Class

Nodes
Public method for changing nodes programatically.

Namespace

HookUpdateDeployTools

Code

public static function updateExistingNode($node, $node_existing) {
  $saved_node = clone $node;
  $saved_node->nid = $node_existing->nid;
  $saved_node->revision = 1;

  // @TODO Need to add handling for field collections.
  // @TODO Need to add handling for entity reference.
  $saved_node->is_new = FALSE;
  $log = !empty($saved_node->log) ? $saved_node->log : '';
  $message = t("Updated from import file by hook_update_deploy_tools Node import.");

  // Concatenate the Updated log to the imported log message.
  $saved_node->log = "{$message}\n {$log}";
  unset($saved_node->workbench_moderation);

  // Map imported states to new moderation states.
  if (!empty($node->workbench_moderation) && !empty($node_existing->workbench_moderation)) {
    $saved_node->workbench_moderation_state_current = $node->workbench_moderation['current']->state;
    $saved_node->workbench_moderation_state_new = $node->workbench_moderation['current']->state;
  }
  node_save($saved_node);
  return $saved_node;
}