You are here

function devel_generate_add_statistics in Devel 4.x

Same name and namespace in other branches
  1. 8.3 devel_generate/devel_generate.module \devel_generate_add_statistics()
  2. 8 devel_generate/devel_generate.module \devel_generate_add_statistics()
  3. 8.2 devel_generate/devel_generate.module \devel_generate_add_statistics()
  4. 6 devel_generate.inc \devel_generate_add_statistics()
  5. 7 devel_generate/devel_generate.inc \devel_generate_add_statistics()

Generate statistics information for a node.

Parameters

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

1 call to devel_generate_add_statistics()
devel_generate_entity_insert in devel_generate/devel_generate.module
Implements hook_entity_insert().

File

devel_generate/devel_generate.module, line 168

Code

function devel_generate_add_statistics(NodeInterface $node) {
  $statistic = [
    'nid' => $node
      ->id(),
    'totalcount' => mt_rand(0, 500),
    'timestamp' => \Drupal::time()
      ->getRequestTime() - mt_rand(0, $node
      ->getCreatedTime()),
  ];
  $statistic['daycount'] = mt_rand(0, $statistic['totalcount']);
  $database = \Drupal::database();
  $database
    ->insert('node_counter')
    ->fields($statistic)
    ->execute();
}