You are here

forena.install in Forena Reports 7.3

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',
      ),
      'modified' => array(
        'type' => 'int',
      ),
      'altered' => array(
        'type' => 'int',
      ),
      'path' => array(
        'type' => 'varchar',
        'length' => 255,
      ),
    ),
    'primary key' => array(
      'report_name',
      'language',
    ),
    'indexes' => array(
      'category' => array(
        'category',
      ),
      'path' => array(
        'path',
      ),
    ),
  );
  $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,
      ),
      'block_type' => array(
        'type' => 'varchar',
        'length' => 30,
        'not null' => TRUE,
      ),
      'access' => 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',
      ),
      'builder' => 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;
}

/**
 * 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',
      ),
    ),
  );
  if (!db_field_exists('forena_reports', 'descriptor')) {
    db_add_field('forena_reports', 'descriptor', array(
      'type' => 'text',
    ));
  }
  if (!db_field_exists('forena_reports', 'altered')) {
    db_add_field('forena_reports', 'altered', array(
      'type' => 'int',
    ));
  }
  if (!db_table_exists('forena_reports')) {
    db_create_table('forena_repositories', $schema['forena_repositories']);
  }
  if (!db_table_exists('forena_data_blocks')) {
    db_create_table('forena_data_blocks', $schema['forena_data_blocks']);
  }
}

/**
 * Add language column
 */
function forena_update_7202() {
  if (!db_field_exists('forena_reports', 'language')) {
    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',
    ));
  }
}
function forena_update_7301() {
  if (!db_field_exists('forena_reports', 'path')) {
    db_add_field('forena_reports', 'path', array(
      'type' => 'varchar',
      'length' => 255,
    ));
    db_add_index('forena_reports', 'path', array(
      'path',
    ));
  }
}
function forena_update_7302() {
  if (db_field_exists('forena_reports', 'src')) {
    db_drop_field('forena_reports', 'src');
  }
}
function forena_update_7303() {

  // Clear cache to load skins
  require_once 'forena.admin.inc';
  forena_sync_reports(FALSE);

  // New block access field.
  if (!db_field_exists('forena_data_blocks', 'access')) {
    db_add_field('forena_data_blocks', 'access', array(
      'type' => 'varchar',
      'length' => 255,
      'not null' => TRUE,
    ));
  }
  if (!db_field_exists('forena_data_blocks', 'block_type')) {
    db_add_field('forena_data_blocks', 'block_type', array(
      'type' => 'varchar',
      'length' => 30,
      'not null' => TRUE,
    ));
  }
}
function forena_update_7304() {
  if (!db_field_exists('forena_data_blocks', 'builder')) {
    db_add_field('forena_data_blocks', 'builder', array(
      'type' => 'text',
    ));
  }
}
function forena_install() {
  $filters = filter_formats();

  // Set default input format.
  if (isset($filters['full_html'])) {
    variable_set('forena_input_format', 'full_html');
  }
  require_once 'forena.admin.inc';
  forena_sync_reports(TRUE);
}

/**
 * Implementation of hook uninstall
 */
function forena_uninstall() {

  // Delete all variables.
  variable_del('forena_default_form');
  variable_del('forena_doc_defaults');
  variable_del('forena_doc_formats');
  variable_del('forena_default_formats');
  variable_del('forena_email_override');
  variable_del('forena_input_format');
  variable_del('forena_last_report_path');
  variable_del('forena_report_repos');
  variable_del('forena_skins');
}

Functions

Namesort descending Description
forena_install
forena_schema Implementation of hook_schema
forena_uninstall Implementation of hook uninstall
forena_update_7201 Updating database schema
forena_update_7202 Add language column
forena_update_7301
forena_update_7302
forena_update_7303
forena_update_7304