function statistics_counter_install in Statistics Counter 8
Same name and namespace in other branches
- 7 statistics_counter.install \statistics_counter_install()
Implements hook_install().
File
- ./
statistics_counter.install, line 13 - Statistics Counter
Code
function statistics_counter_install() {
$db = Database::getConnection();
$transaction = $db
->startTransaction();
$weekcount = [
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'size' => 'medium',
'description' => 'The total number of times the {node} has been viewed this week.',
];
$monthcount = [
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'size' => 'medium',
'description' => 'The total number of times the {node} has been viewed this month.',
];
$yearcount = [
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'size' => 'medium',
'description' => 'The total number of times the {node} has been viewed this year.',
];
try {
$schema = $db
->schema();
$schema
->addField('node_counter', 'weekcount', $weekcount);
$schema
->addField('node_counter', 'monthcount', $monthcount);
$schema
->addField('node_counter', 'yearcount', $yearcount);
// Ignore slave server temporarily to give time for the
// saved block to be propagated to the slave.
// db_ignore_slave();
} catch (\Exception $e) {
$transaction
->rollback();
watchdog_exception('php', $e);
drupal_set_message(t('Cannot create new fields'), 'error');
}
}