Lines: 50.00%
| Line | Hits | Source |
|---|---|---|
| 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() { | |
| 29 | 1 | return $this->select('node_counter', 'nc')->fields('nc'); |
| 30 | } | |
| 31 | ||
| 32 | /** | |
| 33 | * {@inheritdoc} | |
| 34 | */ | |
| 35 | public function fields() { | |
| 36 | 0 | return [ |
| 37 | 0 | 'nid' => $this->t('The node ID.'), |
| 38 | 0 | 'totalcount' => $this->t('The total number of times the node has been viewed.'), |
| 39 | 0 | 'daycount' => $this->t('The total number of times the node has been viewed today.'), |
| 40 | 0 | 'timestamp' => $this->t('The most recent time the node has been viewed.'), |
| 41 | 0 | ]; |
| 42 | } | |
| 43 | ||
| 44 | /** | |
| 45 | * {@inheritdoc} | |
| 46 | */ | |
| 47 | public function getIds() { | |
| 48 | 1 | return [ |
| 49 | 1 | 'nid' => [ |
| 50 | 1 | 'type' => 'integer', |
| 51 | 1 | ], |
| 52 | 1 | ]; |
| 53 | } | |
| 54 | ||
| 55 | } |