Coverage index

src/Plugin/migrate/source/NodeCounter.php

Lines: 50.00%

LineHitsSource
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Drupal\visitors\Plugin\migrate\source;
6
7
use Drupal\migrate\Plugin\migrate\source\SqlBase;
8
9
/**
10
 * Reads node view counts from the Statistics node_counter table.
11
 *
12
 * The connection is the SqlBase key. It defaults to migrate.
13
 *
14
 * Available configuration keys:
15
 * - node_migrations: (optional) Node migration IDs. When this is empty, node
16
 *   IDs are copied unchanged. When it is set, the visitors_node_counter_id
17
 *   process plugin looks up the destination node ID.
18
 *
19
 * @MigrateSource(
20
 *   id = "visitors_node_counter"
21
 * )
22
 */
23
class NodeCounter extends SqlBase {
24
25
  /**
26
   * {@inheritdoc}
27
   */
28
  public function query() {
291
    return $this->select('node_counter', 'nc')->fields('nc');
30
  }
31
32
  /**
33
   * {@inheritdoc}
34
   */
35
  public function fields() {
360
    return [
370
      'nid' => $this->t('The node ID.'),
380
      'totalcount' => $this->t('The total number of times the node has been viewed.'),
390
      'daycount' => $this->t('The total number of times the node has been viewed today.'),
400
      'timestamp' => $this->t('The most recent time the node has been viewed.'),
410
    ];
42
  }
43
44
  /**
45
   * {@inheritdoc}
46
   */
47
  public function getIds() {
481
    return [
491
      'nid' => [
501
        'type' => 'integer',
511
      ],
521
    ];
53
  }
54
55
}