You are here

class MigrateStatisticsEntityHandler in Migrate 7.2

Same name and namespace in other branches
  1. 6.2 plugins/destinations/statistics.inc \MigrateStatisticsEntityHandler

@file Support for node_counter statistics in core Drupal nodes.

Hierarchy

Expanded class hierarchy of MigrateStatisticsEntityHandler

1 string reference to 'MigrateStatisticsEntityHandler'
migrate_migrate_api in ./migrate.migrate.inc

File

plugins/destinations/statistics.inc, line 8
Support for node_counter statistics in core Drupal nodes.

View source
class MigrateStatisticsEntityHandler extends MigrateDestinationHandler {
  public function __construct() {
    $this
      ->registerTypes(array(
      'node',
    ));
  }

  /**
   * Implementation of MigrateDestinationHandler::fields().
   */
  public function fields($entity_type, $bundle, $migration = NULL) {
    if (module_exists('statistics')) {
      $fields = array(
        'totalcount' => t('The total number of times the node has been viewed.'),
        'daycount' => t('The total number of times the node has been viewed today.'),
        'timestamp' => t('The most recent time the node has been viewed.'),
      );
    }
    else {
      $fields = array();
    }
    return $fields;
  }
  public function complete($node, stdClass $row) {
    if (module_exists('statistics') && isset($node->nid)) {
      $totalcount = isset($node->totalcount) && is_numeric($node->totalcount) ? $node->totalcount : 0;
      $daycount = isset($node->daycount) && is_numeric($node->daycount) ? $node->daycount : 0;
      $timestamp = isset($node->timestamp) && is_numeric($node->timestamp) ? $node->timestamp : 0;
      db_merge('node_counter')
        ->key(array(
        'nid' => $node->nid,
      ))
        ->fields(array(
        'totalcount' => $totalcount,
        'daycount' => $daycount,
        'timestamp' => $timestamp,
      ))
        ->execute();
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
MigrateHandler::$dependencies protected property List of other handler classes which should be invoked before the current one.
MigrateHandler::$typesHandled protected property List of "types" handled by this handler. Depending on the kind of handler, these may be destination types, field types, etc.
MigrateHandler::getDependencies public function
MigrateHandler::getTypesHandled public function
MigrateHandler::handlesType public function Does this handler handle the given type? 1
MigrateHandler::registerTypes protected function Register a list of types handled by this class
MigrateStatisticsEntityHandler::complete public function
MigrateStatisticsEntityHandler::fields public function Implementation of MigrateDestinationHandler::fields().
MigrateStatisticsEntityHandler::__construct public function Overrides MigrateHandler::__construct