From 1251cc35a7f78e803ec99f836120496f445b8b84 Mon Sep 17 00:00:00 2001
From: webchick <drupal@webchick.net>
Date: Wed, 18 Jun 2014 00:07:06 -0700
Subject: [PATCH] Issue #2284111 by alexpott, Berdir, damiankloip: Fixed
 Exceptions caught and printed from index.php should not return a 200 status
 code.

---
 .../Entity/ContentEntityDatabaseStorage.php   | 25 +++++++++++--------
 .../ContentEntityDatabaseStorageTest.php      |  2 +-
 index.php                                     |  4 +++
 3 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php b/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php
index cf7930d5e849..a60122fb77e5 100644
--- a/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php
+++ b/core/lib/Drupal/Core/Entity/ContentEntityDatabaseStorage.php
@@ -39,13 +39,6 @@
  */
 class ContentEntityDatabaseStorage extends ContentEntityStorageBase implements SqlEntityStorageInterface {
 
-  /**
-   * The storage field definitions for this entity type.
-   *
-   * @var \Drupal\Core\Field\FieldStorageDefinitionInterface[]
-   */
-  protected $fieldStorageDefinitions;
-
   /**
    * The mapping of field columns to SQL tables.
    *
@@ -129,6 +122,17 @@ public static function createInstance(ContainerInterface $container, EntityTypeI
     );
   }
 
+  /**
+   * Gets the base field definitions for a content entity type.
+   *
+   * @return \Drupal\Core\Field\FieldDefinitionInterface[]
+   *   The array of base field definitions for the entity type, keyed by field
+   *   name.
+   */
+  public function getFieldStorageDefinitions() {
+    return $this->entityManager->getBaseFieldDefinitions($this->entityTypeId);
+  }
+
   /**
    * Constructs a ContentEntityDatabaseStorage object.
    *
@@ -144,7 +148,6 @@ public function __construct(EntityTypeInterface $entity_type, Connection $databa
 
     $this->database = $database;
     $this->entityManager = $entity_manager;
-    $this->fieldStorageDefinitions = $entity_manager->getBaseFieldDefinitions($entity_type->id());
 
     // @todo Remove table names from the entity type definition in
     //   https://drupal.org/node/2232465
@@ -236,7 +239,7 @@ protected function schemaHandler() {
   public function getTableMapping() {
     if (!isset($this->tableMapping)) {
 
-      $definitions = array_filter($this->fieldStorageDefinitions, function (FieldDefinitionInterface $definition) {
+      $definitions = array_filter($this->getFieldStorageDefinitions(), function (FieldDefinitionInterface $definition) {
         // @todo Remove the check for FieldDefinitionInterface::isMultiple() when
         //   multiple-value base fields are supported in
         //   https://drupal.org/node/2248977.
@@ -834,10 +837,10 @@ protected function mapToStorageRecord(ContentEntityInterface $entity, $table_nam
     $table_mapping = $this->getTableMapping();
     foreach ($table_mapping->getFieldNames($table_name) as $field_name) {
 
-      if (empty($this->fieldStorageDefinitions[$field_name])) {
+      if (empty($this->getFieldStorageDefinitions()[$field_name])) {
         throw new EntityStorageException(String::format('Table mapping contains invalid field %field.', array('%field' => $field_name)));
       }
-      $definition = $this->fieldStorageDefinitions[$field_name];
+      $definition = $this->getFieldStorageDefinitions()[$field_name];
       $columns = $table_mapping->getColumnNames($field_name);
 
       foreach ($columns as $column_name => $schema_name) {
diff --git a/core/tests/Drupal/Tests/Core/Entity/ContentEntityDatabaseStorageTest.php b/core/tests/Drupal/Tests/Core/Entity/ContentEntityDatabaseStorageTest.php
index 0b8f6e2d2a3d..80c0b88354ba 100644
--- a/core/tests/Drupal/Tests/Core/Entity/ContentEntityDatabaseStorageTest.php
+++ b/core/tests/Drupal/Tests/Core/Entity/ContentEntityDatabaseStorageTest.php
@@ -1048,7 +1048,7 @@ protected function setUpEntityStorage() {
       ->disableOriginalConstructor()
       ->getMock();
 
-    $this->entityManager->expects($this->once())
+    $this->entityManager->expects($this->any())
       ->method('getBaseFieldDefinitions')
       ->will($this->returnValue($this->fieldDefinitions));
 
diff --git a/index.php b/index.php
index a453ecc1f910..4d8106064e4f 100644
--- a/index.php
+++ b/index.php
@@ -22,6 +22,10 @@
     $rebuild_path = $GLOBALS['base_url'] . '/rebuild.php';
     $message .= " or run the <a href=\"$rebuild_path\">rebuild script</a>";
   }
+
+  // Set the response code manually. Otherwise, this response will default to a
+  // 200.
+  http_response_code(500);
   print $message;
   throw $e;
 }
-- 
GitLab