summaryrefslogtreecommitdiff
path: root/modules
diff options
context:
space:
mode:
authorAngie Byron <webchick@24967.no-reply.drupal.org>2010-12-21 04:11:12 +0000
committerAngie Byron <webchick@24967.no-reply.drupal.org>2010-12-21 04:11:12 +0000
commit2d9916e6f6edda8841cf1251f30761818f799f45 (patch)
tree7cb8c902b1531c480f624bc3a01a94d8095f2961 /modules
parent15ec48062cdd55ae21d04983db210c9a0d2481c2 (diff)
downloadbrdo-2d9916e6f6edda8841cf1251f30761818f799f45.tar.gz
brdo-2d9916e6f6edda8841cf1251f30761818f799f45.tar.bz2
#986992 follow-up by yched, sun: Robustify upgrade path.
Diffstat (limited to 'modules')
-rw-r--r--modules/field/modules/field_sql_storage/field_sql_storage.install53
-rw-r--r--modules/field/modules/field_sql_storage/field_sql_storage.module7
2 files changed, 44 insertions, 16 deletions
diff --git a/modules/field/modules/field_sql_storage/field_sql_storage.install b/modules/field/modules/field_sql_storage/field_sql_storage.install
index efb734fb5..379459dfc 100644
--- a/modules/field/modules/field_sql_storage/field_sql_storage.install
+++ b/modules/field/modules/field_sql_storage/field_sql_storage.install
@@ -113,27 +113,31 @@ function field_sql_storage_update_7001(&$sandbox) {
$sandbox['tables'] = array();
$results = db_select('field_config', 'fc', array('fetch' => PDO::FETCH_ASSOC))
->fields('fc')
+ ->condition('storage_module', 'field_sql_storage')
->execute();
foreach ($results as $field) {
if ($field['deleted']) {
- $sandbox['tables'][] = "field_deleted_data_{$field['id']}";
- $sandbox['tables'][] = "field_deleted_revision_{$field['id']}";
+ $sandbox['tables']["field_deleted_data_{$field['id']}"] = 'data';
+ $sandbox['tables']["field_deleted_revision_{$field['id']}"] = 'revision';
}
else {
- $sandbox['tables'][] = "field_data_{$field['field_name']}";
- $sandbox['tables'][] = "field_revision_{$field['field_name']}";
+ $sandbox['tables']["field_data_{$field['field_name']}"] = 'data';
+ $sandbox['tables']["field_revision_{$field['field_name']}"] = 'revision';
}
}
+ reset($sandbox['tables']);
$sandbox['total'] = count($sandbox['tables']);
$sandbox['progress'] = 0;
}
if ($sandbox['tables']) {
- $table = array_pop($sandbox['tables']);
+ // Grab the next table to process.
+ $table = key($sandbox['tables']);
+ $type = array_shift($sandbox['tables']);
- if (db_table_exists($table)) {
- // Add the 'entity_type' column.
+ // Add the 'entity_type' column.
+ if (!db_field_exists($table, 'entity_type')) {
$column = array(
'type' => 'varchar',
'length' => 128,
@@ -151,12 +155,20 @@ function field_sql_storage_update_7001(&$sandbox) {
->execute();
}
- // Add indexes for the 'entity_type' column.
- db_drop_primary_key($table);
- db_add_primary_key($table, array('entity_type', 'entity_id', 'deleted', 'delta', 'language'));
+ // Index the new column.
db_add_index($table, 'entity_type', array('entity_type'));
+ }
+
+ // Use the 'entity_type' column in the primary key.
+ db_drop_primary_key($table);
+ $primary_keys = array(
+ 'data' => array('entity_type', 'entity_id', 'deleted', 'delta', 'language'),
+ 'revision' => array('entity_type', 'entity_id', 'revision_id', 'deleted', 'delta', 'language'),
+ );
+ db_add_primary_key($table, $primary_keys[$type]);
- // Drop the 'etid' column.
+ // Drop the 'etid' column.
+ if (db_field_exists($table, 'etid')) {
db_drop_field($table, 'etid');
}
@@ -179,5 +191,24 @@ function field_sql_storage_update_7001(&$sandbox) {
}
/**
+ * Fix primary keys in field revision data tables.
+ */
+function field_sql_storage_update_7002() {
+ $results = db_select('field_config', 'fc', array('fetch' => PDO::FETCH_ASSOC))
+ ->fields('fc')
+ ->condition('storage_module', 'field_sql_storage')
+ ->execute();
+ foreach ($results as $field) {
+ // Revision tables of deleted fields do not need to be fixed, since no new
+ // data is written to them.
+ if (!$field['deleted']) {
+ $table = "field_revision_{$field['field_name']}";
+ db_drop_primary_key($table);
+ db_add_primary_key($table, array('entity_type', 'entity_id', 'revision_id', 'deleted', 'delta', 'language'));
+ }
+ }
+}
+
+/**
* @} End of "defgroup field-updates-6.x-to-7.x"
*/
diff --git a/modules/field/modules/field_sql_storage/field_sql_storage.module b/modules/field/modules/field_sql_storage/field_sql_storage.module
index 26f3d8fe4..916649b4e 100644
--- a/modules/field/modules/field_sql_storage/field_sql_storage.module
+++ b/modules/field/modules/field_sql_storage/field_sql_storage.module
@@ -159,7 +159,6 @@ function _field_sql_storage_schema($field) {
'description' => 'The sequence number for this data item, used for multi-value fields',
),
),
- // @todo Is the primary key needed at all ?
'primary key' => array('entity_type', 'entity_id', 'deleted', 'delta', 'language'),
'indexes' => array(
'entity_type' => array('entity_type'),
@@ -196,12 +195,10 @@ function _field_sql_storage_schema($field) {
}
}
- // Construct the revision table. The primary key includes
- // revision_id but not entity_id so that multiple revision loads can
- // use the IN operator.
+ // Construct the revision table.
$revision = $current;
$revision['description'] = "Revision archive storage for {$deleted}field {$field['id']} ({$field['field_name']})";
- $revision['primary key'] = array('entity_type', 'revision_id', 'deleted', 'delta', 'language');
+ $revision['primary key'] = array('entity_type', 'entity_id', 'revision_id', 'deleted', 'delta', 'language');
$revision['fields']['revision_id']['not null'] = TRUE;
$revision['fields']['revision_id']['description'] = 'The entity revision id this data is attached to';