W3cubDocs

/Drupal 8

protected function DatabaseLockBackend::ensureTableExists

protected DatabaseLockBackend::ensureTableExists()

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

File

core/lib/Drupal/Core/Lock/DatabaseLockBackend.php, line 170

Class

DatabaseLockBackend
Defines the database lock backend. This is the default backend in Drupal.

Namespace

Drupal\Core\Lock

Code

protected function ensureTableExists() {
  try {
    $database_schema = $this->database->schema();
    if (!$database_schema->tableExists(static::TABLE_NAME)) {
      $schema_definition = $this->schemaDefinition();
      $database_schema->createTable(static::TABLE_NAME, $schema_definition);
      return TRUE;
    }
  }
  // If another process has already created the semaphore table, attempting to
  // recreate it will throw an exception. In this case just catch the
  // exception and do nothing.
  catch (SchemaObjectExistsException $e) {
    return TRUE;
  }
  return FALSE;
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal!Core!Lock!DatabaseLockBackend.php/function/DatabaseLockBackend::ensureTableExists/8.1.x