You are here

answers.install in Answers 7.3

File

answers.install
View source
<?php

/**
 * @file
 * Install file for the answers module.
 */
require_once dirname(__FILE__) . '/answers.features.field.inc';

/**
 * Implements hook_uninstall().
 */
function answers_uninstall() {
  variable_del('answers_new_answer_notice_subject');
  variable_del('answers_new_answer_notice_body');
  variable_del('answers_new_answer_notice_allow_p');
  variable_del('answers_question_create_button_text');
  variable_del('answers_question_edit_button_text');
  variable_del('answers_answer_create_button_text');
  variable_del('answers_answer_edit_button_text');
}

/**
 * Implements hook_requirements().
 */
function answers_requirements($phase) {
  if ($phase == 'runtime') {
    $t = get_t();
    $info = system_get_info('module', 'answers');
    $requirements['answers'] = array(
      'title' => $t('Answers'),
      'value' => $info['version'],
      'severity' => REQUIREMENT_OK,
    );
    $orphan_nids = _answers_orphan_nids();
    $questions = node_load_multiple($orphan_nids);
    $orphans = count($questions);
    if ($orphans > 0) {
      $d_options = array_merge(array(
        '!count' => $orphans,
        '@url' => url('admin/config/content/answers/orphan'),
      ), answers_translation());
      $requirements['answers']['description'] = $t('!count <a href="@url">Orphaned</a> !answers', $d_options);
      $requirements['answers']['severity'] = REQUIREMENT_WARNING;
    }
    return $requirements;
  }
}

/**
 * Add 'field_question_locked_p' to the question content type.
 */
function answers_update_7200() {
  $fields = answers_field_default_fields();
  if (!field_info_field('field_question_locked_p')) {
    $field = $fields['node-question-field_question_locked_p']['field_config'];
    field_create_field($field);
  }
  if (!field_info_instance('node', 'field_question_locked_p', 'question')) {
    $instance = $fields['node-question-field_question_locked_p']['field_instance'];
    field_create_instance($instance);
  }
  return array();
}

/**
 * Make sure that custom question fields have values set.
 *
 * If one doesn't, set the default value.
 */
function answers_update_7201() {
  $result = db_query("SELECT * from {node} WHERE type = 'question';");
  foreach ($result as $question) {
    $question = node_load($question->nid);
    $changed_p = FALSE;
    if (isset($question->field_answer_count['und'][0]['count'])) {
      $question->field_question_locked_p['und'][0]['count'] = 0;
      $changed_p = TRUE;
    }
    if (isset($question->field_notify_p['und'][0]['value'])) {
      $question->field_notify_p['und'][0]['value'] = 0;
      $changed_p = TRUE;
    }
    if (isset($question->field_question_locked_p['und'][0]['value'])) {
      $question->field_question_locked_p['und'][0]['value'] = 0;
      $changed_p = TRUE;
    }
    if ($changed_p) {
      watchdog('answers', 'Set default question fields for nid :nid', array(
        ':nid' => $question->nid,
      ));
      node_save($question);
    }
  }
  return array();
}

/**
 * Reset the theme cache so that answers theming is enabled.
 */
function answers_update_7300() {
  watchdog('answers', 'Enable answers theming');
  drupal_theme_rebuild();
  return t('Enable answers theming.');
}

/**
 * Drupal Coding Standards.
 *
 * Adds additional branding options.
 */
function answers_update_7304() {
  drupal_flush_all_caches();
  return array();
}

Functions

Namesort descending Description
answers_requirements Implements hook_requirements().
answers_uninstall Implements hook_uninstall().
answers_update_7200 Add 'field_question_locked_p' to the question content type.
answers_update_7201 Make sure that custom question fields have values set.
answers_update_7300 Reset the theme cache so that answers theming is enabled.
answers_update_7304 Drupal Coding Standards.