- Patch #1612014 by aspilicious, Berdir: create an interface for revisionable entities.
parent
4f62dcc38c
commit
619017f1c4
|
@ -252,6 +252,10 @@ class DatabaseStorageController implements EntityStorageControllerInterface {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$query->fields('revision', $entity_revision_fields);
|
$query->fields('revision', $entity_revision_fields);
|
||||||
|
|
||||||
|
// Compare revision id of the base and revision table, if equal then this
|
||||||
|
// is the current revision.
|
||||||
|
$query->addExpression('base.' . $this->revisionKey . ' = revision.' . $this->revisionKey, 'isCurrentRevision');
|
||||||
}
|
}
|
||||||
|
|
||||||
$query->fields('base', $entity_fields);
|
$query->fields('base', $entity_fields);
|
||||||
|
|
|
@ -38,6 +38,13 @@ class Entity implements EntityInterface {
|
||||||
*/
|
*/
|
||||||
protected $enforceIsNew;
|
protected $enforceIsNew;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Indicates whether this is the current revision.
|
||||||
|
*
|
||||||
|
* @var bool
|
||||||
|
*/
|
||||||
|
public $isCurrentRevision = TRUE;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructs a new entity object.
|
* Constructs a new entity object.
|
||||||
*/
|
*/
|
||||||
|
@ -248,4 +255,19 @@ class Entity implements EntityInterface {
|
||||||
public function entityInfo() {
|
public function entityInfo() {
|
||||||
return entity_get_info($this->entityType);
|
return entity_get_info($this->entityType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements Drupal\entity\EntityInterface::getRevisionId().
|
||||||
|
*/
|
||||||
|
public function getRevisionId() {
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Implements Drupal\entity\EntityInterface::isCurrentRevision().
|
||||||
|
*/
|
||||||
|
public function isCurrentRevision() {
|
||||||
|
return $this->isCurrentRevision;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -187,4 +187,22 @@ interface EntityInterface {
|
||||||
* @see entity_get_info()
|
* @see entity_get_info()
|
||||||
*/
|
*/
|
||||||
public function entityInfo();
|
public function entityInfo();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the revision identifier of the entity.
|
||||||
|
*
|
||||||
|
* @return
|
||||||
|
* The revision identifier of the entity, or NULL if the entity does not
|
||||||
|
* have a revision identifier.
|
||||||
|
*/
|
||||||
|
public function getRevisionId();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks if this entity is the current revision.
|
||||||
|
*
|
||||||
|
* @return bool
|
||||||
|
* TRUE if the entity is the current revision, FALSE otherwise.
|
||||||
|
*/
|
||||||
|
public function isCurrentRevision();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -167,4 +167,11 @@ class Node extends Entity {
|
||||||
$duplicate->vid = NULL;
|
$duplicate->vid = NULL;
|
||||||
return $duplicate;
|
return $duplicate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Overrides Drupal\entity\Entity::getRevisionId().
|
||||||
|
*/
|
||||||
|
public function getRevisionId() {
|
||||||
|
return $this->vid;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -149,6 +149,9 @@ class NodeStorageController extends DatabaseStorageController {
|
||||||
}
|
}
|
||||||
// Make sure to update the new revision key for the entity.
|
// Make sure to update the new revision key for the entity.
|
||||||
$entity->{$this->revisionKey} = $record->{$this->revisionKey};
|
$entity->{$this->revisionKey} = $record->{$this->revisionKey};
|
||||||
|
|
||||||
|
// Mark this revision as the current one.
|
||||||
|
$entity->isCurrentRevision = TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -75,6 +75,9 @@ class NodeRevisionsTest extends NodeTestBase {
|
||||||
$this->assertText($log, t('Log message found.'));
|
$this->assertText($log, t('Log message found.'));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Confirm that this is the current revision.
|
||||||
|
$this->assertTrue($node->isCurrentRevision(), 'Third node revision is the current one.');
|
||||||
|
|
||||||
// Confirm that revisions revert properly.
|
// Confirm that revisions revert properly.
|
||||||
$this->drupalPost("node/$node->nid/revisions/{$nodes[1]->vid}/revert", array(), t('Revert'));
|
$this->drupalPost("node/$node->nid/revisions/{$nodes[1]->vid}/revert", array(), t('Revert'));
|
||||||
$this->assertRaw(t('@type %title has been reverted back to the revision from %revision-date.',
|
$this->assertRaw(t('@type %title has been reverted back to the revision from %revision-date.',
|
||||||
|
@ -83,6 +86,10 @@ class NodeRevisionsTest extends NodeTestBase {
|
||||||
$reverted_node = node_load($node->nid);
|
$reverted_node = node_load($node->nid);
|
||||||
$this->assertTrue(($nodes[1]->body[LANGUAGE_NOT_SPECIFIED][0]['value'] == $reverted_node->body[LANGUAGE_NOT_SPECIFIED][0]['value']), t('Node reverted correctly.'));
|
$this->assertTrue(($nodes[1]->body[LANGUAGE_NOT_SPECIFIED][0]['value'] == $reverted_node->body[LANGUAGE_NOT_SPECIFIED][0]['value']), t('Node reverted correctly.'));
|
||||||
|
|
||||||
|
// Confirm that this is not the current version.
|
||||||
|
$node = node_load($node->nid, $node->vid);
|
||||||
|
$this->assertFalse($node->isCurrentRevision(), 'Third node revision is not the current one.');
|
||||||
|
|
||||||
// Confirm revisions delete properly.
|
// Confirm revisions delete properly.
|
||||||
$this->drupalPost("node/$node->nid/revisions/{$nodes[1]->vid}/delete", array(), t('Delete'));
|
$this->drupalPost("node/$node->nid/revisions/{$nodes[1]->vid}/delete", array(), t('Delete'));
|
||||||
$this->assertRaw(t('Revision from %revision-date of @type %title has been deleted.',
|
$this->assertRaw(t('Revision from %revision-date of @type %title has been deleted.',
|
||||||
|
|
Loading…
Reference in New Issue