statistics.inc 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. <?php
  2. /**
  3. * @file
  4. * Support for node_counter statistics in core Drupal nodes.
  5. */
  6. class MigrateStatisticsEntityHandler extends MigrateDestinationHandler {
  7. public function __construct() {
  8. $this->registerTypes(array('node'));
  9. }
  10. public function fields() {
  11. if (module_exists('statistics')) {
  12. $fields = array(
  13. 'totalcount' => t('Node: The total number of times the node has been viewed.'),
  14. 'daycount' => t('Node: The total number of times the node has been viewed today.'),
  15. 'timestamp' => t('Node: The most recent time the node has been viewed.'),
  16. );
  17. }
  18. else {
  19. $fields = array();
  20. }
  21. return $fields;
  22. }
  23. public function complete($node, stdClass $row) {
  24. if (module_exists('statistics') && isset($node->nid)) {
  25. $totalcount = isset($node->totalcount) ? $node->totalcount : 0;
  26. $daycount = isset($node->daycount) ? $node->daycount : 0;
  27. $timestamp = isset($node->timestamp) ? $node->timestamp : 0;
  28. db_merge('node_counter')
  29. ->key(array('nid' => $node->nid))
  30. ->fields(array(
  31. 'totalcount' => $totalcount,
  32. 'daycount' => $daycount,
  33. 'timestamp' => $timestamp,
  34. ))
  35. ->execute();
  36. }
  37. }
  38. }