123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330 |
- <?php
- function field_collection_schema() {
- $schema['field_collection_item'] = array(
- 'description' => 'Stores information about field collection items.',
- 'fields' => array(
- 'item_id' => array(
- 'type' => 'serial',
- 'not null' => TRUE,
- 'description' => 'Primary Key: Unique field collection item ID.',
- ),
- 'revision_id' => array(
- 'type' => 'int',
- 'not null' => TRUE,
- 'description' => 'Default revision ID.',
- ),
- 'field_name' => array(
- 'description' => 'The name of the field on the host entity embedding this entity.',
- 'type' => 'varchar',
- 'length' => 32,
- 'not null' => TRUE,
- ),
- 'archived' => array(
- 'description' => 'Boolean indicating whether the field collection item is archived.',
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- ),
- ),
- 'primary key' => array('item_id'),
- );
- $schema['field_collection_item_revision'] = array(
- 'description' => 'Stores revision information about field collection items.',
- 'fields' => array(
- 'revision_id' => array(
- 'type' => 'serial',
- 'not null' => TRUE,
- 'description' => 'Primary Key: Unique revision ID.',
- ),
- 'item_id' => array(
- 'type' => 'int',
- 'not null' => TRUE,
- 'description' => 'Field collection item ID.',
- ),
- ),
- 'primary key' => array('revision_id'),
- 'indexes' => array(
- 'item_id' => array('item_id'),
- ),
- 'foreign keys' => array(
- 'versioned_field_collection_item' => array(
- 'table' => 'field_collection_item',
- 'columns' => array('item_id' => 'item_id'),
- ),
- ),
- );
- return $schema;
- }
- function field_collection_field_schema($field) {
- $columns = array(
- 'value' => array(
- 'type' => 'int',
- 'not null' => FALSE,
- 'description' => 'The field collection item id.',
- ),
- 'revision_id' => array(
- 'type' => 'int',
- 'not null' => FALSE,
- 'description' => 'The field collection item revision id.',
- ),
- );
- return array(
- 'columns' => $columns,
- 'indexes' => array(
- 'revision_id' => array('revision_id'),
- ),
- );
- }
- function field_collection_update_7000() {
- db_update('role_permission')
- ->fields(array('permission' => 'administer field collections'))
- ->condition('permission', 'administer field-collections')
- ->execute();
- }
- function field_collection_update_7001() {
-
- $revision_id_spec = array(
- 'type' => 'int',
- 'not null' => TRUE,
- 'description' => 'Default revision ID.',
-
- 'initial' => 0,
- );
-
- if (!db_field_exists('field_collection_item', 'revision_id')) {
- db_add_field('field_collection_item', 'revision_id', $revision_id_spec);
- }
-
- db_update('field_collection_item')
- ->expression('revision_id', 'item_id')
- ->execute();
-
- $archived_spec = array(
- 'description' => 'Boolean indicating whether the field collection item is archived.',
- 'type' => 'int',
- 'not null' => TRUE,
- 'default' => 0,
- );
-
- if (!db_field_exists('field_collection_item', 'archived')) {
- db_add_field('field_collection_item', 'archived', $archived_spec);
- }
-
-
- $schema['field_collection_item_revision'] = array(
- 'description' => 'Stores revision information about field collection items.',
- 'fields' => array(
- 'revision_id' => array(
- 'type' => 'serial',
- 'not null' => TRUE,
- 'description' => 'Primary Key: Unique revision ID.',
- ),
- 'item_id' => array(
- 'type' => 'int',
- 'not null' => TRUE,
- 'description' => 'Field collection item ID.',
- ),
- ),
- 'primary key' => array('revision_id'),
- 'indexes' => array(
- 'item_id' => array('item_id'),
- ),
- 'foreign keys' => array(
- 'versioned_field_collection_item' => array(
- 'table' => 'field_collection_item',
- 'columns' => array('item_id' => 'item_id'),
- ),
- ),
- );
-
- if (db_table_exists('field_collection_item_revision')) {
- db_drop_table('field_collection_item_revision');
- }
- db_create_table('field_collection_item_revision', $schema['field_collection_item_revision']);
-
- $items = db_select('field_collection_item', 'fci')
- ->fields('fci')
- ->execute();
- foreach ($items as $item) {
-
- db_insert('field_collection_item_revision')
- ->fields(array(
- 'revision_id' => $item->item_id,
- 'item_id' => $item->item_id,
- ))
- ->execute();
- }
-
-
- $revision_id_spec['description'] = 'The field collection item revision id.';
-
- $revision_id_spec['not null'] = FALSE;
- foreach (field_read_fields(array('type' => 'field_collection')) as $field_name => $field) {
- $table_prefixes = array('field_data', 'field_revision');
- foreach ($table_prefixes as $table_prefix) {
- $table = sprintf('%s_%s', $table_prefix, $field_name);
- $value_column = sprintf('%s_value', $field_name);
- $revision_id_column = sprintf('%s_revision_id', $field_name);
-
- if (!db_field_exists($table, $revision_id_column)) {
- db_add_field($table, $revision_id_column, $revision_id_spec);
- }
- else {
- db_change_field($table, $revision_id_column, $revision_id_column, $revision_id_spec);
- }
-
- db_update($table)
- ->expression($revision_id_column, $value_column)
- ->execute();
- }
- }
-
- $schema = drupal_get_schema('field_collection_item_revision', TRUE);
- }
- function field_collection_update_7002() {
-
- foreach (field_read_fields(array('type' => 'field_collection')) as $field_name => $field) {
- $select = db_select('field_collection_item', 'fci')
- ->fields('fci', array('item_id'))
- ->condition('field_name', $field_name)
- ->condition('archived', 0);
- $select->leftJoin('field_data_' . $field_name, 'field', "field.{$field_name}_value = fci.item_id ");
- $select->isNull('field.entity_id');
- $ids = $select->execute()->fetchCol(0);
- entity_delete_multiple('field_collection_item', $ids);
- drupal_set_message(t('Deleted @count orphaned field collection items.', array('@count' => count($ids))));
- }
- }
- function field_collection_update_7003() {
-
- $revision_id_spec = array(
- 'type' => 'int',
- 'not null' => FALSE,
- 'description' => 'The field collection item revision id.',
- 'initial' => 0,
- );
-
-
-
- foreach (field_read_fields(array('type' => 'field_collection')) as $field_name => $field) {
- $table_prefixes = array('field_data', 'field_revision');
- foreach ($table_prefixes as $table_prefix) {
- $table = sprintf('%s_%s', $table_prefix, $field_name);
- $value_column = sprintf('%s_value', $field_name);
- $revision_id_column = sprintf('%s_revision_id', $field_name);
- db_change_field($table, $revision_id_column, $revision_id_column, $revision_id_spec);
- }
- }
-
- $schema = drupal_get_schema('field_collection_item_revision', TRUE);
- }
- function field_collection_update_7004() {
-
- foreach (field_read_fields(array('type' => 'field_collection')) as $field_name => $field) {
- $table_prefixes = array('field_data', 'field_revision');
- foreach ($table_prefixes as $table_prefix) {
- $table = sprintf('%s_%s', $table_prefix, $field_name);
- $revision_id_column = sprintf('%s_revision_id', $field_name);
-
- if (!db_index_exists($table, $revision_id_column)) {
- db_add_index($table, $revision_id_column, array($revision_id_column));
- }
- }
- }
- }
- function field_collection_update_7005() {
- if (module_exists('entitycache')) {
- $entity_type = 'field_collection_item';
- $table = 'cache_entity_' . $entity_type;
- if (!db_table_exists($table)) {
- $schema = drupal_get_schema_unprocessed('system', 'cache');
- $schema['description'] = 'Cache table used to store' . $entity_type . ' entity records.';
- db_create_table($table, $schema);
- }
- }
- }
- function field_collection_update_7006() {
- $result = db_query("SELECT id, field_name, data FROM {field_config} WHERE type = 'field_collection'");
- foreach ($result as $field_config) {
- $data = unserialize($field_config->data);
-
- if (isset($data['indexes']['revision_id'])) {
- continue;
- }
-
- $data['indexes']['revision_id'] = array('revision_id');
- $data = serialize($data);
- $num_updated = db_update('field_config')
- ->fields(array('data' => $data))
- ->condition('id', $field_config->id)
- ->execute();
-
- if ($num_updated != 1) {
- $t_args['@field'] = $field_config->field_name;
- throw new DrupalUpdateException(t('An error was detected when attempting to update field configuration for field @field.', $t_args));
- }
- }
- }
|