You are here

yandex_metrics_reports.install in Yandex.Metrics 8.3

Install, uninstall and update the module.

File

yandex_metrics_reports/yandex_metrics_reports.install
View source
<?php

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

/**
 * Implements hook_uninstall().
 */
function yandex_metrics_reports_uninstall() {

  // Delete module variables and clear variables cache.
  db_delete('variable')
    ->condition('name', 'yandex_metrics_reports_%', 'LIKE')
    ->execute();
  cache_clear_all('variables', 'cache_bootstrap');
}

/**
 * Implements hook_schema().
 */
function yandex_metrics_reports_schema() {
  $schema['yandex_metrics_reports_popular_content'] = array(
    'description' => 'Stores the popular content.',
    'fields' => array(
      'yid' => array(
        'description' => 'The id for url.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'url' => array(
        'description' => 'The url obtained from Yandex.metrika.',
        'type' => 'varchar',
        'length' => 2048,
        'not null' => TRUE,
        'default' => '',
      ),
      'language' => array(
        'description' => 'Language of the page.',
        'type' => 'varchar',
        'length' => 12,
        '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.',
      ),
    ),
    'primary key' => array(
      'yid',
    ),
    'indexes' => array(
      'language' => array(
        'language',
      ),
      'url' => array(
        array(
          'url',
          255,
        ),
      ),
    ),
  );
  return $schema;
}

/**
 * Implements hook_requirements().
 */
function yandex_metrics_reports_requirements($phase) {
  $t = get_t();
  $requirements = array();
  if ($phase == 'runtime') {
    if (function_exists('yandex_services_auth_info') && !yandex_services_auth_info('token')) {
      $message = $t('Please, <a href="!module_config_url">configure @module</a> module.', array(
        '!module_config_url' => url('admin/config/system/yandex_services_auth'),
        '@module' => 'Yandex Services Authorization API',
      ));
      $requirements['yandex_metrics_reports'] = array(
        'title' => t('Yandex.Metrics Reports'),
        'value' => $message,
        'severity' => REQUIREMENT_WARNING,
      );
    }
  }
  return $requirements;
}

/**
 * Use Yandex Services Authorization API (yandex_services_auth).
 */
function yandex_metrics_reports_update_7201() {

  // Enable yandex_services_auth module.
  if (!module_enable(array(
    'yandex_services_auth',
  ))) {
    throw new Exception('The Yandex.Metrics Reports requires Yandex Services Authorization API (https://drupal.org/project/yandex_services_auth) module.');
  }
  if (!yandex_services_auth_info('token')) {
    variable_set('yandex_services_auth_token', variable_get('yandex_metrics_reports_auth_token', ''));
    variable_set('yandex_services_auth_client_id', variable_get('yandex_metrics_reports_client_id', ''));
    variable_set('yandex_services_auth_client_secret', variable_get('yandex_metrics_reports_client_secret', ''));
  }
  variable_del('yandex_metrics_reports_client_id');
  variable_del('yandex_metrics_reports_client_secret');
  variable_del('yandex_metrics_reports_auth_token');
}

/**
 * Enlarge URL field size for popular content database table.
 */
function yandex_metrics_reports_update_7202() {
  db_drop_unique_key('yandex_metrics_reports_popular_content', 'url');
  db_change_field('yandex_metrics_reports_popular_content', 'url', 'url', array(
    'description' => 'The url obtained from Yandex.Metrika.',
    'type' => 'varchar',
    'length' => 2048,
    'not null' => TRUE,
    'default' => '',
  ), array(
    'indexes' => array(
      'url' => array(
        array(
          'url',
          255,
        ),
      ),
    ),
  ));
}

/**
 * Upgrade from 7.x-2.x to 7.x-3.x.
 *
 * Migration to Yandex.Metrics Popular Content (yandex_metrics_popular_content).
 */
function yandex_metrics_reports_update_7300() {

  // If old table exists.
  if (db_table_exists('yandex_metrics_reports_popular_content')) {

    // Drop redundant table yandex_metrics_reports module.
    db_drop_table('yandex_metrics_reports_popular_content');
  }
  variable_set('yandex_metrics_popular_content_date_period', variable_get('yandex_metrics_reports_date_period', 'week'));
  variable_del('yandex_metrics_reports_date_period');

  // Remove redundant variables. Now we have only one variable for all report metadata.
  db_delete('variable')
    ->condition('name', 'yandex_metrics_reports_%_visible', 'LIKE')
    ->execute();
  cache_clear_all('variables', 'cache_bootstrap');
}

/**
 * Enable Visualization module.
 */
function yandex_metrics_reports_update_7301() {
  module_enable(array(
    'visualization',
  ));
}

Functions

Namesort descending Description
yandex_metrics_reports_requirements Implements hook_requirements().
yandex_metrics_reports_schema Implements hook_schema().
yandex_metrics_reports_uninstall Implements hook_uninstall().
yandex_metrics_reports_update_7201 Use Yandex Services Authorization API (yandex_services_auth).
yandex_metrics_reports_update_7202 Enlarge URL field size for popular content database table.
yandex_metrics_reports_update_7300 Upgrade from 7.x-2.x to 7.x-3.x.
yandex_metrics_reports_update_7301 Enable Visualization module.