Commit b31a4e7b authored by Stefan Korn's avatar Stefan Korn Committed by Omar Mohamad - El Hassan Lopesino
Browse files

Issue #3109239 by stefan.korn: does not work with different entities of...

Issue #3109239 by stefan.korn: does not work with different entities of different entity types that have the same entity id
parent e1bf335a
Loading
Loading
Loading
Loading
+10 −1
Original line number Diff line number Diff line
@@ -57,8 +57,17 @@ function entity_statistics_schema() {
        'default' => '',
      ),
    ),
    'primary key' => array('entity_id'),
    'primary key' => array('entity_id', 'entity_type'),
  );

  return $schema;
}


/**
 * Recreate primary key to fix problems with same entity id on different types
 */
function entity_statistics_update_7001(&$sandbox) {
  db_drop_primary_key('entity_counter');
  db_add_primary_key('entity_counter', array('entity_id', 'entity_type'));
}
+1 −2
Original line number Diff line number Diff line
@@ -35,11 +35,10 @@ function entity_statistics_exit() {
    $entity_type = arg(0);
    if (isset($entity_types[$entity_type]) && is_numeric(arg(1)) && arg(2) == NULL && entity_statistics_entity_type_enabled($entity_type)) {
      // A entity has been viewed, so update the entity's counters.
      db_merge('entity_counter')->key(array('entity_id' => arg(1)))->fields(array(
      db_merge('entity_counter')->key(array('entity_id' => arg(1), 'entity_type' => $entity_type))->fields(array(
        'daycount' => 1,
        'totalcount' => 1,
        'timestamp' => REQUEST_TIME,
        'entity_type' => $entity_type,
      ))->expression('daycount', 'daycount + 1')->expression('totalcount', 'totalcount + 1')->execute();
    }
  }
+1 −2
Original line number Diff line number Diff line
@@ -20,8 +20,7 @@ if (variable_get('entity_statistics_count_entity_views_ajax', 0)) {
    $entity_id = $_POST['entity_id'];
    $entity_type = $_POST['entity_type'];
    if (is_numeric($entity_id)) {
      db_merge('entity_counter')->key(array('entity_id' => $entity_id))->fields(array(
        'entity_type' => $entity_type,
      db_merge('entity_counter')->key(array('entity_id' => $entity_id, 'entity_type' => $entity_type))->fields(array(
        'daycount' => 1,
        'totalcount' => 1,
        'timestamp' => REQUEST_TIME,