You are here

birthdays.install in Birthdays 5

Same filename and directory in other branches
  1. 6 birthdays.install
  2. 7 birthdays.install

File

birthdays.install
View source
<?php

/**
 * Implementation of hook_install().
 */
function birthdays_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("CREATE TABLE IF NOT EXISTS {dob} (\n        uid int(10) unsigned NOT NULL default 0,\n        birthday date NOT NULL default '0000-00-00',\n        PRIMARY KEY (uid)\n        );");

      // fetch current weight of the profile module, decrease with 1;
      break;
    case 'pgsql':
      db_query("CREATE TABLE  {dob} (\n        uid int NOT NULL default 0 check(uid >= 0),\n        birthday date NOT NULL default '0000-01-01',\n        PRIMARY KEY (uid)\n        );");
      break;
  }
  $weight = db_result(db_query("SELECT weight FROM {system} WHERE name = 'profile'")) - 1;
  db_query("UPDATE {system} SET weight = %d WHERE name = 'birthdays'", $weight);
}

/**
 * Implementation of hook_update_N().
 */
function birthdays_update_1() {

  // 2007-08-12 for birthdays.install 1.2.2.2: Ensuring weight is lower than the weight of profile.module.
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':

      // fetch current weight of the profile module, decrease with 1;
      $weight = db_result(db_query("SELECT weight FROM {system} WHERE name = 'profile'")) - 1;
      $ret[] = update_sql("UPDATE {system} SET weight = %d WHERE name = 'birthdays'", $weight);
      break;
    case 'pgsql':

      // TODO
      break;
  }
  return $ret;
}

/**
 * Implementation of hook_update_N().
 */
function birthdays_update_2() {

  // 2008-04-09: Postgresql added
  $ret = array();
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      break;
    case 'pgsql':
      db_query("CREATE TABLE  {dob} (\n        uid int NOT NULL default 0 check(uid >= 0),\n        birthday date NOT NULL default '0000-01-01',\n        PRIMARY KEY (uid)\n        );");

      // fetch current weight of the profile module, decrease with 1;
      $weight = db_result(db_query("SELECT weight FROM {system} WHERE name = 'profile'")) - 1;
      $ret[] = update_sql("UPDATE {system} SET weight = %d WHERE name = 'birthdays'", $weight);
      break;
  }
  return $ret;
}

/**
 * Remove the variable 'birthdays_field_name'.
 */
function birthdays_update_5003() {
  $ret[] = array(
    'success' => TRUE,
    'query' => 'Variable "birthdays_field_name" has been deleted successfully',
  );
  variable_del('birthdays_field_name');
  return $ret;
}

/**
 * Implementation of hook_requirements().
 */
function birthdays_requirements($phase) {
  global $_birthdays_field;
  $t = get_t();
  $requirements = array();
  if ($phase == 'runtime') {
    $value = $t('All requirements are met');
    $severity = REQUIREMENT_OK;
    $date_fields = _birthdays_get_date_fields();
    if (empty($date_fields)) {
      $value = $t('Missing profile field');
      $severity = REQUIREMENT_ERROR;
      $description = $t('No profile fields of type \'date\' were found, please <a href="@profile-settings-page">create one here</a>. Then visit the <a href="@birthdays-settings">birthdays settings page</a> to set up the module.', array(
        '@profile-settings-page' => url('admin/user/profile/add/date'),
        '@birthdays-settings' => url('admin/settings/birthdays'),
      ));
    }
    elseif (!isset($_birthdays_field)) {

      // Set warning/error message when the birthdays profile field hasn't been set yet.
      $value = $t('No date field selected');
      $severity = REQUIREMENT_ERROR;
      $description = $t('The date field has not yet been selected as birthdays field. Please visit the <a href="@birthdays-settings">birthdays settings page</a> to do so.', array(
        '@birthdays-settings' => url('admin/settings/birthdays'),
      ));
    }
    $requirements['birthdays'] = array(
      'title' => $t('Birthdays'),
      'value' => $value,
      'description' => $description,
      'severity' => $severity,
    );
  }
  return $requirements;
}

/**
 * Implementation of hook_uninstall().
 */
function birthdays_uninstall() {
  db_query('DROP TABLE {dob}');
  variable_del('birthdays_show_starsign');
  variable_del('birthdays_field_id');
  variable_del('birthdays_send_user');
  variable_del('birthdays_send_user_subject');
  variable_del('birthdays_send_user_message');
  variable_del('birthdays_remind');
  variable_del('birthdays_hide_year');
  variable_del('birthdays_block_number_by_days');
  variable_del('birthdays_block_number_by_birthdays');
  variable_del('birthdays_page_show_filters');
  variable_del('birthdays_page_settings');
  variable_del('birthdays_page_list_number');
  variable_del('birthdays_block_hide');
}

Functions

Namesort descending Description
birthdays_install Implementation of hook_install().
birthdays_requirements Implementation of hook_requirements().
birthdays_uninstall Implementation of hook_uninstall().
birthdays_update_1 Implementation of hook_update_N().
birthdays_update_2 Implementation of hook_update_N().
birthdays_update_5003 Remove the variable 'birthdays_field_name'.