You are here

public function NodeCounter::import in Drupal 9

Same name and namespace in other branches
  1. 8 core/modules/statistics/src/Plugin/migrate/destination/NodeCounter.php \Drupal\statistics\Plugin\migrate\destination\NodeCounter::import()

Import the row.

Derived classes must implement import(), to construct one new object (pre-populated) using ID mappings in the Migration.

Parameters

\Drupal\migrate\Row $row: The row object.

array $old_destination_id_values: (optional) The old destination IDs. Defaults to an empty array.

Return value

array|bool An indexed array of destination IDs in the same order as defined in the plugin's getIds() method if the plugin wants to save the IDs to the ID map, TRUE to indicate success without saving IDs to the ID map, or FALSE to indicate a failure.

Overrides MigrateDestinationInterface::import

File

core/modules/statistics/src/Plugin/migrate/destination/NodeCounter.php, line 83

Class

NodeCounter
Destination for node counter.

Namespace

Drupal\statistics\Plugin\migrate\destination

Code

public function import(Row $row, array $old_destination_id_values = []) {
  $nid = $row
    ->getDestinationProperty('nid');
  $daycount = $row
    ->getDestinationProperty('daycount');
  $totalcount = $row
    ->getDestinationProperty('totalcount');
  $timestamp = $row
    ->getDestinationProperty('timestamp');
  $this->connection
    ->merge('node_counter')
    ->key('nid', $nid)
    ->fields([
    'daycount' => $daycount,
    'totalcount' => $totalcount,
    'timestamp' => $timestamp,
  ])
    ->expression('daycount', '[daycount] + :daycount', [
    ':daycount' => $daycount,
  ])
    ->expression('totalcount', '[totalcount] + :totalcount', [
    ':totalcount' => $totalcount,
  ])
    ->expression('timestamp', 'CASE WHEN [timestamp] > :timestamp1 THEN [timestamp] ELSE :timestamp2 END', [
    ':timestamp1' => $timestamp,
    ':timestamp2' => $timestamp,
  ])
    ->execute();
  return [
    $row
      ->getDestinationProperty('nid'),
  ];
}