Created
December 24, 2015 16:05
-
-
Save mvc1095/e0653b7d1c1156999371 to your computer and use it in GitHub Desktop.
Drupal 7: Update existing field_config.data
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// remove field settings for entity_translation & i18n_taxonomy after these | |
// modules are disabled. can be run via drush scr or hook_update_N(). | |
// features can't remove existing field settings, or add or change them, so this has to be done manually | |
// https://www.drupal.org/node/1999652 | |
// https://www.drupal.org/node/937554 | |
$query = db_select('field_config', 'fc') | |
->fields('fc', array('id', 'field_name', 'data')) | |
->orderBy('fc.id'); | |
$db_or = db_or(); | |
$db_or->condition('data', '%' . db_like('entity_translation_sync') . '%', 'LIKE'); | |
$db_or->condition('data', '%' . db_like('i18n_taxonomy_allowed_values') . '%', 'LIKE'); | |
$query->condition($db_or); | |
$result = $query->execute(); | |
$fixed_configs = array(); | |
foreach ($result as $record) { | |
$data = unserialize($record->data); | |
if (isset($data['settings']['entity_translation_sync'])) { | |
unset($data['settings']['entity_translation_sync']); | |
} | |
if (isset($data['settings']['options_list_callback']) && $data['settings']['options_list_callback'] == 'i18n_taxonomy_allowed_values') { | |
unset($data['settings']['options_list_callback']); | |
} | |
$fixed_configs[$record->id] = serialize($data); | |
} | |
$i = 0; | |
foreach ($fixed_configs as $id => $data) { | |
db_update('field_config') | |
->condition('id', $id) | |
->fields(array('data' => $data)) | |
->execute(); | |
$i++; | |
} | |
// clear cache to make these changes take effect | |
db_delete('cache_field')->execute(); | |
print "$i fields were fixed\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment