You are here

subuser.install in Subuser 6

Same filename and directory in other branches
  1. 8 subuser.install
  2. 5 subuser.install
  3. 7.2 subuser.install

Provides database schema and uninstall cleanup.

Copyright 2008-2009 by Jimmy Berry ("boombatower", http://drupal.org/user/214218)

File

subuser.install
View source
<?php

/**
 * @file
 * Provides database schema and uninstall cleanup.
 *
 * Copyright 2008-2009 by Jimmy Berry ("boombatower", http://drupal.org/user/214218)
 */

/**
 * Implementation of hook_schema().
 */
function subuser_schema() {
  $schema['subuser_relationship'] = array(
    'description' => t('Holds user relationship associations.'),
    'fields' => array(
      'rid' => array(
        'type' => 'serial',
        'description' => t('The unique relationship identifier.'),
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'parent_id' => array(
        'description' => t('The parent user identifier.'),
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'uid' => array(
        'description' => t('The primary user identifier.'),
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
    ),
    'indexes' => array(
      'uid' => array(
        'uid',
      ),
      'parent_id' => array(
        'parent_id',
      ),
    ),
    'primary key' => array(
      'rid',
    ),
  );
  $schema['subuser_limit'] = array(
    'description' => t('Holds per parent user limits on the number of subusers they can create.'),
    'fields' => array(
      'uid' => array(
        'type' => 'int',
        'description' => t('The uid of the parent.'),
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'subuser_limit' => array(
        'type' => 'int',
        'description' => t('The limit on the number of subusers this parent is allowed to create.'),
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
    ),
    'indexes' => array(
      'uid' => array(
        'uid',
      ),
    ),
    'primary key' => array(
      'uid',
    ),
  );
  return $schema;
}

/**
 * Implementation of hook_install().
 */
function subuser_install() {
  drupal_install_schema('subuser');
}

/**
 * Implementation of hook_uninstall().
 */
function subuser_uninstall() {
  drupal_uninstall_schema('subuser');
  variable_del('subuser_roles');
}

/**
 * Implementation of hook_update_n()
 * Adjusts the table name for the proper namespace.
 */
function subuser_update_6001() {
  $return = array();
  $return[] = update_sql("ALTER TABLE {user_relationship} RENAME TO {subuser_relationship}");
  return $return;
}

/**
 * Adds the subuser_limit table to allow us to enforce limits on the number of subusers
 * on a per parent basis, rather than just site wide.
 */
function subuser_update_6002() {

  // If subuser_limit table exists, update is not necessary
  if (db_table_exists('subuser_limit')) {
    return;
  }
  $schema['subuser_limit'] = array(
    'description' => t('Holds per parent user limits on the number of subusers they can create.'),
    'fields' => array(
      'uid' => array(
        'type' => 'int',
        'description' => t('The uid of the parent.'),
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'subuser_limit' => array(
        'type' => 'int',
        'description' => t('The limit on the number of subusers this parent is allowed to create.'),
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
    ),
    'indexes' => array(
      'uid' => array(
        'uid',
      ),
    ),
    'primary key' => array(
      'uid',
    ),
  );
  $ret = array();
  db_create_table($ret, 'subuser_limit', $schema['subuser_limit']);
  return $ret;
}

Functions

Namesort descending Description
subuser_install Implementation of hook_install().
subuser_schema Implementation of hook_schema().
subuser_uninstall Implementation of hook_uninstall().
subuser_update_6001 Implementation of hook_update_n() Adjusts the table name for the proper namespace.
subuser_update_6002 Adds the subuser_limit table to allow us to enforce limits on the number of subusers on a per parent basis, rather than just site wide.