commit 91d9012982981283904515014623e2ca07c47036 Author: Yves Chedemois Date: Wed Jun 25 01:09:51 2014 +0200 field_purge_batch(0) diff --git a/core/modules/comment/src/Tests/CommentFieldsTest.php b/core/modules/comment/src/Tests/CommentFieldsTest.php index 5dd3bb7..5bb4380 100644 --- a/core/modules/comment/src/Tests/CommentFieldsTest.php +++ b/core/modules/comment/src/Tests/CommentFieldsTest.php @@ -85,9 +85,6 @@ function testCommentInstallAfterContentModule() { // Purge field data now to allow comment module to be uninstalled once the // field has been deleted. field_purge_batch(10); - // Call again as field_purge_batch() won't remove both the instances and - // field in a single pass. - field_purge_batch(10); // Disable the comment module. $edit = array(); diff --git a/core/modules/field/field.purge.inc b/core/modules/field/field.purge.inc index 43a529c..4a289cf 100644 --- a/core/modules/field/field.purge.inc +++ b/core/modules/field/field.purge.inc @@ -92,7 +92,7 @@ function field_purge_batch($batch_size, $field_uuid = NULL) { } $count_purged = \Drupal::entityManager()->getStorage($entity_type)->purgeFieldData($instance, $batch_size); - if ($count_purged < $batch_size || $batch_size <= 0) { + if ($count_purged < $batch_size || $count_purged == 0) { // No field data remains for the instance, so we can remove it. field_purge_instance($instance); } diff --git a/core/modules/field/src/ConfigImporterFieldPurger.php b/core/modules/field/src/ConfigImporterFieldPurger.php index a83ff52..a33df39 100644 --- a/core/modules/field/src/ConfigImporterFieldPurger.php +++ b/core/modules/field/src/ConfigImporterFieldPurger.php @@ -85,8 +85,8 @@ protected static function initializeSandbox(array &$context, ConfigImporter $con $context['sandbox']['field']['steps_to_delete'] += $how_many_steps; } } - // Each field needs one last field_purge_batch() call to remove the last - // instance and the field itself. + // Each field possibly needs one last field_purge_batch() call to remove the + // last instance and the field itself. $context['sandbox']['field']['steps_to_delete'] += count($fields); $context['sandbox']['field']['current_progress'] = 0; diff --git a/core/modules/field/src/FieldInstanceConfigStorage.php b/core/modules/field/src/FieldInstanceConfigStorage.php index 1ca7e1c..87bb826 100644 --- a/core/modules/field/src/FieldInstanceConfigStorage.php +++ b/core/modules/field/src/FieldInstanceConfigStorage.php @@ -157,7 +157,10 @@ public function loadByProperties(array $conditions = array()) { } } - $matching_instances[] = $instance; + // When returning deleted instances, key the results by UUID since they + // can include several instances with the same ID. + $key = $include_deleted ? $instance->uuid() : $instance->id(); + $matching_instances[$key] = $instance; } return $matching_instances; diff --git a/core/modules/field/src/Tests/BulkDeleteTest.php b/core/modules/field/src/Tests/BulkDeleteTest.php index 41636e6..0535939 100644 --- a/core/modules/field/src/Tests/BulkDeleteTest.php +++ b/core/modules/field/src/Tests/BulkDeleteTest.php @@ -182,7 +182,7 @@ function testDeleteFieldInstance() { // The instance still exists, deleted. $instances = entity_load_multiple_by_properties('field_instance_config', array('field_id' => $field->uuid, 'deleted' => TRUE, 'include_deleted' => TRUE)); $this->assertEqual(count($instances), 1, 'There is one deleted instance'); - $instance = $instances[0]; + $instance = $instances[$instance->uuid]; $this->assertEqual($instance->bundle, $bundle, 'The deleted instance is for the correct bundle'); // Check that the actual stored content did not change during delete. @@ -306,9 +306,16 @@ function testPurgeField() { } $this->checkHooksInvocations($hooks, $actual_hooks); + // The instance still exists, deleted. + $instances = entity_load_multiple_by_properties('field_instance_config', array('uuid' => $instance->uuid, 'include_deleted' => TRUE)); + $this->assertTrue(isset($instances[$instance->uuid]) && $instances[$instance->uuid]->deleted, 'The instance exists and is deleted'); + // Purge again to purge the instance. field_purge_batch(0); + // The instance is gone. + $instances = entity_load_multiple_by_properties('field_instance_config', array('uuid' => $instance->uuid, 'include_deleted' => TRUE)); + $this->assertEqual(count($instances), 0, 'The instance is purged.'); // The field still exists, not deleted. $fields = entity_load_multiple_by_properties('field_config', array('uuid' => $field->uuid, 'include_deleted' => TRUE)); $this->assertTrue(isset($fields[$field->uuid]) && !$fields[$field->uuid]->deleted, 'The field exists and is not deleted'); @@ -334,14 +341,18 @@ function testPurgeField() { } $this->checkHooksInvocations($hooks, $actual_hooks); - // The field still exists, deleted. + // The field and instance still exist, deleted. + $instances = entity_load_multiple_by_properties('field_instance_config', array('uuid' => $instance->uuid, 'include_deleted' => TRUE)); + $this->assertTrue(isset($instances[$instance->uuid]) && $instances[$instance->uuid]->deleted, 'The instance exists and is deleted'); $fields = entity_load_multiple_by_properties('field_config', array('uuid' => $field->uuid, 'include_deleted' => TRUE)); $this->assertTrue(isset($fields[$field->uuid]) && $fields[$field->uuid]->deleted, 'The field exists and is deleted'); // Purge again to purge the instance and the field. field_purge_batch(0); - // The field is gone. + // The field and instance are gone. + $instances = entity_load_multiple_by_properties('field_instance_config', array('uuid' => $instance->uuid, 'include_deleted' => TRUE)); + $this->assertEqual(count($instances), 0, 'The instance is purged.'); $fields = entity_load_multiple_by_properties('field_config', array('uuid' => $field->uuid, 'include_deleted' => TRUE)); $this->assertEqual(count($fields), 0, 'The field is purged.'); } diff --git a/core/modules/forum/forum.install b/core/modules/forum/forum.install index 1f5ed4f..2b3d14f 100644 --- a/core/modules/forum/forum.install +++ b/core/modules/forum/forum.install @@ -108,10 +108,7 @@ function forum_uninstall() { } // Purge field data now to allow taxonomy and options module to be uninstalled - // if this is the only field remaining. We need to run it twice because - // field_purge_batch() will not remove the instance and the field in the same - // pass. - field_purge_batch(10); + // if this is the only field remaining. field_purge_batch(10); // Allow to delete a forum's node type. $locked = \Drupal::state()->get('node.type.locked');