You are here

front_page.install in Front Page 6.2

Same filename and directory in other branches
  1. 7.2 front_page.install
  2. 7 front_page.install

Install, update and uninstall functions for the front page module.

File

front_page.install
View source
<?php

/**
 * @file
 * Install, update and uninstall functions for the front page module.
 */

/**
 * Implements hook_install().
 */
function front_page_install() {
  drupal_install_schema('front_page');
}

/**
 * Implements hook_uninstall().
 */
function front_page_uninstall() {
  drupal_uninstall_schema('front_page');
  variable_del('front_page_enable');
  variable_del('front_page_breadcrumb');
  variable_del('front_page_breadcrumb_redirect');
  variable_del('special_notice_time');
  variable_del('special_notice_text');
}

/**
 * Implements hook_schema().
 */
function front_page_schema() {
  $schema['front_page'] = array(
    'description' => 'Stores Front Page settings.',
    'fields' => array(
      'rid' => array(
        'type' => 'int',
        'not null' => TRUE,
        'unsigned' => TRUE,
        'description' => 'Primary Key: Role ID.',
      ),
      'mode' => array(
        'type' => 'varchar',
        'length' => 10,
        'not null' => TRUE,
        'default' => '',
        'description' => 'The mode the front page will operate in for the selected role.',
      ),
      'data' => array(
        'type' => 'text',
        'not null' => TRUE,
        'size' => 'big',
        'description' => 'Contains the data for the selected mode. This could be a path or html to display.',
      ),
      'filter_format' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
        'description' => 'The filter format to apply to the data.',
      ),
      'weight' => array(
        'type' => 'int',
        'default' => 0,
        'description' => 'The weight of the front page setting.',
      ),
    ),
    'primary key' => array(
      'rid',
    ),
    'indexes' => array(
      'weight' => array(
        'weight',
      ),
    ),
  );
  return $schema;
}

/**
 * Update 6200 - Add table if not already added, transfer data into the table and correct special notice times.
 */
function front_page_update_6200() {
  $ret = array();
  if (!db_table_exists('front_page')) {
    $schema = drupal_get_schema_unprocessed('front_page');
    _drupal_initialize_schema('front_page', $schema);
    if (isset($schema['front_page'])) {
      db_create_table($ret, 'front_page', $schema['front_page']);
    }

    // need to add front page data from variables table to new table.
    $formats = filter_formats();
    $formats = drupal_map_assoc(array_keys($formats));
    $default_format = array_shift($formats);
    $php_format = db_result(db_query("SELECT format FROM {filter_formats} WHERE name='PHP code'"));
    if (empty($php_format)) {
      $php_format = $default_format;
    }
    $roles = user_roles();
    foreach ($roles as $rid => $role_name) {
      $mode = variable_get('front_' . $rid . '_type', '');
      if (!empty($mode)) {
        switch ($mode) {
          case 'themed':
          case 'full':
            $data = variable_get('front_' . $rid . '_text', '');
            $format = $default_format;
            if (variable_get('front_' . $rid . '_php', 0)) {
              $format = $php_format;
            }
            break;
          case 'redirect':
          case 'alias':
            $data = variable_get('front_' . $rid . '_redirect', '');
            $format = '';
            break;
          default:
            $mode = '';
            $format = '';
            $data = '';
            break;
        }
        $weight = $rid * -1;
        $ret[] = update_sql("INSERT INTO {front_page} (rid, mode, data, filter_format, weight) VALUES ({$rid}, '{$mode}', '{$data}', '{$format}', {$weight})");
        variable_del('front_' . $rid . '_type');
        variable_del('front_' . $rid . '_text');
        variable_del('front_' . $rid . '_php');
        variable_del('front_' . $rid . '_redirect');
      }
    }
  }
  if (variable_get('site_frontpage', 'node') == 'front_page') {
    variable_set('site_frontpage', 'node');
  }
  return $ret;
}
function front_page_update_6201() {
  $ret = array();
  variable_del('special_notice_time');
  variable_del('special_notice_text');
  variable_del('front_page_breadcrumb');
  $path = variable_get('front_page_breadcrumb_redirect', '');
  variable_set('front_page_home_link_path', $path);
  variable_del('front_page_breadcrumb_redirect');
  return $ret;
}
function front_page_update_6202() {

  //need to set the weight of the module to be greater than the global redirect module
  $weight = db_result(db_query("SELECT weight FROM {system} WHERE name = 'globalredirect'"));
  if (!is_numeric($weight)) {
    $weight = 0;
  }
  $weight++;
  $ret = array();
  $ret[] = update_sql("UPDATE {system} SET weight = {$weight} WHERE name = 'front_page'");
  return $ret;
}

Functions

Namesort descending Description
front_page_install Implements hook_install().
front_page_schema Implements hook_schema().
front_page_uninstall Implements hook_uninstall().
front_page_update_6200 Update 6200 - Add table if not already added, transfer data into the table and correct special notice times.
front_page_update_6201
front_page_update_6202