123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472 |
- <?php
- function field_schema() {
-
- $schema['field_config'] = array(
- 'fields' => array(
- 'id' => array(
- 'type' => 'serial',
- 'not null' => TRUE,
- 'description' => 'The primary identifier for a field',
- ),
- 'field_name' => array(
- 'type' => 'varchar',
- 'length' => 32,
- 'not null' => TRUE,
- 'description' => 'The name of this field. Non-deleted field names are unique, but multiple deleted fields can have the same name.',
- ),
- 'type' => array(
- 'type' => 'varchar',
- 'length' => 128,
- 'not null' => TRUE,
- 'description' => 'The type of this field.',
- ),
- 'module' => array(
- 'type' => 'varchar',
- 'length' => 128,
- 'not null' => TRUE,
- 'default' => '',
- 'description' => 'The module that implements the field type.',
- ),
- 'active' => array(
- 'type' => 'int',
- 'size' => 'tiny',
- 'not null' => TRUE,
- 'default' => 0,
- 'description' => 'Boolean indicating whether the module that implements the field type is enabled.',
- ),
- 'storage_type' => array(
- 'type' => 'varchar',
- 'length' => 128,
- 'not null' => TRUE,
- 'description' => 'The storage backend for the field.',
- ),
- 'storage_module' => array(
- 'type' => 'varchar',
- 'length' => 128,
- 'not null' => TRUE,
- 'default' => '',
- 'description' => 'The module that implements the storage backend.',
- ),
- 'storage_active' => array(
- 'type' => 'int',
- 'size' => 'tiny',
- 'not null' => TRUE,
- 'default' => 0,
- 'description' => 'Boolean indicating whether the module that implements the storage backend is enabled.',
- ),
- 'locked' => array(
- 'type' => 'int',
- 'size' => 'tiny',
- 'not null' => TRUE,
- 'default' => 0,
- 'description' => '@TODO',
- ),
- 'data' => array(
- 'type' => 'blob',
- 'size' => 'big',
- '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(
- 'type' => 'int',
- 'size' => 'tiny',
- 'not null' => TRUE,
- 'default' => 0,
- ),
- 'deleted' => array(
- 'type' => 'int',
- 'size' => 'tiny',
- 'not null' => TRUE,
- 'default' => 0,
- ),
- ),
- 'primary key' => array('id'),
- 'indexes' => array(
- 'field_name' => array('field_name'),
-
- 'active' => array('active'),
- 'storage_active' => array('storage_active'),
- 'deleted' => array('deleted'),
-
- 'module' => array('module'),
- 'storage_module' => array('storage_module'),
- 'type' => array('type'),
- 'storage_type' => array('storage_type'),
- ),
- );
- $schema['field_config_instance'] = array(
- 'fields' => array(
- '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',
- ),
- 'field_name' => array(
- 'type' => 'varchar',
- 'length' => 32,
- 'not null' => TRUE,
- 'default' => ''
- ),
- 'entity_type' => array(
- 'type' => 'varchar',
- 'length' => 32,
- 'not null' => TRUE,
- 'default' => ''
- ),
- 'bundle' => array(
- 'type' => 'varchar',
- 'length' => 128,
- 'not null' => TRUE,
- 'default' => ''
- ),
- 'data' => array(
- 'type' => 'blob',
- 'size' => 'big',
- 'not null' => TRUE,
- 'serialize' => TRUE,
- ),
- 'deleted' => array(
- 'type' => 'int',
- 'size' => 'tiny',
- 'not null' => TRUE,
- 'default' => 0,
- ),
- ),
- 'primary key' => array('id'),
- 'indexes' => array(
-
- 'field_name_bundle' => array('field_name', 'entity_type', 'bundle'),
-
- 'deleted' => array('deleted'),
- ),
- );
- $schema['cache_field'] = drupal_get_schema_unprocessed('system', 'cache');
- $schema['cache_field']['description'] = 'Cache table for the Field module to store already built field information.';
- return $schema;
- }
- function _update_7000_field_create_field(&$field) {
-
- $field += array(
- 'entity_types' => array(),
- 'cardinality' => 1,
- 'translatable' => FALSE,
- 'locked' => FALSE,
- 'settings' => array(),
- 'indexes' => array(),
- 'deleted' => 0,
- 'active' => 1,
- );
-
- $field['storage'] = array(
- 'type' => 'field_sql_storage',
- 'settings' => array(),
- 'module' => 'field_sql_storage',
- 'active' => 1,
- );
-
-
- module_load_install($field['module']);
- $schema = (array) module_invoke($field['module'], 'field_schema', $field);
- $schema += array('columns' => array(), 'indexes' => array());
-
- $field['columns'] = $schema['columns'];
-
-
- $field['indexes'] += $schema['indexes'];
-
-
-
- $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']);
-
-
- unset($data['bundles']);
-
- $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'],
- );
-
- $field['id'] = db_insert('field_config')
- ->fields($record)
- ->execute();
-
- field_sql_storage_field_storage_create_field($field);
- }
- 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'));
- }
-
- db_delete('field_config_instance')
- ->condition('field_name', $field_name)
- ->execute();
-
- db_drop_table($table_name);
- db_drop_table('field_revision_' . $field_name);
-
- db_delete('field_config')
- ->condition('field_name', $field_name)
- ->execute();
- }
- function _update_7000_field_delete_instance($field_name, $entity_type, $bundle) {
-
- db_delete('field_config_instance')
- ->condition('field_name', $field_name)
- ->condition('entity_type', $entity_type)
- ->condition('bundle', $bundle)
- ->execute();
-
- db_delete('field_data_' . $field_name)
- ->condition('entity_type', $entity_type)
- ->condition('bundle', $bundle)
- ->execute();
- db_delete('field_revision_' . $field_name)
- ->condition('entity_type', $entity_type)
- ->condition('bundle', $bundle)
- ->execute();
- }
- function _update_7000_field_read_fields(array $conditions = array(), $key = 'id') {
- $fields = array();
- $query = db_select('field_config', 'fc', array('fetch' => PDO::FETCH_ASSOC))
- ->fields('fc');
- foreach ($conditions as $column => $value) {
- $query->condition($column, $value);
- }
- foreach ($query->execute() as $record) {
- $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'];
- $fields[$field[$key]] = $field;
- }
- return $fields;
- }
- function _update_7000_field_create_instance($field, &$instance) {
-
- $instance += array(
- 'field_id' => $field['id'],
- 'field_name' => $field['field_name'],
- 'deleted' => 0,
- );
-
-
-
- $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();
- }
- function field_update_7000() {
-
-
-
-
-
-
- }
- function field_update_7001() {
- $fields = _update_7000_field_read_fields();
- foreach ($fields as $field) {
-
-
-
- module_load_install($field['module']);
- $schema = (array) module_invoke($field['module'], 'field_schema', $field);
- $schema += array('indexes' => array());
-
-
- $field['indexes'] += $schema['indexes'];
-
- $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'];
-
- $query = db_update('field_config')
- ->condition('id', $field['id'])
- ->fields(array('data' => serialize($data)))
- ->execute();
- }
- }
- 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');
- }
- }
- function field_update_7003() {
-
- }
|