nodeviewcount.install in Node view count 7.2
Same filename and directory in other branches
Creates table for views counting.
File
nodeviewcount.installView source
<?php
/**
* @file
* Creates table for views counting.
*/
/**
* Implements hook_schema().
*/
function nodeviewcount_schema() {
$schema = array();
$schema['nodeviewcount'] = array(
'description' => 'The count views of node for every user.',
'fields' => array(
'id' => array(
'description' => 'The unique ID.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'nid' => array(
'description' => 'The node ID.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'uid' => array(
'description' => 'The user ID who view of node.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
),
'timestamp' => array(
'description' => 'The Unix timestamp when the node was view.',
'type' => 'int',
'not null' => TRUE,
'default' => 0,
),
),
'primary key' => array(
'id',
),
'indexes' => array(
'nid_uid' => array(
'uid',
'nid',
),
'timestamp' => array(
'timestamp',
),
),
);
return $schema;
}
/**
* Implements hook_install().
*/
function nodeviewcount_install() {
variable_set('nodeviewcount_node_types', array());
variable_set('nodeviewcount_user_roles', array());
variable_set('nodeviewcount_way_counting', NODEVIEWCOUNT_PHP_WAY_COUNT_VIEWS);
variable_set('nodeviewcount_flush_log_timer', 0);
}
/**
* Implements hook_uninstall().
*/
function nodeviewcount_uninstall() {
variable_del('nodeviewcount_node_types');
variable_del('nodeviewcount_user_roles');
variable_del('nodeviewcount_way_counting');
variable_del('nodeviewcount_flush_log_timer');
}
/**
* Add a new nid index in DB to the table nodeviewcount.
*/
function nodeviewcount_update_7211() {
$table = 'nodeviewcount';
$index_name = 'nid';
if (db_table_exists($table)) {
if (!db_index_exists($table, $index_name)) {
db_add_index($table, $index_name, array(
'nid',
));
return t('New index added');
}
else {
return t('Index already exist');
}
}
}
Functions
Name![]() |
Description |
---|---|
nodeviewcount_install | Implements hook_install(). |
nodeviewcount_schema | Implements hook_schema(). |
nodeviewcount_uninstall | Implements hook_uninstall(). |
nodeviewcount_update_7211 | Add a new nid index in DB to the table nodeviewcount. |