function ContentDevelGenerate::addNodeStatistics

Generate statistics information for a node.

Parameters

\Drupal\node\NodeInterface $node: A node object.

1 call to ContentDevelGenerate::addNodeStatistics()
ContentDevelGenerate::insertNodeData in devel_generate/src/Plugin/DevelGenerate/ContentDevelGenerate.php

File

devel_generate/src/Plugin/DevelGenerate/ContentDevelGenerate.php, line 874

Class

ContentDevelGenerate
Provides a ContentDevelGenerate plugin.

Namespace

Drupal\devel_generate\Plugin\DevelGenerate

Code

private function addNodeStatistics(NodeInterface $node) : void {
  if (!$this->moduleHandler
    ->moduleExists('statistics')) {
    return;
  }
  $statistic = [
    'nid' => $node->id(),
    'totalcount' => mt_rand(0, 500),
    'timestamp' => $this->time
      ->getRequestTime() - mt_rand(0, $node->getCreatedTime()),
  ];
  $statistic['daycount'] = mt_rand(0, $statistic['totalcount']);
  $this->database
    ->insert('node_counter')
    ->fields($statistic)
    ->execute();
}