<?php

/**
 * @file
 * Uninstall function to clean up variables data.
 */

/**
 * Implements hook_install().
 */
function user_registrationpassword_install() {
  $t = get_t();
  // Set the correct default configuration settings
  // so the module needs no more configuration.
  // Enable account registration without e-mail confirmation.
  variable_set('user_register', 1);
  // Disable e-mail verification.
  variable_set('user_email_verification', 0);
  // Prevent standard notification email to administrators and to user.
  variable_set('user_mail_register_pending_approval_notify', 0);
  // Save the original activation email template to a temporally
  // variable, so we can revive them when we uninstall the module.
  variable_set('user_registrationpassword_user_mail_status_activated_subject_original', variable_get('user_mail_status_activated_subject', ''));
  variable_set('user_registrationpassword_user_mail_status_activated_body_original', variable_get('user_mail_status_activated_body', ''));
  // Set basic e-mail template variable for the
  // account activation e-mail so it makes sense.
  variable_set('user_mail_status_activated_subject', $t('Account details for [user:name] at [site:name]'));
  variable_set('user_mail_status_activated_body', $t('[user:name],

Your account at [site:name] has been activated.

You will be able to log in to [site:login-url] in the future using:

username: [user:name]
password: your password.

-- [site:name] team'));
}

/**
 * Implements hook_uninstall().
 */
function user_registrationpassword_uninstall() {
  // Reset system variables back to defauls.
  variable_del('user_mail_register_pending_approval_notify');
  // Reset the original (or previous adapted) ativation email template.
  variable_set('user_mail_status_activated_subject', variable_get('user_registrationpassword_user_mail_status_activated_subject_original', ''));
  variable_set('user_mail_status_activated_body', variable_get('user_registrationpassword_user_mail_status_activated_body_original', ''));
  // Delete all variables related to user_registrationpassword.
  db_delete('variable')
    ->condition('name', db_like('user_registrationpassword_') . '%', 'LIKE')
    ->execute();
}

/**
 * Update 7000 updates the name of the variable.
 */
function user_registrationpassword_update_7000() {
  // Copy the value of the user_registrationpassword variable
  // to the user_registrationpassword_registration variable.
  variable_set('user_registrationpassword_registration', variable_get('user_registrationpassword', 2));
  // Delete the user_registrationpassword variable.
  variable_del('user_registrationpassword');
}
