You are here

homebox.install in Homebox 6

The install file for Home box allows the module to install (and uninstall) itself. This is required as this module uses its own table.

File

homebox.install
View source
<?php

/**
 * @file
 * The install file for Home box allows the module to install (and uninstall) itself. This is required as this module uses its own table.
 */

/**
 * Implementation of hook_install().
 */
function homebox_install() {
  drupal_install_schema('homebox');
}
function homebox_schema() {

  // Schema for home box pages
  $schema['homebox_pages'] = array(
    'fields' => array(
      'pid' => array(
        'type' => 'serial',
        'not null' => TRUE,
      ),
      'name' => array(
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
        'default' => '',
      ),
    ),
    'primary key' => array(
      'pid',
    ),
  );

  // Schema for default layout settings
  $schema['homebox_default'] = array(
    'fields' => array(
      'pid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'bid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'region' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'movable' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 1,
      ),
      'status' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 1,
      ),
      'open' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 1,
      ),
      'weight' => array(
        'type' => 'int',
        'unsigned' => FALSE,
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'bid',
      'pid',
    ),
  );

  // Schema for user custom settings
  $schema['homebox_users'] = array(
    'fields' => array(
      'uid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'pid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'bid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'region' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'weight' => array(
        'type' => 'int',
        'unsigned' => FALSE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'status' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 1,
      ),
      'color' => array(
        'type' => 'varchar',
        'length' => 7,
        'not null' => TRUE,
        'default' => '',
      ),
      'open' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 1,
      ),
    ),
    'primary key' => array(
      'uid',
      'bid',
      'pid',
    ),
  );
  return $schema;
}

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

  // Remove variables
  foreach (homebox_pages() as $page) {

    // Remove url_alias records for homebox
    db_query("DELETE FROM {url_alias} WHERE src = 'homebox/%d'", $page->pid);

    // Settings
    variable_del('homebox_column_count_' . $page->pid);
    variable_del('homebox_users_use_colors_' . $page->pid);
    variable_del('homebox_cache_enabled_' . $page->pid);

    // Colors
    for ($i = 0; $i < HOMEBOX_NUMBER_OF_COLOURS; $i++) {
      variable_del('homebox_color_' . $page->pid . '_' . $i);
    }
  }

  // Remove schema
  drupal_uninstall_schema('homebox');
}
function homebox_update_6001() {
  $ret[] = update_sql("DELETE FROM {homebox_users} WHERE uid = 0");
  return $ret;
}
function homebox_update_6002() {
  $ret = array();
  $field_definition = array(
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 1,
  );
  db_add_field($ret, 'homebox_default', 'status', $field_definition);
  db_add_field($ret, 'homebox_default', 'open', $field_definition);
  $ret[] = update_sql("DELETE FROM {homebox_users} WHERE uid = 0");
  return $ret;
}
function homebox_update_6003() {
  $ret = array();
  $field_definition = array(
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 1,
  );
  if (!db_column_exists('homebox_default', 'status')) {
    db_add_field($ret, 'homebox_default', 'status', $field_definition);
  }
  if (!db_column_exists('homebox_default', 'open')) {
    db_add_field($ret, 'homebox_default', 'open', $field_definition);
  }
  return $ret;
}

/**
 * Update the permissions table, to fix invalid permission names having non-English characters.
 */
function homebox_update_6005() {
  $ret = array();
  $res = db_query('SELECT rid, perm FROM {permission}');
  $perms = array();
  drupal_load('module', 'homebox');
  while ($p = db_fetch_object($res)) {
    $perm = $p->perm;
    foreach (homebox_pages() as $page) {
      $perm = preg_replace('/access homebox ' . $page->name . '/', 'access homebox ' . $page->safe_name, $perm);
    }
    $perms[$p->rid] = $perm;
  }
  foreach ($perms as $rid => $permission) {

    // Use db_query as update_sql() could fail if single quotes are in a permission string.
    db_query("UPDATE {permission} SET perm = '%s' WHERE rid = %d", $permission, $rid);
    $ret[] = array(
      'success' => TRUE,
      'query' => 'UPDATE {permission} SET perm = ' . check_plain($permission) . ' WHERE rid = ' . $rid,
    );
  }
  return $ret;
}

Functions

Namesort descending Description
homebox_install Implementation of hook_install().
homebox_schema
homebox_uninstall Implementation of hook_uninstall().
homebox_update_6001
homebox_update_6002
homebox_update_6003
homebox_update_6005 Update the permissions table, to fix invalid permission names having non-English characters.