Security update for Core, with self-updated composer
[yaffs-website] / web / core / lib / Drupal / Core / Entity / Sql / TemporaryTableMapping.php
diff --git a/web/core/lib/Drupal/Core/Entity/Sql/TemporaryTableMapping.php b/web/core/lib/Drupal/Core/Entity/Sql/TemporaryTableMapping.php
new file mode 100644 (file)
index 0000000..c53e660
--- /dev/null
@@ -0,0 +1,46 @@
+<?php
+
+namespace Drupal\Core\Entity\Sql;
+
+use Drupal\Core\Field\FieldStorageDefinitionInterface;
+
+/**
+ * Defines a temporary table mapping class.
+ */
+class TemporaryTableMapping extends DefaultTableMapping {
+
+  /**
+   * {@inheritdoc}
+   */
+  protected function generateFieldTableName(FieldStorageDefinitionInterface $storage_definition, $revision) {
+    return static::getTempTableName(parent::generateFieldTableName($storage_definition, $revision));
+  }
+
+  /**
+   * Generates a temporary table name.
+   *
+   * The method accounts for a maximum table name length of 64 characters.
+   *
+   * @param string $table_name
+   *   The initial table name.
+   * @param string $prefix
+   *   (optional) The prefix to use for the new table name. Defaults to 'tmp_'.
+   *
+   * @return string
+   *   The final table name.
+   */
+  public static function getTempTableName($table_name, $prefix = 'tmp_') {
+    $tmp_table_name = $prefix . $table_name;
+
+    // Limit the string to 48 characters, keeping a 16 characters margin for db
+    // prefixes.
+    if (strlen($table_name) > 48) {
+      $short_table_name = substr($table_name, 0, 34);
+      $table_hash = substr(hash('sha256', $table_name), 0, 10);
+
+      $tmp_table_name = $prefix . $short_table_name . $table_hash;
+    }
+    return $tmp_table_name;
+  }
+
+}