Commit fc7c985b authored by Dries's avatar Dries

- Patch #1264728 by yched: Refresh field 'active' state in module_enable() / _disable().

parent e341d8ec
...@@ -103,10 +103,9 @@ function field_schema() { ...@@ -103,10 +103,9 @@ function field_schema() {
'active' => array('active'), 'active' => array('active'),
'storage_active' => array('storage_active'), 'storage_active' => array('storage_active'),
'deleted' => array('deleted'), 'deleted' => array('deleted'),
// Used by field_modules_disabled(). // Used by field_sync_field_status().
'module' => array('module'), 'module' => array('module'),
'storage_module' => array('storage_module'), 'storage_module' => array('storage_module'),
// Used by field_associate_fields().
'type' => array('type'), 'type' => array('type'),
'storage_type' => array('storage_type'), 'storage_type' => array('storage_type'),
), ),
......
...@@ -362,11 +362,12 @@ function field_theme() { ...@@ -362,11 +362,12 @@ function field_theme() {
/** /**
* Implements hook_cron(). * Implements hook_cron().
*
* Purges some deleted Field API data, if any exists.
*/ */
function field_cron() { function field_cron() {
// Refresh the 'active' status of fields.
field_sync_field_status(); field_sync_field_status();
// Do a pass of purging on deleted Field API data, if any exists.
$limit = variable_get('field_purge_batch_size', 10); $limit = variable_get('field_purge_batch_size', 10);
field_purge_batch($limit); field_purge_batch($limit);
} }
...@@ -412,10 +413,29 @@ function field_system_info_alter(&$info, $file, $type) { ...@@ -412,10 +413,29 @@ function field_system_info_alter(&$info, $file, $type) {
* Implements hook_flush_caches(). * Implements hook_flush_caches().
*/ */
function field_flush_caches() { function field_flush_caches() {
// Refresh the 'active' status of fields.
field_sync_field_status(); field_sync_field_status();
// Request a flush of our cache table.
return array('field'); return array('field');
} }
/**
* Implements hook_modules_enabled().
*/
function field_modules_enabled($modules) {
// Refresh the 'active' status of fields.
field_sync_field_status();
}
/**
* Implements hook_modules_disabled().
*/
function field_modules_disabled($modules) {
// Refresh the 'active' status of fields.
field_sync_field_status();
}
/** /**
* Refreshes the 'active' and 'storage_active' columns for fields. * Refreshes the 'active' and 'storage_active' columns for fields.
*/ */
...@@ -449,18 +469,18 @@ function field_sync_field_status() { ...@@ -449,18 +469,18 @@ function field_sync_field_status() {
function field_associate_fields($module) { function field_associate_fields($module) {
// Associate field types. // Associate field types.
$field_types = (array) module_invoke($module, 'field_info'); $field_types = (array) module_invoke($module, 'field_info');
foreach ($field_types as $name => $field_info) { if ($field_types) {
db_update('field_config') db_update('field_config')
->fields(array('module' => $module, 'active' => 1)) ->fields(array('module' => $module, 'active' => 1))
->condition('type', $name) ->condition('type', array_keys($field_types))
->execute(); ->execute();
} }
// Associate storage backends. // Associate storage backends.
$storage_types = (array) module_invoke($module, 'field_storage_info'); $storage_types = (array) module_invoke($module, 'field_storage_info');
foreach ($storage_types as $name => $storage_info) { if ($storage_types) {
db_update('field_config') db_update('field_config')
->fields(array('storage_module' => $module, 'storage_active' => 1)) ->fields(array('storage_module' => $module, 'storage_active' => 1))
->condition('storage_type', $name) ->condition('storage_type', array_keys($storage_types))
->execute(); ->execute();
} }
} }
......
...@@ -2357,7 +2357,6 @@ class FieldCrudTestCase extends FieldTestCase { ...@@ -2357,7 +2357,6 @@ class FieldCrudTestCase extends FieldTestCase {
$this->assertTrue($field_definition <= $field, t('The field was properly read.')); $this->assertTrue($field_definition <= $field, t('The field was properly read.'));
module_disable($modules, FALSE); module_disable($modules, FALSE);
drupal_flush_all_caches();
$fields = field_read_fields(array('field_name' => $field_name), array('include_inactive' => TRUE)); $fields = field_read_fields(array('field_name' => $field_name), array('include_inactive' => TRUE));
$this->assertTrue(isset($fields[$field_name]) && $field_definition < $field, t('The field is properly read when explicitly fetching inactive fields.')); $this->assertTrue(isset($fields[$field_name]) && $field_definition < $field, t('The field is properly read when explicitly fetching inactive fields.'));
...@@ -2370,7 +2369,6 @@ class FieldCrudTestCase extends FieldTestCase { ...@@ -2370,7 +2369,6 @@ class FieldCrudTestCase extends FieldTestCase {
$module = array_shift($modules); $module = array_shift($modules);
module_enable(array($module), FALSE); module_enable(array($module), FALSE);
drupal_flush_all_caches();
} }
// Check that the field is active again after all modules have been // Check that the field is active again after all modules have been
......
...@@ -375,7 +375,6 @@ class TaxonomyVocabularyUnitTest extends TaxonomyWebTestCase { ...@@ -375,7 +375,6 @@ class TaxonomyVocabularyUnitTest extends TaxonomyWebTestCase {
field_create_instance($this->instance); field_create_instance($this->instance);
module_disable(array('taxonomy')); module_disable(array('taxonomy'));
drupal_flush_all_caches();
require_once DRUPAL_ROOT . '/core/includes/install.inc'; require_once DRUPAL_ROOT . '/core/includes/install.inc';
drupal_uninstall_modules(array('taxonomy')); drupal_uninstall_modules(array('taxonomy'));
module_enable(array('taxonomy')); module_enable(array('taxonomy'));
......
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