function DatabaseStorage::ensureTableExists

Same name in this branch
  1. 10 core/lib/Drupal/Core/Config/DatabaseStorage.php \Drupal\Core\Config\DatabaseStorage::ensureTableExists()
Same name in other branches
  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()
  3. 8.9.x core/lib/Drupal/Core/Config/DatabaseStorage.php \Drupal\Core\Config\DatabaseStorage::ensureTableExists()
  4. 11.x core/lib/Drupal/Core/Config/DatabaseStorage.php \Drupal\Core\Config\DatabaseStorage::ensureTableExists()
  5. 11.x 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();
        $database_schema->createTable($this->table, $this->schemaDefinition());
    } catch (DatabaseException $e) {
    } catch (\Exception $e) {
        return FALSE;
    }
    return TRUE;
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.