You are here

yandex_metrics_reports.install in Yandex.Metrics 6.2

Install, uninstall and update the module.

File

yandex_metrics_reports/yandex_metrics_reports.install
View source
<?php

/**
 * @file
 *   Install, uninstall and update the module.
 */

/**
 * Implementation of hook_install().
 */
function yandex_metrics_reports_install() {
  if (!db_table_exists('yandex_metrics_reports_popular_content')) {
    drupal_install_schema('yandex_metrics_reports');
  }
}

/**
 * Implementation of hook_uninstall().
 */
function yandex_metrics_reports_uninstall() {

  // Delete module variables and clear variables cache.
  db_query("DELETE FROM {variable} WHERE name LIKE 'yandex_metrics_reports_%'");
  cache_clear_all('variables', 'cache');

  // Remove block.
  db_query("DELETE FROM {blocks} WHERE module = 'yandex_metrics_reports'");

  // Uninstall schema.
  drupal_uninstall_schema('yandex_metrics_reports');
}

/**
 * Implementation of hook_schema().
 */
function yandex_metrics_reports_schema() {
  $schema['yandex_metrics_reports_popular_content'] = array(
    'description' => 'Stores the popular content.',
    'fields' => array(
      'url' => array(
        'description' => 'The url obtained from Yandex.metrika.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'page_title' => array(
        'description' => 'The page title of the url.',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ),
      'page_views' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Page views of this url.',
      ),
    ),
    'unique keys' => array(
      'url' => array(
        'url',
      ),
    ),
  );
  return $schema;
}

/**
 * Added primary key field.
 */
function yandex_metrics_reports_update_6200() {
  $spec = array(
    'description' => 'The id for url.',
    'type' => 'serial',
    'unsigned' => TRUE,
    'not null' => TRUE,
  );
  $ret = array();
  db_add_field($ret, 'yandex_metrics_reports_popular_content', 'yid', $spec, array(
    'primary key' => array(
      'yid',
    ),
  ));
  return $ret;
}

/**
 * Delete yandex_metrics_reports_use_ajax variable.
 */
function yandex_metrics_reports_update_6201() {
  variable_del('yandex_metrics_reports_use_ajax');
}

Functions

Namesort descending Description
yandex_metrics_reports_install Implementation of hook_install().
yandex_metrics_reports_schema Implementation of hook_schema().
yandex_metrics_reports_uninstall Implementation of hook_uninstall().
yandex_metrics_reports_update_6200 Added primary key field.
yandex_metrics_reports_update_6201 Delete yandex_metrics_reports_use_ajax variable.