You are here

quizfileupload.install in Quiz File Upload 7.5

The install file for installing the quizfileupload module.

File

quizfileupload.install
View source
<?php

/**
 * @file
 * The install file for installing the quizfileupload module.
 */

/**
 * Implements hook_install().
 */
function quizfileupload_install() {

  // Add body field to quizfileupload node.
  quiz_question_add_body_field('quizfileupload');
  cache_clear_all('autoload:', 'cache');
  variable_set('node_options_quizfileupload', array(
    'status',
  ));
  variable_set('quizfileupload_default_max_score', 1);
}

/**
 * Implements hook_schema().
 */
function quizfileupload_schema() {

  // Properties for a question nodes go in here:
  $schema['quiz_fileupload_node_properties'] = array(
    'fields' => array(
      'nid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'vid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'filetypes' => array(
        'type' => 'text',
      ),
      'filesize' => array(
        'type' => 'varchar',
        'description' => "Filesize",
        'length' => 18,
        'not null' => FALSE,
      ),
      'correct_answer_evaluation' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'size' => 'tiny',
        'not null' => TRUE,
        'default' => 0,
      ),
    ),
    'primary key' => array(
      'nid',
      'vid',
    ),
  );

  // User answers go in here.
  $schema['quiz_fileupload_user_answers'] = array(
    'fields' => array(
      'answer_id' => array(
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ),
      'result_answer_id' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => FALSE,
      ),
      'score' => array(
        'type' => 'float',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
      ),
      'is_evaluated' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'size' => 'tiny',
        'not null' => TRUE,
        'default' => 0,
      ),
      'fid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => FALSE,
      ),
      'answer_feedback' => array(
        'type' => 'text',
      ),
      'answer_feedback_format' => array(
        'type' => 'varchar',
        'length' => 255,
      ),
    ),
    'primary key' => array(
      'answer_id',
    ),
    'unique keys' => array(
      'result_answer_id' => array(
        'result_answer_id',
      ),
    ),
  );
  return $schema;
}

/**
 * Implements hook_uninstall().
 */
function quizfileupload_uninstall() {
  cache_clear_all('variables', 'cache');
  drupal_set_message(t('The quiz file upload module has been uninstalled. Quiz file upload nodes may still exist, but they will not function properly.'));
}

/**
 * Fixes the data structure for users with the original #2092275 patch.
 */
function quizfileupload_update_7001() {
  $instance = field_info_instance('node', 'quizfileupload_scoring', 'quizfileupload');
  if ($instance) {
    field_delete_instance($instance, TRUE);
  }
  if (db_field_exists('quiz_fileupload_user_answers', 'is_evaluated')) {
    $spec = array(
      'type' => 'int',
      'unsigned' => TRUE,
      'size' => 'tiny',
      'not null' => TRUE,
      'default' => 0,
    );
    db_change_field('quiz_fileupload_user_answers', 'is_evaluated', 'is_evaluated', $spec);
  }
  if (db_field_exists('quiz_fileupload_node_properties', 'type')) {
    $spec = array(
      'type' => 'int',
      'unsigned' => TRUE,
      'size' => 'tiny',
      'not null' => TRUE,
      'default' => 0,
    );
    db_change_field('quiz_fileupload_node_properties', 'type', 'correct_answer_evaluation', $spec);
  }
}

/**
 * Add the option to manually score the question.
 */
