Problem/Motivation

Edge case, when entity_get_info() is called in hook_theme_registry_alter and there's a missing database, drupal_get_schema() is called which results in a broken maintenance page. drupal_get_schema() is called from both drupal_schema_fields_sql and drupal_schema_field_types. In other words: entity_get_info() -> drupal_schema_fields_sql -> drupal_get_schema()

To replicate:

  • Download and enable zurb_foundation theme
  • Apply the patch that wraps entity_get_info() in `try catch`. https://www.drupal.org/node/2833423
  • Turn off sql or mis-name the database
  • Load site

I understand this has more to do with this particular theme than with Drupal core, however, reading the code in drupal_get_schema() it appears to me like it is not functioning as planned and perhaps this edge case could become more prevalent in other situations.

When `drupal_get_schema()` is called in the previous situation, the $schema variable is empty. As a result a `new SchemaCache()` object is created. However, `isset` is then called on that protected object and, as such, doesn't return properly.

The relevant code:

function drupal_get_schema($table = NULL, $rebuild = FALSE) {
  static $schema;

  if ($rebuild || !isset($table)) {
    $schema = drupal_get_complete_schema($rebuild);
  }
  elseif (!isset($schema)) {
    $schema = new SchemaCache(); // Here's our new schema object
  }

  if (!isset($table)) { // In this case the table is set.
    return $schema;
  }
  if (isset($schema[$table])) { // This never exits properly
    return $schema[$table];
  }
  else { // And the else condition never fires.
    return FALSE;
  }
}

Proposed resolution

I can make up some solutions, but I'm not sure of a) their viability b) other consequences, but I've never let lack of knowledge slow me down!
1. Implement a public interface for the SchemaCache object.
2. Put the check in `try catch` instead of `if else.

Remaining tasks

Answer the question, might this appear in other situations? ie. is this just a throw away edge case?

Comments

icicleking created an issue. See original summary.

icicleking’s picture

Issue summary: View changes
icicleking’s picture

Issue summary: View changes

Status: Active » Closed (outdated)

Automatically closed because Drupal 7 security and bugfix support has ended as of 5 January 2025. If the issue verifiably applies to later versions, please reopen with details and update the version.