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()

Check if the table exists and create it if not.

Return value

bool TRUE if the table exists, FALSE if it does not exists.

4 calls to DatabaseStorage::ensureTableExists()
DatabaseStorage::set in core/lib/Drupal/Core/KeyValueStore/DatabaseStorage.php
Saves a value for a given key.
DatabaseStorage::setIfNotExists in core/lib/Drupal/Core/KeyValueStore/DatabaseStorage.php
Saves a value for a given key if it does not exist yet.
DatabaseStorageExpirable::setWithExpire in core/lib/Drupal/Core/KeyValueStore/DatabaseStorageExpirable.php
Saves a value for a given key with a time to live.
DatabaseStorageExpirable::setWithExpireIfNotExists in core/lib/Drupal/Core/KeyValueStore/DatabaseStorageExpirable.php
Sets a value for a given key with a time to live if it does not yet exist.

File

core/lib/Drupal/Core/KeyValueStore/DatabaseStorage.php, line 255

Class

DatabaseStorage
Defines a default key/value store implementation.

Namespace

Drupal\Core\KeyValueStore

Code

protected function ensureTableExists() {
  try {
    $database_schema = $this->connection
      ->schema();
    if (!$database_schema
      ->tableExists($this->table)) {
      $database_schema
        ->createTable($this->table, $this
        ->schemaDefinition());
      return TRUE;
    }
  } catch (SchemaObjectExistsException $e) {
    return TRUE;
  }
  return FALSE;
}