Commit 9502260e authored by Dries's avatar Dries

- Patch #902264 by Damien Tournoud: move hook_field_schema() to .install files...

- Patch #902264 by Damien Tournoud: move hook_field_schema() to .install files so we can get the upgrade path to work.
parent 47326c49
......@@ -211,6 +211,9 @@ function hook_field_info_alter(&$info) {
/**
* Define the Field API schema for a field structure.
*
* This hook MUST be defined in .install for it to be detected during
* installation and upgrade.
*
* @param $field
* A field structure.
*
......
......@@ -317,6 +317,7 @@ function field_create_field($field) {
$field['storage']['module'] = $storage_type['module'];
$field['storage']['active'] = 1;
// Collect storage information.
module_load_install($field['module']);
$schema = (array) module_invoke($field['module'], 'field_schema', $field);
$schema += array('columns' => array(), 'indexes' => array());
// 'columns' are hardcoded in the field type.
......@@ -426,6 +427,7 @@ function field_update_field($field) {
// Collect the new storage information, since what is in
// $prior_field may no longer be right.
module_load_install($field['module']);
$schema = (array) module_invoke($field['module'], 'field_schema', $field);
$schema += array('columns' => array(), 'indexes' => array());
// 'columns' are hardcoded in the field type.
......@@ -552,6 +554,7 @@ function field_read_fields($params = array(), $include_additional = array()) {
module_invoke_all('field_read_field', $field);
// Populate storage information.
module_load_install($field['module']);
$schema = (array) module_invoke($field['module'], 'field_schema', $field);
$schema += array('columns' => array(), 'indexes' => array());
$field['columns'] = $schema['columns'];
......
<?php
// $Id$
/**
* @file
* Install, update and uninstall functions for the list module.
*/
/**
* Implements hook_field_schema().
*/
function list_field_schema($field) {
switch ($field['type']) {
case 'list_text':
$columns = array(
'value' => array(
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
),
);
break;
case 'list_number':
$columns = array(
'value' => array(
'type' => 'float',
'not null' => FALSE,
),
);
break;
default:
$columns = array(
'value' => array(
'type' => 'int',
'not null' => FALSE,
),
);
break;
}
return array(
'columns' => $columns,
'indexes' => array(
'value' => array('value'),
),
);
}
\ No newline at end of file
......@@ -55,45 +55,6 @@ function list_field_info() {
);
}
/**
* Implements hook_field_schema().
*/
function list_field_schema($field) {
switch ($field['type']) {
case 'list_text':
$columns = array(
'value' => array(
'type' => 'varchar',
'length' => 255,
'not null' => FALSE,
),
);
break;
case 'list_number':
$columns = array(
'value' => array(
'type' => 'float',
'not null' => FALSE,
),
);
break;
default:
$columns = array(
'value' => array(
'type' => 'int',
'not null' => FALSE,
),
);
break;
}
return array(
'columns' => $columns,
'indexes' => array(
'value' => array('value'),
),
);
}
/**
* Implements hook_field_settings_form().
*
......
<?php
// $Id$
/**
* @file
* Install, update and uninstall functions for the number module.
*/
/**
* Implements hook_field_schema().
*/
function number_field_schema($field) {
switch ($field['type']) {
case 'number_integer' :
$columns = array(
'value' => array(
'type' => 'int',
'not null' => FALSE
),
);
break;
case 'number_float' :
$columns = array(
'value' => array(
'type' => 'float',
'not null' => FALSE
),
);
break;
case 'number_decimal' :
$columns = array(
'value' => array(
'type' => 'numeric',
'precision' => $field['settings']['precision'],
'scale' => $field['settings']['scale'],
'not null' => FALSE
),
);
break;
}
return array(
'columns' => $columns,
);
}
......@@ -50,45 +50,6 @@ function number_field_info() {
);
}
/**
* Implements hook_field_schema().
*/
function number_field_schema($field) {
switch ($field['type']) {
case 'number_integer' :
$columns = array(
'value' => array(
'type' => 'int',
'not null' => FALSE
),
);
break;
case 'number_float' :
$columns = array(
'value' => array(
'type' => 'float',
'not null' => FALSE
),
);
break;
case 'number_decimal' :
$columns = array(
'value' => array(
'type' => 'numeric',
'precision' => $field['settings']['precision'],
'scale' => $field['settings']['scale'],
'not null' => FALSE
),
);
break;
}
return array(
'columns' => $columns,
);
}
/**
* Implements hook_field_settings_form().
*/
......
<?php
// $Id$
/**
* @file
* Install, update and uninstall functions for the text module.
*/
/**
* Implements hook_field_schema().
*/
function text_field_schema($field) {
switch ($field['type']) {
case 'text':
$columns = array(
'value' => array(
'type' => 'varchar',
'length' => $field['settings']['max_length'],
'not null' => FALSE,
),
);
break;
case 'text_long':
$columns = array(
'value' => array(
'type' => 'text',
'size' => 'big',
'not null' => FALSE,
),
);
break;
case 'text_with_summary':
$columns = array(
'value' => array(
'type' => 'text',
'size' => 'big',
'not null' => FALSE,
),
'summary' => array(
'type' => 'text',
'size' => 'big',
'not null' => FALSE,
),
);
break;
}
$columns += array(
'format' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
),
);
return array(
'columns' => $columns,
'indexes' => array(
'format' => array('format'),
),
);
}
......@@ -57,59 +57,6 @@ function text_field_info() {
);
}
/**
* Implements hook_field_schema().
*/
function text_field_schema($field) {
switch ($field['type']) {
case 'text':
$columns = array(
'value' => array(
'type' => 'varchar',
'length' => $field['settings']['max_length'],
'not null' => FALSE,
),
);
break;
case 'text_long':
$columns = array(
'value' => array(
'type' => 'text',
'size' => 'big',
'not null' => FALSE,
),
);
break;
case 'text_with_summary':
$columns = array(
'value' => array(
'type' => 'text',
'size' => 'big',
'not null' => FALSE,
),
'summary' => array(
'type' => 'text',
'size' => 'big',
'not null' => FALSE,
),
);
break;
}
$columns += array(
'format' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
),
);
return array(
'columns' => $columns,
'indexes' => array(
'format' => array('format'),
),
);
}
/**
* Implements hook_field_settings_form().
*/
......
......@@ -46,42 +46,6 @@ function field_test_field_info() {
);
}
/**
* Implements hook_field_schema().
*/
function field_test_field_schema($field) {
if ($field['type'] == 'test_field') {
return array(
'columns' => array(
'value' => array(
'type' => 'int',
'size' => 'medium',
'not null' => FALSE,
),
),
'indexes' => array(
'value' => array('value'),
),
);
}
else {
return array(
'columns' => array(
'shape' => array(
'type' => 'varchar',
'length' => 32,
'not null' => FALSE,
),
'color' => array(
'type' => 'varchar',
'length' => 32,
'not null' => FALSE,
),
),
);
}
}
/**
* Implements hook_field_update_forbid().
*/
......
......@@ -106,3 +106,39 @@ function field_test_schema() {
return $schema;
}
/**
* Implements hook_field_schema().
*/
function field_test_field_schema($field) {
if ($field['type'] == 'test_field') {
return array(
'columns' => array(
'value' => array(
'type' => 'int',
'size' => 'medium',
'not null' => FALSE,
),
),
'indexes' => array(
'value' => array('value'),
),
);
}
else {
return array(
'columns' => array(
'shape' => array(
'type' => 'varchar',
'length' => 32,
'not null' => FALSE,
),
'color' => array(
'type' => 'varchar',
'length' => 32,
'not null' => FALSE,
),
),
);
}
}
......@@ -31,38 +31,6 @@ function file_field_info() {
);
}
/**
* Implements hook_field_schema().
*/
function file_field_schema($field) {
return array(
'columns' => array(
'fid' => array(
'description' => 'The {files}.fid being referenced in this field.',
'type' => 'int',
'not null' => FALSE,
'unsigned' => TRUE,
),
'display' => array(
'description' => 'Flag to control whether this file should be displayed when viewing content.',
'type' => 'int',
'size' => 'tiny',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 1,
),
'description' => array(
'description' => 'A description of the file.',
'type' => 'text',
'not null' => FALSE,
),
),
'indexes' => array(
'fid' => array('fid'),
),
);
}
/**
* Implements hook_field_settings_form().
*/
......
......@@ -6,6 +6,38 @@
* Install, update and uninstall functions for File module.
*/
/**
* Implements hook_field_schema().
*/
function file_field_schema($field) {
return array(
'columns' => array(
'fid' => array(
'description' => 'The {files}.fid being referenced in this field.',
'type' => 'int',
'not null' => FALSE,
'unsigned' => TRUE,
),
'display' => array(
'description' => 'Flag to control whether this file should be displayed when viewing content.',
'type' => 'int',
'size' => 'tiny',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 1,
),
'description' => array(
'description' => 'A description of the file.',
'type' => 'text',
'not null' => FALSE,
),
),
'indexes' => array(
'fid' => array('fid'),
),
);
}
/**
* Implements hook_requirements().
*
......
......@@ -33,37 +33,6 @@ function image_field_info() {
);
}
/**
* Implements hook_field_schema().
*/
function image_field_schema($field) {
return array(
'columns' => array(
'fid' => array(
'description' => 'The {files}.fid being referenced in this field.',
'type' => 'int',
'not null' => FALSE,
'unsigned' => TRUE,
),
'alt' => array(
'description' => "Alternative image text, for the image's 'alt' attribute.",
'type' => 'varchar',
'length' => 128,
'not null' => FALSE,
),
'title' => array(
'description' => "Image title text, for the image's 'title' attribute.",
'type' => 'varchar',
'length' => 128,
'not null' => FALSE,
),
),
'indexes' => array(
'fid' => array('fid'),
),
);
}
/**
* Implements hook_field_settings_form().
*/
......
......@@ -107,6 +107,37 @@ function image_schema() {
return $schema;
}
/**
* Implements hook_field_schema().
*/
function image_field_schema($field) {
return array(
'columns' => array(
'fid' => array(
'description' => 'The {files}.fid being referenced in this field.',
'type' => 'int',
'not null' => FALSE,
'unsigned' => TRUE,
),
'alt' => array(
'description' => "Alternative image text, for the image's 'alt' attribute.",
'type' => 'varchar',
'length' => 128,
'not null' => FALSE,
),
'title' => array(
'description' => "Image title text, for the image's 'title' attribute.",
'type' => 'varchar',
'length' => 128,
'not null' => FALSE,
),
),
'indexes' => array(
'fid' => array('fid'),
),
);
}
/**
* Install the schema for users upgrading from the contributed module.
*/
......
......@@ -221,6 +221,24 @@ function taxonomy_schema() {
return $schema;
}
/**
* Implements hook_field_schema().
*/
function taxonomy_field_schema($field) {
return array(
'columns' => array(
'tid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
),
),
'indexes' => array(
'tid' => array('tid'),
),
);
}
/**
* Implements hook_update_dependencies().
*/
......
......@@ -1117,24 +1117,6 @@ function taxonomy_options_list($field) {
return $function($field);
}
/**
* Implements hook_field_schema().
*/
function taxonomy_field_schema($field) {
return array(
'columns' => array(
'tid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => FALSE,
),
),
'indexes' => array(
'tid' => array('tid'),
),
);
}
/**
* Implements hook_field_validate().
*
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment