Security update for Core, with self-updated composer
[yaffs-website] / web / core / lib / Drupal / Core / Entity / Sql / SqlContentEntityStorage.php
index a13a4b2d17fbe2cd27a56b4951f2decebd062b49..22238d4bf50548377308ab9e840598354b599ee1 100644 (file)
@@ -117,6 +117,13 @@ class SqlContentEntityStorage extends ContentEntityStorageBase implements SqlEnt
    */
   protected $languageManager;
 
+  /**
+   * Whether this storage should use the temporary table mapping.
+   *
+   * @var bool
+   */
+  protected $temporary = FALSE;
+
   /**
    * {@inheritdoc}
    */
@@ -266,6 +273,31 @@ class SqlContentEntityStorage extends ContentEntityStorageBase implements SqlEnt
     }
   }
 
+  /**
+   * Sets the wrapped table mapping definition.
+   *
+   * @param \Drupal\Core\Entity\Sql\TableMappingInterface $table_mapping
+   *   The table mapping.
+   *
+   * @internal Only to be used internally by Entity API. Expected to be removed
+   *   by https://www.drupal.org/node/2554235.
+   */
+  public function setTableMapping(TableMappingInterface $table_mapping) {
+    $this->tableMapping = $table_mapping;
+  }
+
+  /**
+   * Changes the temporary state of the storage.
+   *
+   * @param bool $temporary
+   *   Whether to use a temporary table mapping or not.
+   *
+   * @internal Only to be used internally by Entity API.
+   */
+  public function setTemporary($temporary) {
+    $this->temporary = $temporary;
+  }
+
   /**
    * {@inheritdoc}
    */
@@ -279,8 +311,10 @@ class SqlContentEntityStorage extends ContentEntityStorageBase implements SqlEnt
     // @todo Clean-up this in https://www.drupal.org/node/2274017 so we can
     //   easily instantiate a new table mapping whenever needed.
     if (!isset($this->tableMapping) || $storage_definitions) {
+      $table_mapping_class = $this->temporary ? TemporaryTableMapping::class : DefaultTableMapping::class;
       $definitions = $storage_definitions ?: $this->entityManager->getFieldStorageDefinitions($this->entityTypeId);
-      $table_mapping = new DefaultTableMapping($this->entityType, $definitions);
+      /** @var \Drupal\Core\Entity\Sql\DefaultTableMapping|\Drupal\Core\Entity\Sql\TemporaryTableMapping $table_mapping */
+      $table_mapping = new $table_mapping_class($this->entityType, $definitions);
 
       $shared_table_definitions = array_filter($definitions, function (FieldStorageDefinitionInterface $definition) use ($table_mapping) {
         return $table_mapping->allowsSharedTableStorage($definition);
@@ -294,17 +328,11 @@ class SqlContentEntityStorage extends ContentEntityStorageBase implements SqlEnt
       // Make sure the key fields come first in the list of fields.
       $all_fields = array_merge($key_fields, array_diff($all_fields, $key_fields));
 
-      // Nodes have all three of these fields, while custom blocks only have
-      // log.
-      // @todo Provide automatic definitions for revision metadata fields in
-      //   https://www.drupal.org/node/2248983.
-      $revision_metadata_fields = array_intersect([
-        'revision_timestamp',
-        'revision_uid',
-        'revision_log',
-      ], $all_fields);
-
+      // If the entity is revisionable, gather the fields that need to be put
+      // in the revision table.
       $revisionable = $this->entityType->isRevisionable();
+      $revision_metadata_fields = $revisionable ? array_values($this->entityType->getRevisionMetadataKeys()) : [];
+
       $translatable = $this->entityType->isTranslatable();
       if (!$revisionable && !$translatable) {
         // The base layout stores all the base field values in the base table.
@@ -1512,12 +1540,12 @@ class SqlContentEntityStorage extends ContentEntityStorageBase implements SqlEnt
   /**
    * {@inheritdoc}
    */
-  public function onBundleCreate($bundle, $entity_type_id) { }
+  public function onBundleCreate($bundle, $entity_type_id) {}
 
   /**
    * {@inheritdoc}
    */
-  public function onBundleDelete($bundle, $entity_type_id) { }
+  public function onBundleDelete($bundle, $entity_type_id) {}
 
   /**
    * {@inheritdoc}
@@ -1699,7 +1727,7 @@ class SqlContentEntityStorage extends ContentEntityStorageBase implements SqlEnt
    */
   protected function storageDefinitionIsDeleted(FieldStorageDefinitionInterface $storage_definition) {
     // Configurable fields are marked for deletion.
-    if ($storage_definition instanceOf FieldStorageConfigInterface) {
+    if ($storage_definition instanceof FieldStorageConfigInterface) {
       return $storage_definition->isDeleted();
     }
     // For non configurable fields check whether they are still in the last