You are here

protected function DatabaseStorage::ensureTableExists in Drupal 9

Same name in this branch
  1. 9 core/lib/Drupal/Core/Config/DatabaseStorage.php \Drupal\Core\Config\DatabaseStorage::ensureTableExists()
  2. 9 core/lib/Drupal/Core/KeyValueStore/DatabaseStorage.php \Drupal\Core\KeyValueStore\DatabaseStorage::ensureTableExists()
Same name and namespace in other branches
  1. 8 core/lib/Drupal/Core/Config/DatabaseStorage.php \Drupal\Core\Config\DatabaseStorage::ensureTableExists()

Check if the config table exists and create it if not.

Return value

bool TRUE if the table was created, FALSE otherwise.

Throws

\Drupal\Core\Config\StorageException If a database error occurs.

1 call to DatabaseStorage::ensureTableExists()
DatabaseStorage::write in core/lib/Drupal/Core/Config/DatabaseStorage.php
Writes configuration data to the storage.

File

core/lib/Drupal/Core/Config/DatabaseStorage.php, line 162

Class

DatabaseStorage
Defines the Database storage.

Namespace

Drupal\Core\Config

Code

protected function ensureTableExists() {
  try {
    if (!$this->connection
      ->schema()
      ->tableExists($this->table)) {
      $this->connection
        ->schema()
        ->createTable($this->table, static::schemaDefinition());
      return TRUE;
    }
  } catch (DatabaseException $e) {
    return TRUE;
  } catch (\Exception $e) {
    throw new StorageException($e
      ->getMessage(), 0, $e);
  }
  return FALSE;
}