Commit 13c47f88 authored by mcpuddin's avatar mcpuddin Committed by jmuzz
Browse files

Issue #2000690 by mcpuddin: Better support revision deletions.

parent edb4e7d2
......@@ -566,23 +566,19 @@ class FieldCollectionItemEntity extends Entity {
* delete the collection item from archived revisions too. Instead, we delete
* the current default revision and archive the field collection.
*
* If no revisions are left or the host is not revisionable, the whole item
* is deleted.
*/
public function deleteRevision($skip_host_update = FALSE) {
if (!$this->revision_id) {
return;
}
$info = entity_get_info($this->hostEntityType());
if (empty($info['entity keys']['revision']) || !$this->hostEntity()) {
return $this->delete();
}
if (!$skip_host_update) {
// Just remove the item from the host, which cares about deleting the
// item (depending on whether the update creates a new revision).
$this->deleteHostEntityReference();
}
elseif (!$this->isDefaultRevision()) {
if (!$this->isDefaultRevision()) {
entity_revision_delete('field_collection_item', $this->revision_id);
}
// If deleting the default revision, take care!
......
......@@ -217,6 +217,20 @@ class FieldCollectionBasicTestCase extends DrupalWebTestCase {
$item = field_collection_item_load($item->item_id);
$this->assertTrue($item, 'Removed field collection item still exists.');
$this->assertTrue($item->archived, 'Removed field collection item is archived.');
// Test removing an old node revision. Make sure that the field collection
// is not removed
list ($node, $item) = $this->createNodeWithFieldCollection();
$node_vid = $node->vid;
$node->revision = TRUE;
node_save($node);
$node_vid2 = $node->vid;
$item_vid2 = $node->{$this->field_name}[LANGUAGE_NONE][0]['revision_id'];
node_revision_delete($node_vid);
$item2 = field_collection_item_revision_load($item_vid2);
$item_id2 = isset($item2->item_id) ? $item2->item_id : -1;
$this->assertEqual($item_id2, $item->item_id, 'Removing an old node revision does not delete newer field collection revisions');
}
/**
......
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