diff --git a/core/modules/entity/entity.class.inc b/core/modules/entity/entity.class.inc index 9a00718..35dd494 100644 --- a/core/modules/entity/entity.class.inc +++ b/core/modules/entity/entity.class.inc @@ -193,6 +193,13 @@ interface EntityInterface { class Entity implements EntityInterface { /** + * Boolean indicating whether the entity is saving to the base table or just as a revision. + * + * @var bool + */ + public $isLive = TRUE; + + /** * The language code of the entity's default language. * * @var string diff --git a/core/modules/field/modules/field_sql_storage/field_sql_storage.module b/core/modules/field/modules/field_sql_storage/field_sql_storage.module index b3eed49..acbc367 100644 --- a/core/modules/field/modules/field_sql_storage/field_sql_storage.module +++ b/core/modules/field/modules/field_sql_storage/field_sql_storage.module @@ -395,11 +395,14 @@ function field_sql_storage_field_storage_write($entity_type, $entity, $op, $fiel // Delete all language codes if $entity->$field_name is empty. $langcodes = !empty($entity->$field_name) ? $field_langcodes : $all_langcodes; if ($langcodes) { - db_delete($table_name) - ->condition('entity_type', $entity_type) - ->condition('entity_id', $id) - ->condition('langcode', $langcodes, 'IN') - ->execute(); + // Only act on the main table for this field if this entity is going live. + if (!empty($entity->isLive)) { + db_delete($table_name) + ->condition('entity_type', $entity_type) + ->condition('entity_id', $id) + ->condition('langcode', $langcodes, 'IN') + ->execute(); + } db_delete($revision_name) ->condition('entity_type', $entity_type) ->condition('entity_id', $id) @@ -448,7 +451,10 @@ function field_sql_storage_field_storage_write($entity_type, $entity, $op, $fiel // Execute the query if we have values to insert. if ($do_insert) { - $query->execute(); + // Only overwrite the live table field if this entity is going live. + if (!empty($entity->isLive)) { + $query->execute(); + } $revision_query->execute(); } } diff --git a/core/modules/node/lib/Drupal/node/NodeStorageController.php b/core/modules/node/lib/Drupal/node/NodeStorageController.php index 0cdca80..5f4e7e2 100644 --- a/core/modules/node/lib/Drupal/node/NodeStorageController.php +++ b/core/modules/node/lib/Drupal/node/NodeStorageController.php @@ -100,7 +100,15 @@ class NodeStorageController extends EntityDatabaseStorageController { } else { $op = 'update'; - $return = drupal_write_record($this->entityInfo['base table'], $entity, $this->idKey); + // $node->nid, but only if marked as the live revision. + if ($entity->isLive) { + $return = drupal_write_record($this->entityInfo['base table'], $entity, $this->idKey); + } + else { + // @todo, should a different value be returned when saving an entity + // with isLive = FALSE? + $return = FALSE; + } } if ($this->revisionKey) { @@ -139,10 +147,13 @@ class NodeStorageController extends EntityDatabaseStorageController { if (empty($entity->{$this->revisionKey}) || !empty($entity->revision)) { drupal_write_record($this->revisionTable, $record); - db_update($this->entityInfo['base table']) - ->fields(array($this->revisionKey => $record->{$this->revisionKey})) - ->condition($this->idKey, $entity->{$this->idKey}) - ->execute(); + // Updates the base table the revision saved was going live. + if ($entity->isLive) { + db_update($this->entityInfo['base table']) + ->fields(array($this->revisionKey => $record->{$this->revisionKey})) + ->condition($this->idKey, $entity->{$this->idKey}) + ->execute(); + } } else { drupal_write_record($this->revisionTable, $record, $this->revisionKey); @@ -260,7 +271,11 @@ class NodeStorageController extends EntityDatabaseStorageController { * Overrides EntityDatabaseStorageController::postSave(). */ function postSave(EntityInterface $node, $update) { - node_access_acquire_grants($node, $update); + // Update the node access table for this node, but only if it is the live + // revision. There's no need to delete existing records if the node is new. + if ($node->isLive) { + node_access_acquire_grants($node, $update); + } } /** diff --git a/core/modules/node/node.pages.inc b/core/modules/node/node.pages.inc index 868acbd..cff4918 100644 --- a/core/modules/node/node.pages.inc +++ b/core/modules/node/node.pages.inc @@ -233,6 +233,17 @@ function node_form($form, &$form_state, Node $node) { '#default_value' => $node->revision, '#access' => user_access('administer nodes'), ); + $form['revision_information']['isLive'] = array( + '#type' => 'checkbox', + '#title' => t('Set as live revision'), + '#default_value' => 1, + '#access' => user_access('administer nodes'), + '#states' => array( + 'visible' => array( + ':input[name="revision"]' => array('checked' => TRUE), + ), + ), + ); // Check the revision log checkbox when the log textarea is filled in. // This must not happen if "Create new revision" is enabled by default, since // the state would auto-disable the checkbox otherwise.