function NodeCounter::import

Same name and namespace in other branches
  1. 9 core/modules/statistics/src/Plugin/migrate/destination/NodeCounter.php \Drupal\statistics\Plugin\migrate\destination\NodeCounter::import()
  2. 8.9.x core/modules/statistics/src/Plugin/migrate/destination/NodeCounter.php \Drupal\statistics\Plugin\migrate\destination\NodeCounter::import()
  3. 11.x 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 destination IDs from the previous import of this source row. This is empty the first time a source row is migrated. 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 85

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'),
    ];
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.