Commit 34c6cdd6 authored by webchick's avatar webchick

Issue #1022924 by yched, chx: Fixed critical bug: Updates are broken for...

Issue #1022924 by yched, chx: Fixed critical bug: Updates are broken for deleted fields in installs upgraded from rc1.
parent 6dabf4fc
...@@ -309,18 +309,27 @@ function _update_7000_field_delete_instance($field_name, $entity_type, $bundle) ...@@ -309,18 +309,27 @@ function _update_7000_field_delete_instance($field_name, $entity_type, $bundle)
/** /**
* Utility function: fetch all the field definitions from the database. * Utility function: fetch all the field definitions from the database.
* *
* 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.
*
* @param $conditions * @param $conditions
* An array of conditions to limit the select query to. * An array of conditions to limit the select query to.
* @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.
*/ */
function _update_7000_field_read_fields(array $conditions = array()) { function _update_7000_field_read_fields(array $conditions = array(), $key = 'id') {
$fields = array(); $fields = array();
$query = db_select('field_config', 'fc', array('fetch' => PDO::FETCH_ASSOC)) $query = db_select('field_config', 'fc', array('fetch' => PDO::FETCH_ASSOC))
->fields('fc') ->fields('fc');
->condition('deleted', 0); foreach ($conditions as $column => $value) {
if (!empty($conditions)) { $query->condition($column, $value);
foreach ($conditions as $column => $value) {
$query->condition($column, $value);
}
} }
foreach ($query->execute() as $record) { foreach ($query->execute() as $record) {
$field = unserialize($record['data']); $field = unserialize($record['data']);
...@@ -337,7 +346,7 @@ function _update_7000_field_read_fields(array $conditions = array()) { ...@@ -337,7 +346,7 @@ function _update_7000_field_read_fields(array $conditions = array()) {
$field['translatable'] = $record['translatable']; $field['translatable'] = $record['translatable'];
$field['deleted'] = $record['deleted']; $field['deleted'] = $record['deleted'];
$fields[$field['field_name']] = $field; $fields[$field[$key]] = $field;
} }
return $fields; return $fields;
} }
......
...@@ -50,7 +50,7 @@ function list_field_schema($field) { ...@@ -50,7 +50,7 @@ function list_field_schema($field) {
*/ */
function list_update_7001() { function list_update_7001() {
$fields = _update_7000_field_read_fields(array('module' => 'list')); $fields = _update_7000_field_read_fields(array('module' => 'list'));
foreach ($fields as $field_name => $field) { foreach ($fields as $field) {
$update = array(); $update = array();
// Translate the old string format into the new array format. // Translate the old string format into the new array format.
...@@ -115,3 +115,15 @@ function _list_update_7001_extract_allowed_values($string, $position_keys) { ...@@ -115,3 +115,15 @@ function _list_update_7001_extract_allowed_values($string, $position_keys) {
return $values; return $values;
} }
/**
* Re-apply list_update_7001() for deleted fields.
*/
function list_update_7002() {
// See http://drupal.org/node/1022924: list_update_7001() intitally
// overlooked deleted fields, which then caused fatal errors when the fields
// were being purged.
// list_update_7001() has the required checks to ensure it is reentrant, so
// it can simply be executed once more..
list_update_7001();
}
\ No newline at end of file
...@@ -92,7 +92,7 @@ function text_update_7000() { ...@@ -92,7 +92,7 @@ function text_update_7000() {
'module' => 'text', 'module' => 'text',
'storage_type' => 'field_sql_storage', 'storage_type' => 'field_sql_storage',
)); ));
foreach ($fields as $field_name => $field) { foreach ($fields as $field) {
if ($field['deleted']) { if ($field['deleted']) {
$table = "field_deleted_data_{$field['id']}"; $table = "field_deleted_data_{$field['id']}";
$revision_table = "field_deleted_revision_{$field['id']}"; $revision_table = "field_deleted_revision_{$field['id']}";
......
...@@ -566,8 +566,12 @@ function taxonomy_update_7005(&$sandbox) { ...@@ -566,8 +566,12 @@ function taxonomy_update_7005(&$sandbox) {
// of term references stored so far for the current revision, which // of term references stored so far for the current revision, which
// provides the delta value for each term reference data insert. The // provides the delta value for each term reference data insert. The
// deltas are reset for each new revision. // deltas are reset for each new revision.
$field_info = _update_7000_field_read_fields(); $conditions = array(
'type' => 'taxonomy_term_reference',
'deleted' => 0,
);
$field_info = _update_7000_field_read_fields($conditions, 'field_name');
// This is a multi-pass update. On the first call we need to initialize some // This is a multi-pass update. On the first call we need to initialize some
// variables. // variables.
......
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