Commit 206d6ee6 authored by catch's avatar catch
Browse files

Issue #3192487 by andypost, murilohp, Gábor Hojtsy, daffie, pobster, apaderno:...

Issue #3192487 by andypost, murilohp, Gábor Hojtsy, daffie, pobster, apaderno: Warn about upcoming JSON database support requirement in Drupal 9
parent fe307a0f
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -1849,4 +1849,19 @@ public function getPagerManager(): PagerManagerInterface {
    return \Drupal::service('pager.manager');
  }

  /**
   * Runs a simple query to validate json datatype support.
   *
   * @return bool
   *   Returns the query result.
   */
  public function hasJson(): bool {
    try {
      return (bool) $this->query('SELECT JSON_TYPE(\'1\')');
    }
    catch (\Exception $e) {
      return FALSE;
    }
  }

}
+12 −0
Original line number Diff line number Diff line
@@ -353,6 +353,18 @@ public function rollbackSavepoint($savepoint_name = 'mimic_implicit_commit') {
    }
  }

  /**
   * {@inheritDoc}
   */
  public function hasJson(): bool {
    try {
      return (bool) $this->query('SELECT JSON_TYPEOF(\'1\')');
    }
    catch (\Exception $e) {
      return FALSE;
    }
  }

}

/**
+16 −0
Original line number Diff line number Diff line
@@ -487,6 +487,22 @@ function system_requirements($phase) {
    }
  }

  if ($phase == 'runtime') {
    // Test JSON support. To be required from Drupal 10.0.
    // @todo remove in https://www.drupal.org/project/drupal/issues/3203193
    $requirements['database_support_json'] = [
      'title' => t('Database support for JSON'),
      'severity' => REQUIREMENT_OK,
      'value' => t('Available'),
      'description' => t('Is required in Drupal 10.0.'),
    ];

    if (!Database::getConnection()->hasJson()) {
      $requirements['database_support_json']['value'] = t('Not available');
      $requirements['database_support_json']['severity'] = REQUIREMENT_WARNING;
    }
  }

  // Test PHP memory_limit
  $memory_limit = ini_get('memory_limit');
  $requirements['php_memory_limit'] = [
+8 −0
Original line number Diff line number Diff line
@@ -91,6 +91,14 @@ public function testStatusPage() {
    $this->drupalGet('admin/reports/status');
    $this->assertSession()->elementExists('xpath', '//details[contains(@class, "system-status-report__entry")]//div[contains(text(), "Cron has not run recently")]');
    \Drupal::state()->set('system.cron_last', $cron_last_run);

    // Check if JSON database support is enabled.
    $this->assertSession()->pageTextContains('Database support for JSON');
    $elements = $this->xpath('//details[@class="system-status-report__entry"]//div[contains(text(), :text)]', [
      ':text' => 'Is required in Drupal 10.0.',
    ]);
    $this->assertCount(1, $elements);
    $this->assertStringStartsWith('Available', $elements[0]->getParent()->getText());
  }

}