You are here

tft.install in Taxonomy File Tree 7.2

Same filename and directory in other branches
  1. 8 tft.install
  2. 7 tft.install
  3. 3.x tft.install

Module install logic.

File

tft.install
View source
<?php

/**
 * @file
 * Module install logic.
 */

/**
 * Implements hook_install().
 */
function tft_install() {
  $vocabulary = taxonomy_vocabulary_machine_name_load('tft_tree');
  if (empty($vocabulary)) {
    $vocabulary = (object) array(
      'name' => "Opigno file tree",
      'machine_name' => 'tft_tree',
    );
    taxonomy_vocabulary_save($vocabulary);
  }
  variable_set('tft_vocabulary_vid', $vocabulary->vid);
  $type = node_type_load('tft_file');
  if (empty($type)) {
    $type = node_type_set_defaults(array(
      'type' => 'tft_file',
      'name' => st('File'),
      'base' => 'node_content',
      'description' => '',
      'custom' => 1,
      'modified' => 1,
      'locked' => 1,
      'promoted' => 0,
    ));
    node_type_save($type);
    node_add_body_field($type);
  }

  // Add the quiz weight field.
  $field = field_info_field('tft_file');
  if (empty($field)) {
    field_create_field(array(
      'field_name' => 'tft_file',
      'type' => 'file',
    ));
  }
  $field = field_info_field('tft_folder');
  if (empty($field)) {
    field_create_field(array(
      'cardinality' => 1,
      'field_name' => 'tft_folder',
      'foreign keys' => array(
        'tid' => array(
          'columns' => array(
            'tid' => 'tid',
          ),
          'table' => 'taxonomy_term_data',
        ),
      ),
      'indexes' => array(
        'tid' => array(
          0 => 'tid',
        ),
      ),
      'locked' => 0,
      'module' => 'taxonomy',
      'settings' => array(
        'allowed_values' => array(
          0 => array(
            'vocabulary' => 'tft_tree',
            'parent' => 0,
          ),
        ),
      ),
      'translatable' => 0,
      'type' => 'taxonomy_term_reference',
    ));
  }
  $instance = field_info_instance('node', 'tft_file', 'tft_file');
  if (empty($instance)) {
    field_create_instance(array(
      'field_name' => 'tft_file',
      'entity_type' => 'node',
      'bundle' => 'tft_file',
      'label' => "File",
      'required' => 1,
      'settings' => array(
        'file_extensions' => 'jpg jpeg gif png txt doc docx xls xlsx pdf ppt pptx pps odt ods odp',
      ),
    ));
  }
  $instance = field_info_instance('node', 'tft_folder', 'tft_file');
  if (empty($instance)) {
    field_create_instance(array(
      'bundle' => 'tft_file',
      'description' => '',
      'entity_type' => 'node',
      'field_name' => 'tft_folder',
      'label' => 'Folder',
      'required' => 0,
      'widget' => array(
        'active' => 1,
        'module' => 'options',
        'settings' => array(),
        'type' => 'options_select',
        'weight' => -2,
      ),
    ));
  }
}

/**
 * Implements hook_schema().
 */
function tft_schema() {
  return array(
    'tft_folder_content_weight' => array(
      'description' => 'Weights of folder child items',
      'fields' => array(
        'id' => array(
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
        ),
        'type' => array(
          'type' => 'varchar',
          'length' => 10,
        ),
        'parent_tid' => array(
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
        ),
        'weight' => array(
          'type' => 'int',
          'not null' => TRUE,
        ),
      ),
    ),
  );
}

/**
 * Implements hook_update_N for passing to Drupal 7.
 */
function tft_update_7000(&$sandbox) {
}

/**
 * Implements hook_update_N for updating to the 2.x branch.
 */
function tft_update_7200(&$sandbox) {

  // The 1.x branch (be it D6 or D7) had 3 tables. 2 of them are now part of sub-modules. Rename
  // the tables, so they don't conflict. The submodules, when installed for the first time, will
  // copy the content of these tables over to their own table.
  db_rename_table('tft_tid_og_nid', 'tft_tid_og_nid_d6');
  db_rename_table('tft_archive_restore', 'tft_archive_restore_d6');
  return t("Suffix 'tft_tid_og_nid' and 'tft_archive_restore' tables with '_d6'. They are not part of TFT core anymore, but of 2 submodules. When one of the submodules will be enabled, they will copy the content from these tables to their own.");
}

Functions

Namesort descending Description
tft_install Implements hook_install().
tft_schema Implements hook_schema().
tft_update_7000 Implements hook_update_N for passing to Drupal 7.
tft_update_7200 Implements hook_update_N for updating to the 2.x branch.