protected function MenuTreeStorage::ensureTableExists

protected MenuTreeStorage::ensureTableExists()

Checks if the tree table exists and create it if not.

Return value

bool TRUE if the table was created, FALSE otherwise.

Throws

\Drupal\Component\Plugin\Exception\PluginException If a database error occurs.

File

core/lib/Drupal/Core/Menu/MenuTreeStorage.php, line 1151

Class

MenuTreeStorage
Provides a menu tree storage using the database.

Namespace

Drupal\Core\Menu

Code

protected function ensureTableExists() {
  try {
    if (!$this->connection->schema()->tableExists($this->table)) {
      $this->connection->schema()->createTable($this->table, static::schemaDefinition());
      return TRUE;
    }
  }
  catch (SchemaObjectExistsException $e) {
    // If another process has already created the config table, attempting to
    // recreate it will throw an exception. In this case just catch the
    // exception and do nothing.
    return TRUE;
  }
  catch (\Exception $e) {
    throw new PluginException($e->getMessage(), NULL, $e);
  }
  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!Menu!MenuTreeStorage.php/function/MenuTreeStorage::ensureTableExists/8.1.x