You are here

function userprotect_install in User protect 6

Same name and namespace in other branches
  1. 8 userprotect.install \userprotect_install()
  2. 5 userprotect.install \userprotect_install()
  3. 7 userprotect.install \userprotect_install()

Implementation of hook_install().

File

./userprotect.install, line 7

Code

function userprotect_install() {
  $ret = drupal_install_schema('userprotect');
  $failed = array();
  foreach ($ret as $query) {
    if (!$query['success']) {
      $failed[] = $query['query'];
    }
  }
  if (empty($failed)) {

    // Default settings
    $q1 = db_query("INSERT INTO {userprotect} (uid, up_name, up_mail, up_pass, up_status, up_roles, up_delete, up_edit, up_type, up_openid) VALUES (0, 0, 0, 0, 0, 0, 1, 1, 'user', 1)");
    $q2 = db_query("INSERT INTO {userprotect} (uid, up_name, up_mail, up_pass, up_status, up_roles, up_delete, up_edit, up_type, up_openid) VALUES (1, 0, 0, 0, 0, 0, 1, 1, 'user', 1)");
    $q3 = db_query("INSERT INTO {userprotect} (uid, up_name, up_mail, up_pass, up_status, up_roles, up_delete, up_edit, up_type, up_openid) VALUES (1, 1, 1, 1, 1, 1, 1, 1, 'admin', 1)");
    $q4 = db_result(db_query('SELECT perm FROM {permission} WHERE rid = %d', DRUPAL_AUTHENTICATED_RID));
    $q5 = db_query("UPDATE {permission} SET perm = '%s' WHERE rid = %d", $q4 . ', change own e-mail, change own password, change own openid', DRUPAL_AUTHENTICATED_RID);
    if ($q1 && $q2 && $q3 && $q4 && $q5) {
      drupal_set_message(t('User Protect module installed successfully.'));
    }
    else {
      drupal_set_message(t('Errors occurred while inserting the default data for the User Protect module.'), 'error');
    }
  }
  else {
    drupal_set_message(t('Table installation for the User Protect module was unsuccessful. The following queries failed: !queries', array(
      '!queries' => theme('item_list', $failed),
    )), 'error');
  }
}