You are here

yandex_metrics.install in Yandex.Metrics 6

Install, uninstall and update the module.

File

yandex_metrics.install
View source
<?php

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

/**
 * Implementation of hook_install().
 */
function yandex_metrics_install() {
  drupal_install_schema('yandex_metrics');
}

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

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

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

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

/**
 * Implementation of hook_update_N().
 */
function yandex_metrics_update_6100() {
  $schema['yandex_metrics_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',
      ),
    ),
  );
  $ret = array();
  if (!db_table_exists('yandex_metrics_popular_content')) {
    db_create_table($ret, 'yandex_metrics_popular_content', $schema['yandex_metrics_popular_content']);
  }

  // Clear CSS and JS caches.
  drupal_clear_css_cache();
  drupal_clear_js_cache();

  // Rebuild the menu to add new item admin/yandex_metrics_ajax/%/%/%.
  menu_rebuild();

  // Flush content caches.
  cache_clear_all();
  $ret[] = array(
    'success' => TRUE,
    'query' => 'Caches have been flushed',
  );
  return $ret;
}

/**
 * Implementation of hook_schema().
 */
function yandex_metrics_schema() {
  $schema['yandex_metrics_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;
}

Functions

Namesort descending Description
yandex_metrics_install Implementation of hook_install().
yandex_metrics_schema Implementation of hook_schema().
yandex_metrics_uninstall Implementation of hook_uninstall().
yandex_metrics_update_6100 Implementation of hook_update_N().