You are here

forena.install in Forena Reports 7.2

Installation api for module

File

forena.install
View source
<?php

// $Id$

/**
 * @file
 * Installation api for module
 */

/**
 * Implementation of hook_schema
 *
 * @return unknown
 */
function forena_schema() {

  /*
   * Table to store Reports
   */
  $schema['forena_reports'] = array(
    'fields' => array(
      'report_name' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'language' => array(
        'type' => 'varchar',
        'length' => 30,
        'not null' => TRUE,
      ),
      'title' => array(
        'type' => 'varchar',
        'length' => 63,
        'not null' => TRUE,
      ),
      'descriptor' => array(
        'type' => 'text',
      ),
      'category' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
      ),
      'hidden' => array(
        'type' => 'int',
        'not null' => FALSE,
      ),
      'cache' => array(
        'type' => 'text',
      ),
      'src' => array(
        'type' => 'text',
      ),
      'modified' => array(
        'type' => 'int',
      ),
      'altered' => array(
        'type' => 'int',
      ),
    ),
    'primary key' => array(
      'report_name',
      'language',
    ),
    'indexes' => array(
      'category' => array(
        'category',
      ),
    ),
  );
  $schema['forena_repositories'] = array(
    'fields' => array(
      'repository' => array(
        'type' => 'varchar',
        'length' => '63',
        'not null' => TRUE,
      ),
      'title' => array(
        'type' => 'varchar',
        'length' => '63',
      ),
      'enabled' => array(
        'type' => 'int',
        'not null' => TRUE,
      ),
      'config' => array(
        'type' => 'text',
      ),
    ),
    'primary_key' => array(
      'repository',
    ),
  );
  $schema['forena_data_blocks'] = array(
    'fields' => array(
      'repository' => array(
        'type' => 'varchar',
        'length' => '63',
        'not null' => TRUE,
      ),
      'block_name' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'title' => array(
        'type' => 'varchar',
        'length' => 63,
        'not null' => FALSE,
      ),
      'descriptor' => array(
        'type' => 'varchar',
        'length' => '255',
      ),
      'category' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
      ),
      'modified' => array(
        'type' => 'int',
      ),
      'src' => array(
        'type' => 'text',
      ),
      'locked' => array(
        'type' => 'int',
        'not null' => TRUE,
      ),
    ),
    'primary key' => array(
      'block_name',
    ),
    'indexes' => array(
      'category' => array(
        'category',
      ),
      'repository' => array(
        'repository',
      ),
    ),
  );
  return $schema;
}

/**
 * Implements hook_requirements().
 */
function forena_requirements($phase) {
  $requirements = array();
  if ($phase == 'runtime') {
    $settings_initialized = variable_get('forena_report_repos', FALSE) !== FALSE;
    if ($settings_initialized) {
      $requirements['forena'] = array(
        'value' => t('Configured'),
        'severity' => REQUIREMENT_OK,
      );
    }
    else {
      $requirements['forena'] = array(
        'value' => t('Not configured'),
        'description' => t('Before using Forena please visit !link, verify and save the settings.', array(
          '!link' => l('configuration page', 'admin/config/content/forena'),
        )),
        'severity' => REQUIREMENT_ERROR,
      );
    }
    $requirements['forena']['title'] = t('Forena Reports module');
  }
  return $requirements;
}

/**
 * Updating database schema
 */
function forena_update_7201() {
  $schema = array();
  $schema['forena_repositories'] = array(
    'fields' => array(
      'repository' => array(
        'type' => 'varchar',
        'length' => 63,
        'not null' => TRUE,
      ),
      'title' => array(
        'type' => 'varchar',
        'length' => 63,
      ),
      'enabled' => array(
        'type' => 'int',
        'not null' => TRUE,
      ),
      'config' => array(
        'type' => 'text',
      ),
    ),
    'primary_key' => array(
      'repository',
    ),
  );
  $schema['forena_data_blocks'] = array(
    'fields' => array(
      'repository' => array(
        'type' => 'varchar',
        'length' => '63',
        'not null' => TRUE,
      ),
      'block_name' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
      ),
      'title' => array(
        'type' => 'varchar',
        'length' => 63,
        'not null' => FALSE,
      ),
      'descriptor' => array(
        'type' => 'varchar',
        'length' => '255',
      ),
      'category' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
      ),
      'modified' => array(
        'type' => 'int',
      ),
      'src' => array(
        'type' => 'text',
      ),
      'locked' => array(
        'type' => 'int',
        'not null' => TRUE,
      ),
    ),
    'primary key' => array(
      'block_name',
    ),
    'indexes' => array(
      'category' => array(
        'category',
      ),
      'repository' => array(
        'repository',
      ),
    ),
  );
  db_add_field('forena_reports', 'descriptor', array(
    'type' => 'text',
  ));
  db_add_field('forena_reports', 'src', array(
    'type' => 'text',
  ));
  db_add_field('forena_reports', 'altered', array(
    'type' => 'int',
  ));
  db_create_table('forena_repositories', $schema['forena_repositories']);
  db_create_table('forena_data_blocks', $schema['forena_data_blocks']);
}

/**
 * Add language column
 */
function forena_update_7202() {
  db_add_field('forena_reports', 'language', array(
    'type' => 'varchar',
    'length' => 30,
    'not null' => TRUE,
    'default' => 'en',
  ));
  db_query("update {forena_reports} set language='en'");
  db_drop_primary_key('forena_reports');
  db_add_primary_key('forena_reports', array(
    'report_name',
    'language',
  ));
}

Functions

Namesort descending Description
forena_requirements Implements hook_requirements().
forena_schema Implementation of hook_schema
forena_update_7201 Updating database schema
forena_update_7202 Add language column