Skip to content
linkit.install 2.92 KiB
Newer Older
<?php

/**
 * @file
 * Install, update and uninstall functions for the Linkit module.
/**
 * Implements hook_schema().
 */
function linkit_schema() {
  $schema = array();

  $schema['linkit_profiles'] = array(
    'description' => 'Base table holding Linkit profiles.',
    'export' => array(
      'key' => 'name',
      'key name' => 'Name',
      'primary key' => 'pid',
      'identifier' => 'linkit_profile',
      'default hook' => 'default_linkit_profile',
Emil Stjerneman's avatar
Emil Stjerneman committed
      'status' => 'linkit_profiles_status',
      'load callback' => 'linkit_profile_load',
      'load all callback' => 'linkit_profile_load_all',
      'save callback' => 'linkit_profile_save',
Emil Stjerneman's avatar
Emil Stjerneman committed
      'bulk export' => TRUE,
      'api' => array(
        'owner' => 'linkit',
        'api' => 'linkit_profiles',
        'minimum_version' => 1,
        'current_version' => 1,
      ),
    ),
    'fields' => array(
      'pid' => array(
Emil Stjerneman's avatar
Emil Stjerneman committed
        'description' => 'Serial id for this profile.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'no export' => TRUE,
      ),
      'name' => array(
        'description' => 'Machine-readable name for this profile.',
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
      ),
Emil Stjerneman's avatar
Emil Stjerneman committed
      'admin_title' => array(
        'description' => 'Administrative title for this profile.',
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
      ),
      'data' => array(
        'type' => 'text',
        'size' => 'big',
        'description' => 'A serialized array with settings.',
Emil Stjerneman's avatar
Emil Stjerneman committed
      'role_rids' => array(
        'type' => 'text',
        'size' => 'big',
        'description' => 'A serialized array with role rids that is assign to this profile.',
      ),
      'weight' => array(
        'description' => 'Profile weight.',
Emil Stjerneman's avatar
Emil Stjerneman committed
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
    'primary key' => array('pid'),
    'unique keys' => array(
      'name' => array('name'),
    ),
  );

  return $schema;
}

 * Implements hook_uninstall().
 */
function linkit_uninstall() {
Emil Stjerneman's avatar
Emil Stjerneman committed
  variable_del('linkit_profiles_status');
}

/**
 * Create the {linkit_profiles} table if it not exists.
 */
function linkit_update_7200() {
  if (!db_table_exists('linkit_profiles')) {
    // Call the schema function to reduce the lines of code here.
    $schema = linkit_schema();
    // Create the table.
    db_create_table('linkit_profiles', $schema['linkit_profiles']);
    return t('The table {linkit_profiles} was successfully created.');
  }
}

/**
 * Delete old linkit settings.
 */
function linkit_update_7201() {
  // Delete old settings if any.
  $num_deleted = db_delete('variable')
  ->condition('name', array('linkit_node', 'linkit_term'), 'IN')
  ->execute();

  // No old settings deleted
  if(!$num_deleted) {
    return t("No old Linkit settings were deleted.");
    return t("Old Linkit settings were deleted.");