function quizfileupload_update_7002() {

  // Add the required fields to the database.
  if (!db_field_exists('quiz_fileupload_node_properties', 'correct_answer_evaluation')) {
    $spec = array(
      'type' => 'int',
      'unsigned' => TRUE,
      'size' => 'tiny',
      'not null' => TRUE,
      'default' => 0,
    );
    db_add_field('quiz_fileupload_node_properties', 'correct_answer_evaluation', $spec);
  }
  if (!db_field_exists('quiz_fileupload_user_answers', 'is_evaluated')) {
    $spec = array(
      'type' => 'int',
      'unsigned' => TRUE,
      'size' => 'tiny',
      'not null' => TRUE,
      'default' => 0,
    );
    db_add_field('quiz_fileupload_user_answers', 'is_evaluated', $spec);
  }
  if (!db_field_exists('quiz_fileupload_user_answers', 'answer_feedback')) {
    $spec = array(
      'type' => 'text',
    );
    db_add_field('quiz_fileupload_user_answers', 'answer_feedback', $spec);
  }
  if (!db_field_exists('quiz_fileupload_user_answers', 'answer_feedback_format')) {
    $spec = array(
      'type' => 'varchar',
      'length' => 255,
    );
    db_add_field('quiz_fileupload_user_answers', 'answer_feedback_format', $spec);
  }
}

/**
 * Update the modules data structure to support quiz 5.x.
 */
function quizfileupload_update_7500() {

  // We may store empty files (as users are allowed to skip the question).
  $spec = array(
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => FALSE,
  );
  db_change_field('quiz_fileupload_user_answers', 'fid', 'fid', $spec);

  // Match the data storage of the Quiz 5.x version.
  db_drop_index('quiz_fileupload_user_answers', 'answer_id');
  db_add_field('quiz_fileupload_user_answers', 'result_answer_id', array(
    'type' => 'int',
    'unsigned' => TRUE,
    'not null' => FALSE,
  ));
  db_query("UPDATE {quiz_fileupload_user_answers} qfua\n    INNER JOIN {quiz_node_results_answers} qnra ON (qfua.question_nid = qnra.question_nid\n    AND qfua.question_vid = qnra.question_vid\n    AND qfua.result_id = qnra.result_id)\n    SET qfua.result_answer_id = qnra.result_answer_id");
  db_drop_field('quiz_fileupload_user_answers', 'result_id');
  db_drop_field('quiz_fileupload_user_answers', 'question_nid');
  db_drop_field('quiz_fileupload_user_answers', 'question_vid');
  db_add_unique_key('quiz_fileupload_user_answers', 'result_answer_id', array(
    'result_answer_id',
  ));

  // Rename the variable to match the default naming of the quiz module.
  variable_set('quizfileupload_default_max_score', variable_get('quizfileupload_default_score', 1));
  variable_del('quizfileupload_default_score');
}

/**
 * Issue #2709835 Change db field score to float.
 */
function quizfileupload_update_7501() {
  $spec = array(
    'type' => 'float',
    'unsigned' => TRUE,
    'not null' => TRUE,
    'default' => 0,
  );
  db_change_field('quiz_fileupload_user_answers', 'score', 'score', $spec);
}

/**
 * Issue #2973043 Normalise the variable quizfileupload_default_extensions.
 */
function quizfileupload_update_7502() {
  if ($extensions = variable_get('quizfileupload_default_extensions')) {
    variable_set('quizfileupload_default_extensions', preg_replace("/[\r\n]{2,}/", " ", $extensions));
  }
}

/**
 * Issue #2973014 Add filesize col to quiz_fileupload_node_properties table.
 */
function quizfileupload_update_7503() {
  $spec = array(
    'type' => 'varchar',
    'description' => "Filesize",
    'length' => 18,
    'not null' => FALSE,
  );
  db_add_field('quiz_fileupload_node_properties', 'filesize', $spec);
}

Functions

Namesort descending Description
quizfileupload_install Implements hook_install().
quizfileupload_schema Implements hook_schema().
quizfileupload_uninstall Implements hook_uninstall().
quizfileupload_update_7001 Fixes the data structure for users with the original #2092275 patch.
quizfileupload_update_7002 Add the option to manually score the question.
quizfileupload_update_7500 Update the modules data structure to support quiz 5.x.
quizfileupload_update_7501 Issue #2709835 Change db field score to float.
quizfileupload_update_7502 Issue #2973043 Normalise the variable quizfileupload_default_extensions.
quizfileupload_update_7503 Issue #2973014 Add filesize col to quiz_fileupload_node_properties table.