You are here

filefield.install in FileField 6.2

Same filename and directory in other branches
  1. 5.2 filefield.install
  2. 5 filefield.install
  3. 6.3 filefield.install

File

filefield.install
View source
<?php

/**
 * @file
 * FileField: Defines a CCK file field type.
 *
 * Uses content.module to store the fid and field specific metadata,
 * and Drupal's {files} table to store the actual file data.
 */
include_once drupal_get_path('module', 'filefield') . '/field_file.inc';

/**
 * Implementation of hook_install().
 */
function filefield_install() {
  content_notify('install', 'filefield');
}

/**
 * Implementation of hook_uninstall().
 */
function filefield_uninstall() {
  content_notify('uninstall', 'filefield');
}

/**
 * Implementation of hook_enable().
 */
function filefield_enable() {
  content_notify('enable', 'filefield');
}

/**
 * Implementation of hook_disable().
 */
function filefield_disable() {
  content_notify('disable', 'filefield');
}

// Update procedures.
function filefield_update_1() {
  $ret = array();
  include_once drupal_get_path('module', 'content') . '/content.module';
  include_once drupal_get_path('module', 'content') . '/content_admin.inc';
  $fields = content_fields();
  foreach ($fields as $field) {
    switch ($field['type']) {
      case 'file':
        $columns = array(
          'list' => array(
            'type' => 'int',
            'not null' => TRUE,
            'default' => '0',
          ),
        );
        content_alter_db_field(array(), array(), $field, $columns);
        break;
    }
  }
  db_query('DELETE FROM {cache}');
  return $ret;
}
function filefield_update_2() {
  cache_clear_all('*', 'cache_menu', TRUE);
  return array();
}

/**
 * Update to filefield 5.x-2.3: Move the 'show_list' widget setting
 * to the (inverse) 'force_list' field setting.
 */
function filefield_update_3() {
  $ret = array();
  include_once drupal_get_path('module', 'content') . '/content.module';
  include_once drupal_get_path('module', 'content') . '/content_admin.inc';
  $fields = content_fields();
  foreach ($fields as $field) {
    switch ($field['type']) {
      case 'file':
        $result = db_query("SELECT * FROM {node_field_instance} WHERE field_name = '%s'", $field['field_name']);
        while ($instance = db_fetch_object($result)) {
          $widget_settings = unserialize($instance->widget_settings);
          if (isset($widget_settings['show_list'])) {
            $show_list = $widget_settings['show_list'];
            unset($widget_settings['show_list']);

            // write the widget settings without 'show_list' to the instance
            $ret[] = update_sql("UPDATE {node_field_instance}\n               SET widget_settings = '" . serialize($widget_settings) . "'\n               WHERE field_name = '" . $field['field_name'] . "'\n               AND type_name = '" . $instance->type_name . "'");

            // write the field settings with the new $force_list to the global settings
            $global = db_result(db_query("SELECT * FROM {node_field} WHERE field_name = '%s'", $field['field_name']));
            $field_settings = unserialize($global->global_settings);
            $field_settings['force_list'] = $show_list == 0 ? 1 : 0;
            $ret[] = update_sql("UPDATE {node_field}\n               SET global_settings = '" . serialize($field_settings) . "'\n               WHERE field_name = '" . $field['field_name'] . "'");
          }
        }
        break;
    }
  }
  db_query('DELETE FROM {cache}');
  db_query('DELETE FROM {cache_content}');
  return $ret;
}
function filefield_update_6001() {
  include_once drupal_get_path('module', 'content') . '/includes/content.admin.inc';

  // add data column to filefields.
  $fields = content_fields();
  foreach ($fields as $field) {
    if ($field['type'] != 'file') {
      continue;
    }
    $new_field = $field;
    $new_field['columns']['data'] = array(
      'type' => 'text',
    );
    content_alter_db($field, $new_field);
  }
}

Functions

Namesort descending Description
filefield_disable Implementation of hook_disable().
filefield_enable Implementation of hook_enable().
filefield_install Implementation of hook_install().
filefield_uninstall Implementation of hook_uninstall().
filefield_update_1
filefield_update_2
filefield_update_3 Update to filefield 5.x-2.3: Move the 'show_list' widget setting to the (inverse) 'force_list' field setting.
filefield_update_6001