NodeUpdateMethod.php in GatherContent 8.4
File
src/Import/NodeUpdateMethod.php
View source
<?php
namespace Drupal\gathercontent\Import;
use Drupal\gathercontent\Entity\OperationItem;
use Drupal\node\Entity\Node;
class NodeUpdateMethod {
const ALWAYS_CREATE = 'always_create';
const UPDATE_IF_NOT_CHANGED = 'update_if_not_changed';
const ALWAYS_UPDATE = 'always_update';
public static function getDestinationNode($gc_id, $node_update_method, $node_type_id, $langcode) {
switch ($node_update_method) {
case NodeUpdateMethod::UPDATE_IF_NOT_CHANGED:
$result = \Drupal::entityQuery('node')
->condition('gc_id', $gc_id)
->sort('created', 'DESC')
->range(0, 1)
->execute();
if ($result) {
$node = Node::load(reset($result));
$query_result = \Drupal::entityQuery('gathercontent_operation_item')
->condition('gc_id', $gc_id)
->sort('changed', 'DESC')
->range(0, 1)
->execute();
$operation = OperationItem::load(reset($query_result));
if ($node
->getChangedTime() === $operation
->getChangedTime()) {
return $node;
}
}
break;
case NodeUpdateMethod::ALWAYS_UPDATE:
$result = \Drupal::entityQuery('node')
->condition('gc_id', $gc_id)
->sort('created', 'DESC')
->range(0, 1)
->execute();
if ($result) {
return Node::load(reset($result));
}
break;
}
return Node::create([
'type' => $node_type_id,
'langcode' => $langcode,
]);
}
}