2009-02-03 17:30:13 +00:00
|
|
|
<?php
|
2009-02-10 03:16:15 +00:00
|
|
|
|
2009-05-13 19:42:18 +00:00
|
|
|
/**
|
|
|
|
* @file
|
|
|
|
* Install, update and uninstall functions for the field module.
|
|
|
|
*/
|
|
|
|
|
2009-02-03 17:30:13 +00:00
|
|
|
/**
|
2009-12-04 16:49:48 +00:00
|
|
|
* Implements hook_schema().
|
2009-02-03 17:30:13 +00:00
|
|
|
*/
|
|
|
|
function field_schema() {
|
|
|
|
// Static (meta) tables.
|
|
|
|
$schema['field_config'] = array(
|
|
|
|
'fields' => array(
|
2009-03-10 09:45:32 +00:00
|
|
|
'id' => array(
|
|
|
|
'type' => 'serial',
|
|
|
|
'not null' => TRUE,
|
|
|
|
'description' => 'The primary identifier for a field',
|
|
|
|
),
|
2009-02-03 17:30:13 +00:00
|
|
|
'field_name' => array(
|
|
|
|
'type' => 'varchar',
|
|
|
|
'length' => 32,
|
|
|
|
'not null' => TRUE,
|
2009-05-28 10:05:32 +00:00
|
|
|
'description' => 'The name of this field. Non-deleted field names are unique, but multiple deleted fields can have the same name.',
|
2009-02-03 17:30:13 +00:00
|
|
|
),
|
|
|
|
'type' => array(
|
|
|
|
'type' => 'varchar',
|
|
|
|
'length' => 128,
|
|
|
|
'not null' => TRUE,
|
- Patch #443422 by yched, bjaspan | chx, merlinofchaos, Scott Reynolds, plach, profix898, mattyoung: added support for pluggable 'per field' storage engine. Comes with documentation and tests.
The Field Attach API uses the Field Storage API to perform all "database access". Each Field Storage API hook function defines a primitive database operation such as read, write, or delete. The default field storage module, field_sql_storage.module, uses the local SQL database to implement these operations, but alternative field storage backends can choose to represent the data in SQL differently or use a completely different storage mechanism such as a cloud-based database.
2009-09-27 12:52:55 +00:00
|
|
|
'description' => 'The type of this field.',
|
2009-02-03 17:30:13 +00:00
|
|
|
),
|
- Patch #443422 by yched, bjaspan | chx, merlinofchaos, Scott Reynolds, plach, profix898, mattyoung: added support for pluggable 'per field' storage engine. Comes with documentation and tests.
The Field Attach API uses the Field Storage API to perform all "database access". Each Field Storage API hook function defines a primitive database operation such as read, write, or delete. The default field storage module, field_sql_storage.module, uses the local SQL database to implement these operations, but alternative field storage backends can choose to represent the data in SQL differently or use a completely different storage mechanism such as a cloud-based database.
2009-09-27 12:52:55 +00:00
|
|
|
'module' => array(
|
|
|
|
'type' => 'varchar',
|
|
|
|
'length' => 128,
|
|
|
|
'not null' => TRUE,
|
|
|
|
'default' => '',
|
|
|
|
'description' => 'The module that implements the field type.',
|
|
|
|
),
|
|
|
|
'active' => array(
|
2009-02-03 17:30:13 +00:00
|
|
|
'type' => 'int',
|
|
|
|
'size' => 'tiny',
|
|
|
|
'not null' => TRUE,
|
|
|
|
'default' => 0,
|
- Patch #443422 by yched, bjaspan | chx, merlinofchaos, Scott Reynolds, plach, profix898, mattyoung: added support for pluggable 'per field' storage engine. Comes with documentation and tests.
The Field Attach API uses the Field Storage API to perform all "database access". Each Field Storage API hook function defines a primitive database operation such as read, write, or delete. The default field storage module, field_sql_storage.module, uses the local SQL database to implement these operations, but alternative field storage backends can choose to represent the data in SQL differently or use a completely different storage mechanism such as a cloud-based database.
2009-09-27 12:52:55 +00:00
|
|
|
'description' => 'Boolean indicating whether the module that implements the field type is enabled.',
|
2009-02-03 17:30:13 +00:00
|
|
|
),
|
- Patch #443422 by yched, bjaspan | chx, merlinofchaos, Scott Reynolds, plach, profix898, mattyoung: added support for pluggable 'per field' storage engine. Comes with documentation and tests.
The Field Attach API uses the Field Storage API to perform all "database access". Each Field Storage API hook function defines a primitive database operation such as read, write, or delete. The default field storage module, field_sql_storage.module, uses the local SQL database to implement these operations, but alternative field storage backends can choose to represent the data in SQL differently or use a completely different storage mechanism such as a cloud-based database.
2009-09-27 12:52:55 +00:00
|
|
|
'storage_type' => array(
|
|
|
|
'type' => 'varchar',
|
|
|
|
'length' => 128,
|
2009-02-03 17:30:13 +00:00
|
|
|
'not null' => TRUE,
|
- Patch #443422 by yched, bjaspan | chx, merlinofchaos, Scott Reynolds, plach, profix898, mattyoung: added support for pluggable 'per field' storage engine. Comes with documentation and tests.
The Field Attach API uses the Field Storage API to perform all "database access". Each Field Storage API hook function defines a primitive database operation such as read, write, or delete. The default field storage module, field_sql_storage.module, uses the local SQL database to implement these operations, but alternative field storage backends can choose to represent the data in SQL differently or use a completely different storage mechanism such as a cloud-based database.
2009-09-27 12:52:55 +00:00
|
|
|
'description' => 'The storage backend for the field.',
|
2009-02-03 17:30:13 +00:00
|
|
|
),
|
- Patch #443422 by yched, bjaspan | chx, merlinofchaos, Scott Reynolds, plach, profix898, mattyoung: added support for pluggable 'per field' storage engine. Comes with documentation and tests.
The Field Attach API uses the Field Storage API to perform all "database access". Each Field Storage API hook function defines a primitive database operation such as read, write, or delete. The default field storage module, field_sql_storage.module, uses the local SQL database to implement these operations, but alternative field storage backends can choose to represent the data in SQL differently or use a completely different storage mechanism such as a cloud-based database.
2009-09-27 12:52:55 +00:00
|
|
|
'storage_module' => array(
|
2009-02-03 17:30:13 +00:00
|
|
|
'type' => 'varchar',
|
|
|
|
'length' => 128,
|
|
|
|
'not null' => TRUE,
|
|
|
|
'default' => '',
|
- Patch #443422 by yched, bjaspan | chx, merlinofchaos, Scott Reynolds, plach, profix898, mattyoung: added support for pluggable 'per field' storage engine. Comes with documentation and tests.
The Field Attach API uses the Field Storage API to perform all "database access". Each Field Storage API hook function defines a primitive database operation such as read, write, or delete. The default field storage module, field_sql_storage.module, uses the local SQL database to implement these operations, but alternative field storage backends can choose to represent the data in SQL differently or use a completely different storage mechanism such as a cloud-based database.
2009-09-27 12:52:55 +00:00
|
|
|
'description' => 'The module that implements the storage backend.',
|
2009-02-03 17:30:13 +00:00
|
|
|
),
|
- Patch #443422 by yched, bjaspan | chx, merlinofchaos, Scott Reynolds, plach, profix898, mattyoung: added support for pluggable 'per field' storage engine. Comes with documentation and tests.
The Field Attach API uses the Field Storage API to perform all "database access". Each Field Storage API hook function defines a primitive database operation such as read, write, or delete. The default field storage module, field_sql_storage.module, uses the local SQL database to implement these operations, but alternative field storage backends can choose to represent the data in SQL differently or use a completely different storage mechanism such as a cloud-based database.
2009-09-27 12:52:55 +00:00
|
|
|
'storage_active' => array(
|
2009-02-03 17:30:13 +00:00
|
|
|
'type' => 'int',
|
|
|
|
'size' => 'tiny',
|
|
|
|
'not null' => TRUE,
|
2009-05-28 10:05:32 +00:00
|
|
|
'default' => 0,
|
- Patch #443422 by yched, bjaspan | chx, merlinofchaos, Scott Reynolds, plach, profix898, mattyoung: added support for pluggable 'per field' storage engine. Comes with documentation and tests.
The Field Attach API uses the Field Storage API to perform all "database access". Each Field Storage API hook function defines a primitive database operation such as read, write, or delete. The default field storage module, field_sql_storage.module, uses the local SQL database to implement these operations, but alternative field storage backends can choose to represent the data in SQL differently or use a completely different storage mechanism such as a cloud-based database.
2009-09-27 12:52:55 +00:00
|
|
|
'description' => 'Boolean indicating whether the module that implements the storage backend is enabled.',
|
2009-02-03 17:30:13 +00:00
|
|
|
),
|
- Patch #443422 by yched, bjaspan | chx, merlinofchaos, Scott Reynolds, plach, profix898, mattyoung: added support for pluggable 'per field' storage engine. Comes with documentation and tests.
The Field Attach API uses the Field Storage API to perform all "database access". Each Field Storage API hook function defines a primitive database operation such as read, write, or delete. The default field storage module, field_sql_storage.module, uses the local SQL database to implement these operations, but alternative field storage backends can choose to represent the data in SQL differently or use a completely different storage mechanism such as a cloud-based database.
2009-09-27 12:52:55 +00:00
|
|
|
'locked' => array(
|
2009-08-22 00:58:55 +00:00
|
|
|
'type' => 'int',
|
|
|
|
'size' => 'tiny',
|
|
|
|
'not null' => TRUE,
|
|
|
|
'default' => 0,
|
- Patch #443422 by yched, bjaspan | chx, merlinofchaos, Scott Reynolds, plach, profix898, mattyoung: added support for pluggable 'per field' storage engine. Comes with documentation and tests.
The Field Attach API uses the Field Storage API to perform all "database access". Each Field Storage API hook function defines a primitive database operation such as read, write, or delete. The default field storage module, field_sql_storage.module, uses the local SQL database to implement these operations, but alternative field storage backends can choose to represent the data in SQL differently or use a completely different storage mechanism such as a cloud-based database.
2009-09-27 12:52:55 +00:00
|
|
|
'description' => '@TODO',
|
2009-08-22 00:58:55 +00:00
|
|
|
),
|
- Patch #443422 by yched, bjaspan | chx, merlinofchaos, Scott Reynolds, plach, profix898, mattyoung: added support for pluggable 'per field' storage engine. Comes with documentation and tests.
The Field Attach API uses the Field Storage API to perform all "database access". Each Field Storage API hook function defines a primitive database operation such as read, write, or delete. The default field storage module, field_sql_storage.module, uses the local SQL database to implement these operations, but alternative field storage backends can choose to represent the data in SQL differently or use a completely different storage mechanism such as a cloud-based database.
2009-09-27 12:52:55 +00:00
|
|
|
'data' => array(
|
2010-06-25 17:47:22 +00:00
|
|
|
'type' => 'blob',
|
|
|
|
'size' => 'big',
|
- Patch #443422 by yched, bjaspan | chx, merlinofchaos, Scott Reynolds, plach, profix898, mattyoung: added support for pluggable 'per field' storage engine. Comes with documentation and tests.
The Field Attach API uses the Field Storage API to perform all "database access". Each Field Storage API hook function defines a primitive database operation such as read, write, or delete. The default field storage module, field_sql_storage.module, uses the local SQL database to implement these operations, but alternative field storage backends can choose to represent the data in SQL differently or use a completely different storage mechanism such as a cloud-based database.
2009-09-27 12:52:55 +00:00
|
|
|
'not null' => TRUE,
|
|
|
|
'serialize' => TRUE,
|
|
|
|
'description' => 'Serialized data containing the field properties that do not warrant a dedicated column.',
|
|
|
|
),
|
|
|
|
'cardinality' => array(
|
|
|
|
'type' => 'int',
|
|
|
|
'size' => 'tiny',
|
|
|
|
'not null' => TRUE,
|
|
|
|
'default' => 0,
|
|
|
|
),
|
|
|
|
'translatable' => array(
|
2009-02-03 17:30:13 +00:00
|
|
|
'type' => 'int',
|
|
|
|
'size' => 'tiny',
|
|
|
|
'not null' => TRUE,
|
2009-05-28 10:05:32 +00:00
|
|
|
'default' => 0,
|
2009-02-03 17:30:13 +00:00
|
|
|
),
|
|
|
|
'deleted' => array(
|
|
|
|
'type' => 'int',
|
|
|
|
'size' => 'tiny',
|
|
|
|
'not null' => TRUE,
|
|
|
|
'default' => 0,
|
|
|
|
),
|
|
|
|
),
|
2009-03-10 09:45:32 +00:00
|
|
|
'primary key' => array('id'),
|
2009-02-03 17:30:13 +00:00
|
|
|
'indexes' => array(
|
2009-05-28 10:05:32 +00:00
|
|
|
'field_name' => array('field_name'),
|
2012-03-02 05:21:29 +00:00
|
|
|
// Used by field_sync_field_status().
|
- Patch #443422 by yched, bjaspan | chx, merlinofchaos, Scott Reynolds, plach, profix898, mattyoung: added support for pluggable 'per field' storage engine. Comes with documentation and tests.
The Field Attach API uses the Field Storage API to perform all "database access". Each Field Storage API hook function defines a primitive database operation such as read, write, or delete. The default field storage module, field_sql_storage.module, uses the local SQL database to implement these operations, but alternative field storage backends can choose to represent the data in SQL differently or use a completely different storage mechanism such as a cloud-based database.
2009-09-27 12:52:55 +00:00
|
|
|
'active' => array('active'),
|
|
|
|
'storage_active' => array('storage_active'),
|
|
|
|
'deleted' => array('deleted'),
|
|
|
|
// Used by field_modules_disabled().
|
2009-02-03 17:30:13 +00:00
|
|
|
'module' => array('module'),
|
- Patch #443422 by yched, bjaspan | chx, merlinofchaos, Scott Reynolds, plach, profix898, mattyoung: added support for pluggable 'per field' storage engine. Comes with documentation and tests.
The Field Attach API uses the Field Storage API to perform all "database access". Each Field Storage API hook function defines a primitive database operation such as read, write, or delete. The default field storage module, field_sql_storage.module, uses the local SQL database to implement these operations, but alternative field storage backends can choose to represent the data in SQL differently or use a completely different storage mechanism such as a cloud-based database.
2009-09-27 12:52:55 +00:00
|
|
|
'storage_module' => array('storage_module'),
|
2009-02-03 17:30:13 +00:00
|
|
|
'type' => array('type'),
|
- Patch #443422 by yched, bjaspan | chx, merlinofchaos, Scott Reynolds, plach, profix898, mattyoung: added support for pluggable 'per field' storage engine. Comes with documentation and tests.
The Field Attach API uses the Field Storage API to perform all "database access". Each Field Storage API hook function defines a primitive database operation such as read, write, or delete. The default field storage module, field_sql_storage.module, uses the local SQL database to implement these operations, but alternative field storage backends can choose to represent the data in SQL differently or use a completely different storage mechanism such as a cloud-based database.
2009-09-27 12:52:55 +00:00
|
|
|
'storage_type' => array('storage_type'),
|
2009-02-03 17:30:13 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
$schema['field_config_instance'] = array(
|
|
|
|
'fields' => array(
|
2009-03-10 09:45:32 +00:00
|
|
|
'id' => array(
|
|
|
|
'type' => 'serial',
|
|
|
|
'not null' => TRUE,
|
|
|
|
'description' => 'The primary identifier for a field instance',
|
|
|
|
),
|
|
|
|
'field_id' => array(
|
|
|
|
'type' => 'int',
|
|
|
|
'not null' => TRUE,
|
|
|
|
'description' => 'The identifier of the field attached by this instance',
|
|
|
|
),
|
2009-10-01 19:16:57 +00:00
|
|
|
'field_name' => array(
|
|
|
|
'type' => 'varchar',
|
|
|
|
'length' => 32,
|
2009-02-03 17:30:13 +00:00
|
|
|
'not null' => TRUE,
|
2009-10-01 19:16:57 +00:00
|
|
|
'default' => ''
|
|
|
|
),
|
2010-03-27 05:52:50 +00:00
|
|
|
'entity_type' => array(
|
2009-10-15 12:44:36 +00:00
|
|
|
'type' => 'varchar',
|
|
|
|
'length' => 32,
|
|
|
|
'not null' => TRUE,
|
|
|
|
'default' => ''
|
|
|
|
),
|
2009-10-01 19:16:57 +00:00
|
|
|
'bundle' => array(
|
|
|
|
'type' => 'varchar',
|
|
|
|
'length' => 128,
|
|
|
|
'not null' => TRUE,
|
|
|
|
'default' => ''
|
2009-02-03 17:30:13 +00:00
|
|
|
),
|
|
|
|
'data' => array(
|
2010-06-25 17:47:22 +00:00
|
|
|
'type' => 'blob',
|
|
|
|
'size' => 'big',
|
2009-02-03 17:30:13 +00:00
|
|
|
'not null' => TRUE,
|
|
|
|
'serialize' => TRUE,
|
|
|
|
),
|
|
|
|
'deleted' => array(
|
|
|
|
'type' => 'int',
|
|
|
|
'size' => 'tiny',
|
|
|
|
'not null' => TRUE,
|
|
|
|
'default' => 0,
|
|
|
|
),
|
|
|
|
),
|
2009-03-10 09:45:32 +00:00
|
|
|
'primary key' => array('id'),
|
2009-02-03 17:30:13 +00:00
|
|
|
'indexes' => array(
|
- Patch #443422 by yched, bjaspan | chx, merlinofchaos, Scott Reynolds, plach, profix898, mattyoung: added support for pluggable 'per field' storage engine. Comes with documentation and tests.
The Field Attach API uses the Field Storage API to perform all "database access". Each Field Storage API hook function defines a primitive database operation such as read, write, or delete. The default field storage module, field_sql_storage.module, uses the local SQL database to implement these operations, but alternative field storage backends can choose to represent the data in SQL differently or use a completely different storage mechanism such as a cloud-based database.
2009-09-27 12:52:55 +00:00
|
|
|
// Used by field_delete_instance().
|
2010-03-27 05:52:50 +00:00
|
|
|
'field_name_bundle' => array('field_name', 'entity_type', 'bundle'),
|
- Patch #443422 by yched, bjaspan | chx, merlinofchaos, Scott Reynolds, plach, profix898, mattyoung: added support for pluggable 'per field' storage engine. Comes with documentation and tests.
The Field Attach API uses the Field Storage API to perform all "database access". Each Field Storage API hook function defines a primitive database operation such as read, write, or delete. The default field storage module, field_sql_storage.module, uses the local SQL database to implement these operations, but alternative field storage backends can choose to represent the data in SQL differently or use a completely different storage mechanism such as a cloud-based database.
2009-09-27 12:52:55 +00:00
|
|
|
// Used by field_read_instances().
|
|
|
|
'deleted' => array('deleted'),
|
2009-02-03 17:30:13 +00:00
|
|
|
),
|
|
|
|
);
|
|
|
|
$schema['cache_field'] = drupal_get_schema_unprocessed('system', 'cache');
|
|
|
|
|
|
|
|
return $schema;
|
|
|
|
}
|
2010-09-13 05:50:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Utility function: create a field by writing directly to the database.
|
|
|
|
*
|
2010-09-29 19:46:40 +00:00
|
|
|
* This function can be used for databases whose schema is at field module
|
|
|
|
* version 7000 or higher.
|
2010-09-13 05:50:09 +00:00
|
|
|
*
|
|
|
|
* @ingroup update-api-6.x-to-7.x
|
|
|
|
*/
|
|
|
|
function _update_7000_field_create_field(&$field) {
|
|
|
|
// Merge in default values.`
|
|
|
|
$field += array(
|
|
|
|
'entity_types' => array(),
|
|
|
|
'cardinality' => 1,
|
|
|
|
'translatable' => FALSE,
|
|
|
|
'locked' => FALSE,
|
|
|
|
'settings' => array(),
|
|
|
|
'indexes' => array(),
|
|
|
|
'deleted' => 0,
|
|
|
|
'active' => 1,
|
|
|
|
);
|
|
|
|
|
|
|
|
// Set storage.
|
|
|
|
$field['storage'] = array(
|
|
|
|
'type' => 'field_sql_storage',
|
|
|
|
'settings' => array(),
|
|
|
|
'module' => 'field_sql_storage',
|
|
|
|
'active' => 1,
|
|
|
|
);
|
|
|
|
|
2010-12-18 02:04:36 +00:00
|
|
|
// Fetch the field schema to initialize columns and indexes. The field module
|
|
|
|
// is not guaranteed to be loaded at this point.
|
|
|
|
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.
|
|
|
|
$field['columns'] = $schema['columns'];
|
|
|
|
// 'indexes' can be both hardcoded in the field type, and specified in the
|
|
|
|
// incoming $field definition.
|
|
|
|
$field['indexes'] += $schema['indexes'];
|
|
|
|
|
2010-09-13 05:50:09 +00:00
|
|
|
// The serialized 'data' column contains everything from $field that does not
|
|
|
|
// have its own column and is not automatically populated when the field is
|
|
|
|
// read.
|
|
|
|
$data = $field;
|
|
|
|
unset($data['columns'], $data['field_name'], $data['type'], $data['active'], $data['module'], $data['storage_type'], $data['storage_active'], $data['storage_module'], $data['locked'], $data['cardinality'], $data['deleted']);
|
|
|
|
// Additionally, do not save the 'bundles' property populated by
|
|
|
|
// field_info_field().
|
|
|
|
unset($data['bundles']);
|
|
|
|
|
|
|
|
// Write the field to the database.
|
|
|
|
$record = array(
|
|
|
|
'field_name' => $field['field_name'],
|
|
|
|
'type' => $field['type'],
|
|
|
|
'module' => $field['module'],
|
|
|
|
'active' => (int) $field['active'],
|
|
|
|
'storage_type' => $field['storage']['type'],
|
|
|
|
'storage_module' => $field['storage']['module'],
|
|
|
|
'storage_active' => (int) $field['storage']['active'],
|
|
|
|
'locked' => (int) $field['locked'],
|
|
|
|
'data' => serialize($data),
|
|
|
|
'cardinality' => $field['cardinality'],
|
|
|
|
'translatable' => (int) $field['translatable'],
|
|
|
|
'deleted' => (int) $field['deleted'],
|
|
|
|
);
|
|
|
|
// We don't use drupal_write_record() here because it depends on the schema.
|
|
|
|
$field['id'] = db_insert('field_config')
|
|
|
|
->fields($record)
|
|
|
|
->execute();
|
|
|
|
|
2010-12-18 02:04:36 +00:00
|
|
|
// Create storage for the field.
|
2010-09-13 05:50:09 +00:00
|
|
|
field_sql_storage_field_storage_create_field($field);
|
|
|
|
}
|
|
|
|
|
2010-09-28 02:58:13 +00:00
|
|
|
/**
|
2010-09-29 19:46:40 +00:00
|
|
|
* Utility function: delete a field stored in SQL storage directly from the database.
|
2010-09-28 02:58:13 +00:00
|
|
|
*
|
|
|
|
* To protect user data, this function can only be used to delete fields once
|
|
|
|
* all information it stored is gone. Delete all data from the
|
|
|
|
* field_data_$field_name table before calling by either manually issuing
|
|
|
|
* delete queries against it or using _update_7000_field_delete_instance().
|
|
|
|
*
|
2010-09-29 19:46:40 +00:00
|
|
|
* This function can be used for databases whose schema is at field module
|
|
|
|
* version 7000 or higher.
|
2010-09-28 02:58:13 +00:00
|
|
|
*
|
|
|
|
* @param $field_name
|
|
|
|
* The field name to delete.
|
|
|
|
*
|
|
|
|
* @ingroup update-api-6.x-to-7.x
|
|
|
|
*/
|
|
|
|
function _update_7000_field_delete_field($field_name) {
|
|
|
|
$table_name = 'field_data_' . $field_name;
|
|
|
|
if (db_select($table_name)->range(0, 1)->countQuery()->execute()->fetchField()) {
|
|
|
|
$t = get_t();
|
|
|
|
throw new Exception($t('This function can only be used to delete fields without data'));
|
|
|
|
}
|
|
|
|
// Delete all instances.
|
|
|
|
db_delete('field_config_instance')
|
|
|
|
->condition('field_name', $field_name)
|
|
|
|
->execute();
|
|
|
|
|
|
|
|
// Nuke field data and revision tables.
|
|
|
|
db_drop_table($table_name);
|
|
|
|
db_drop_table('field_revision_' . $field_name);
|
|
|
|
|
|
|
|
// Delete the field.
|
|
|
|
db_delete('field_config')
|
|
|
|
->condition('field_name', $field_name)
|
|
|
|
->execute();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Utility function: delete an instance and all its data of a field stored in SQL Storage.
|
|
|
|
*
|
|
|
|
* BEWARE: this function deletes user data from the field storage tables.
|
|
|
|
*
|
|
|
|
* This function is valid for a database schema version 7000.
|
|
|
|
*
|
|
|
|
* @ingroup update-api-6.x-to-7.x
|
|
|
|
*/
|
|
|
|
function _update_7000_field_delete_instance($field_name, $entity_type, $bundle) {
|
|
|
|
// Delete field instance configuration data.
|
|
|
|
db_delete('field_config_instance')
|
|
|
|
->condition('field_name', $field_name)
|
|
|
|
->condition('entity_type', $entity_type)
|
|
|
|
->condition('bundle', $bundle)
|
|
|
|
->execute();
|
|
|
|
|
|
|
|
// Nuke data.
|
|
|
|
db_delete('field_data_' . $field_name)
|
2010-12-14 19:50:05 +00:00
|
|
|
->condition('entity_type', $entity_type)
|
2010-09-28 02:58:13 +00:00
|
|
|
->condition('bundle', $bundle)
|
|
|
|
->execute();
|
|
|
|
db_delete('field_revision_' . $field_name)
|
2010-12-14 19:50:05 +00:00
|
|
|
->condition('entity_type', $entity_type)
|
2010-09-28 02:58:13 +00:00
|
|
|
->condition('bundle', $bundle)
|
|
|
|
->execute();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Utility function: fetch all the field definitions from the database.
|
2010-10-20 01:15:58 +00:00
|
|
|
*
|
2011-03-10 07:40:12 +00:00
|
|
|
* Warning: unlike the field_read_fields() API function, this function returns
|
|
|
|
* all fields by default, including deleted and inactive fields, unless
|
|
|
|
* specified otherwise in the $conditions parameter.
|
|
|
|
*
|
2010-10-20 01:15:58 +00:00
|
|
|
* @param $conditions
|
|
|
|
* An array of conditions to limit the select query to.
|
2011-03-10 07:40:12 +00:00
|
|
|
* @param $key
|
|
|
|
* The name of the field property the return array is indexed by. Using
|
|
|
|
* anything else than 'id' might cause incomplete results if the $conditions
|
|
|
|
* do not filter out deleted fields.
|
|
|
|
*
|
|
|
|
* @return
|
|
|
|
* An array of fields matching $conditions, keyed by the property specified
|
|
|
|
* by the $key parameter.
|
2010-09-28 02:58:13 +00:00
|
|
|
*/
|
2011-03-10 07:40:12 +00:00
|
|
|
function _update_7000_field_read_fields(array $conditions = array(), $key = 'id') {
|
2010-09-28 02:58:13 +00:00
|
|
|
$fields = array();
|
2010-10-20 01:15:58 +00:00
|
|
|
$query = db_select('field_config', 'fc', array('fetch' => PDO::FETCH_ASSOC))
|
2011-03-10 07:40:12 +00:00
|
|
|
->fields('fc');
|
|
|
|
foreach ($conditions as $column => $value) {
|
|
|
|
$query->condition($column, $value);
|
2010-10-20 01:15:58 +00:00
|
|
|
}
|
|
|
|
foreach ($query->execute() as $record) {
|
2010-09-28 02:58:13 +00:00
|
|
|
$field = unserialize($record['data']);
|
|
|
|
$field['id'] = $record['id'];
|
|
|
|
$field['field_name'] = $record['field_name'];
|
|
|
|
$field['type'] = $record['type'];
|
|
|
|
$field['module'] = $record['module'];
|
|
|
|
$field['active'] = $record['active'];
|
|
|
|
$field['storage']['type'] = $record['storage_type'];
|
|
|
|
$field['storage']['module'] = $record['storage_module'];
|
|
|
|
$field['storage']['active'] = $record['storage_active'];
|
|
|
|
$field['locked'] = $record['locked'];
|
|
|
|
$field['cardinality'] = $record['cardinality'];
|
|
|
|
$field['translatable'] = $record['translatable'];
|
|
|
|
$field['deleted'] = $record['deleted'];
|
|
|
|
|
2011-03-10 07:40:12 +00:00
|
|
|
$fields[$field[$key]] = $field;
|
2010-09-28 02:58:13 +00:00
|
|
|
}
|
|
|
|
return $fields;
|
|
|
|
}
|
|
|
|
|
2010-09-13 05:50:09 +00:00
|
|
|
/**
|
2010-09-29 19:46:40 +00:00
|
|
|
* Utility function: write a field instance directly to the database.
|
2010-09-13 05:50:09 +00:00
|
|
|
*
|
2010-09-29 19:46:40 +00:00
|
|
|
* This function can be used for databases whose schema is at field module
|
|
|
|
* version 7000 or higher.
|
2010-09-13 05:50:09 +00:00
|
|
|
*
|
|
|
|
* @ingroup update-api-6.x-to-7.x
|
|
|
|
*/
|
|
|
|
function _update_7000_field_create_instance($field, &$instance) {
|
|
|
|
// Merge in defaults.
|
|
|
|
$instance += array(
|
|
|
|
'field_id' => $field['id'],
|
|
|
|
'field_name' => $field['field_name'],
|
|
|
|
'deleted' => 0,
|
|
|
|
);
|
|
|
|
|
|
|
|
// The serialized 'data' column contains everything from $instance that does
|
|
|
|
// not have its own column and is not automatically populated when the
|
|
|
|
// instance is read.
|
|
|
|
$data = $instance;
|
|
|
|
unset($data['id'], $data['field_id'], $data['field_name'], $data['entity_type'], $data['bundle'], $data['deleted']);
|
|
|
|
|
|
|
|
$record = array(
|
|
|
|
'field_id' => $instance['field_id'],
|
|
|
|
'field_name' => $instance['field_name'],
|
|
|
|
'entity_type' => $instance['entity_type'],
|
|
|
|
'bundle' => $instance['bundle'],
|
|
|
|
'data' => serialize($data),
|
|
|
|
'deleted' => (int) $instance['deleted'],
|
|
|
|
);
|
|
|
|
$instance['id'] = db_insert('field_config_instance')
|
|
|
|
->fields($record)
|
|
|
|
->execute();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2011-01-02 17:26:40 +00:00
|
|
|
* @addtogroup updates-6.x-to-7.x
|
2010-09-13 05:50:09 +00:00
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Field update version placeholder.
|
|
|
|
*/
|
|
|
|
function field_update_7000() {
|
2010-09-29 19:46:40 +00:00
|
|
|
// Some update helper functions (such as _update_7000_field_create_field())
|
|
|
|
// modify the database directly. They can be used safely only if the database
|
|
|
|
// schema matches the field module schema established for Drupal 7.0 (i.e.
|
|
|
|
// version 7000). This function exists solely to set the schema version to
|
|
|
|
// 7000, so that update functions calling those helpers can do so safely
|
|
|
|
// by declaring a dependency on field_update_7000().
|
2010-09-13 05:50:09 +00:00
|
|
|
}
|
|
|
|
|
2010-12-18 02:04:36 +00:00
|
|
|
/**
|
2010-12-21 21:01:49 +00:00
|
|
|
* Fix fields definitions created during the d6 to d7 upgrade path.
|
2010-12-18 02:04:36 +00:00
|
|
|
*/
|
|
|
|
function field_update_7001() {
|
|
|
|
$fields = _update_7000_field_read_fields();
|
|
|
|
foreach ($fields as $field) {
|
|
|
|
// _update_7000_field_create_field() was broken in d7 RC2, and the fields
|
|
|
|
// created during a d6 to d7 upgrade do not correcly store the 'index'
|
|
|
|
// entry. See http://drupal.org/node/996160.
|
|
|
|
|
|
|
|
module_load_install($field['module']);
|
|
|
|
$schema = (array) module_invoke($field['module'], 'field_schema', $field);
|
|
|
|
$schema += array('indexes' => array());
|
|
|
|
// 'indexes' can be both hardcoded in the field type, and specified in the
|
|
|
|
// incoming $field definition.
|
|
|
|
$field['indexes'] += $schema['indexes'];
|
|
|
|
|
|
|
|
// Place the updated entries in the existing serialized 'data' column.
|
|
|
|
$data = db_query("SELECT data FROM {field_config} WHERE id = :id", array(':id' => $field['id']))->fetchField();
|
|
|
|
$data = unserialize($data);
|
|
|
|
$data['columns'] = $field['columns'];
|
|
|
|
$data['indexes'] = $field['indexes'];
|
|
|
|
|
|
|
|
// Save the new data.
|
|
|
|
$query = db_update('field_config')
|
|
|
|
->condition('id', $field['id'])
|
|
|
|
->fields(array('data' => serialize($data)))
|
|
|
|
->execute();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-09-13 05:50:09 +00:00
|
|
|
/**
|
2012-05-23 19:25:30 +00:00
|
|
|
* @} End of "addtogroup updates-6.x-to-7.x".
|
2010-09-13 05:50:09 +00:00
|
|
|
*/
|
2012-04-12 07:50:52 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @addtogroup updates-7.x-extra
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Split the all-inclusive field_bundle_settings variable per bundle.
|
|
|
|
*/
|
|
|
|
function field_update_7002() {
|
|
|
|
$settings = variable_get('field_bundle_settings', array());
|
|
|
|
if ($settings) {
|
|
|
|
foreach ($settings as $entity_type => $entity_type_settings) {
|
|
|
|
foreach ($entity_type_settings as $bundle => $bundle_settings) {
|
|
|
|
variable_set('field_bundle_settings_' . $entity_type . '__' . $bundle, $bundle_settings);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
variable_del('field_bundle_settings');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2012-05-23 19:25:30 +00:00
|
|
|
* @} End of "addtogroup updates-7.x-extra".
|
2012-04-12 07:50:52 +00:00
|
|
|
*/
|