You are here

profile2_regpath.install in Profile2 Registration Path 7

Same filename and directory in other branches
  1. 7.2 profile2_regpath.install

Install file for the profile2_regpath module.

File

profile2_regpath.install
View source
<?php

/**
 * @file
 * Install file for the profile2_regpath module.
 */

/**
 * Implements hook_schema().
 */
function profile2_regpath_schema() {
  $schema['profile2_regpath'] = array(
    'description' => 'Stores registration path information for profile2 profiles',
    'export' => array(
      'key' => 'profile_type',
      'key name' => 'Profile Type',
      'primary key' => 'profile_type',
      'identifier' => 'regpath',
      'api' => array(
        'owner' => 'profile2_regpath',
        'api' => 'profile2_regpath',
        'minimum_version' => '1',
        'current_version' => '1',
      ),
    ),
    'fields' => array(
      'profile_type' => array(
        'description' => 'The {profile_type}.type of this profile.',
        'type' => 'varchar',
        'length' => '255',
        'not null' => TRUE,
        'default' => '',
      ),
      'profile_id' => array(
        'description' => 'Profile2 profile ID',
        'type' => 'int',
        'not null' => TRUE,
        'no export' => TRUE,
      ),
      'path' => array(
        'description' => 'Profile-specific registration form path',
        'type' => 'varchar',
        'length' => '2048',
        'not null' => FALSE,
      ),
      'roles' => array(
        'description' => 'Array of role ids',
        'type' => 'text',
        'size' => 'big',
        'not null' => FALSE,
      ),
      'status' => array(
        'description' => 'Enabled or disabled',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'weight' => array(
        'description' => 'Weight of profile type',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'misc' => array(
        'description' => 'Miscellaneous display settings',
        'type' => 'text',
        'size' => 'big',
        'not null' => FALSE,
      ),
    ),
    'primary key' => array(
      'profile_type',
    ),
    'indexes' => array(
      'type' => array(
        array(
          'path',
          255,
        ),
      ),
    ),
  );
  return $schema;
}

/**
 * Implements hook_enable().
 */
function profile2_regpath_enable() {
  drupal_set_message(st('Profile2 Registration Path has been enabled. To configure profile registration paths, edit a profile type on the ' . l(t('Profile Types administration page'), 'admin/structure/profiles')), 'status');
}

/**
 * Implements hook_update_n().
 */
function profile2_regpath_update_7100() {

  // Add roles column.
  $roles_spec = array(
    'description' => 'Array of role ids',
    'type' => 'text',
    'size' => 'big',
    'not null' => FALSE,
  );
  db_add_field('profile2_regpath', 'roles', $roles_spec);

  // Change length of path column.
  $path_spec = array(
    'description' => 'Profile-specific registration form path',
    'type' => 'varchar',
    'length' => '2048',
    'not null' => FALSE,
  );
  db_change_field('profile2_regpath', 'path', 'path', $path_spec);
}

/**
 * Implements hook_update_n().
 */
function profile2_regpath_update_7110() {

  // Add weight column.
  $weight_specs = array(
    'description' => 'Weight of profile type',
    'type' => 'int',
    'not null' => TRUE,
    'default' => 0,
  );
  db_add_field('profile2_regpath', 'weight', $weight_specs);
}

/**
 * Implements hook_update_n().
 */
function profile2_regpath_update_7120() {
  drupal_set_message(t('The Profile2 Registration Path URL pattern has changed. Please check your site to be sure that this has not broken any links.'));
}

/**
 * Implements hook_update_n().
 */
function profile2_regpath_update_7130() {

  // Add weight column.
  $misc_specs = array(
    'description' => 'Miscellaneous display settings',
    'type' => 'text',
    'size' => 'big',
    'not null' => FALSE,
  );
  db_add_field('profile2_regpath', 'misc', $misc_specs);
  $profile_types = profile2_regpath_get_profiles();
  foreach ($profile_types as $key => $value) {

    // Check for name space collisions after changing URL pattern.
    // We must make exceptions for '/user' and other p2rp registered paths.
    if ($value->path != 'user' && ($existing_item = menu_get_item($value->path))) {
      if ($existing_item['page_callback'] != '_profile2_regpath_user_login') {
        drupal_set_message(t("Error, there is a name space collision between and existing URL alias and the Profile2 Registration path '@path'", array(
          '@path' => $value->path,
        )));
        module_disable(array(
          'profile2_regpath',
        ));
      }
    }

    // Check to see if selected path is being used by an alias.
    if ($existing_alias = drupal_lookup_path('source', $value->path)) {
      drupal_set_message(t("Error, there is a name space collision between and existing URL alias and the Profile2 Registration path '@path'", array(
        '@path' => $value->path,
      )));
      module_disable(array(
        'profile2_regpath',
      ));
    }
  }
}

/**
 * Add fields.
 */
function profile2_regpath_update_7131() {
  $spec = array(
    'description' => 'The {profile_type}.type of this profile.',
    'type' => 'varchar',
    'length' => '255',
    'not null' => TRUE,
    'default' => '',
  );
  db_add_field('profile2_regpath', 'profile_type', $spec);
  db_add_index('profile2_regpath', 'profile_type', array(
    'profile_type',
  ));
  db_drop_index('profile2_regpath', 'profile_id');
}

/**
 * Update roles.
 */
function profile2_regpath_update_7132() {
  $query = db_select('profile2_regpath', 'pr');
  $query
    ->fields('pr', array(
    'roles',
    'profile_id',
  ));
  $result = $query
    ->execute();
  $regpaths = $result
    ->fetchAll();

  // Only store role that is enabled.
  foreach ($regpaths as $regpath) {
    $roles = unserialize($regpath->roles);
    $updated_roles = array();
    foreach ($roles as $role_id => $enable) {
      if ($enable) {
        $updated_roles[$role_id] = db_query("SELECT r.name FROM {role} AS r WHERE r.rid = :rid", array(
          ':rid' => $role_id,
        ))
          ->fetchField();
      }
    }

    // Update roles.
    db_update('profile2_regpath')
      ->fields(array(
      'roles' => serialize($updated_roles),
    ))
      ->condition('profile_id', $regpath->profile_id)
      ->execute();
  }
}

/**
 * Update profile name.
 */
function profile2_regpath_update_7133() {
  db_query('UPDATE {profile2_regpath} AS pr ' . 'JOIN {profile_type} AS pt ' . 'ON pr.profile_id = pt.id ' . 'SET pr.profile_type = pt.type ');
}

/**
 * Enable dependencies
 */
function profile2_regpath_update_7134() {
  if (!module_exists('ctools')) {
    module_enable(array(
      'ctools',
    ));
  }
}

Functions

Namesort descending Description
profile2_regpath_enable Implements hook_enable().
profile2_regpath_schema Implements hook_schema().
profile2_regpath_update_7100 Implements hook_update_n().
profile2_regpath_update_7110 Implements hook_update_n().
profile2_regpath_update_7120 Implements hook_update_n().
profile2_regpath_update_7130 Implements hook_update_n().
profile2_regpath_update_7131 Add fields.
profile2_regpath_update_7132 Update roles.
profile2_regpath_update_7133 Update profile name.
profile2_regpath_update_7134 Enable dependencies