function MenuTreeStorage::ensureTableExists

Same name in other branches
  1. 9 core/lib/Drupal/Core/Menu/MenuTreeStorage.php \Drupal\Core\Menu\MenuTreeStorage::ensureTableExists()
  2. 10 core/lib/Drupal/Core/Menu/MenuTreeStorage.php \Drupal\Core\Menu\MenuTreeStorage::ensureTableExists()
  3. 11.x core/lib/Drupal/Core/Menu/MenuTreeStorage.php \Drupal\Core\Menu\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.

1 call to MenuTreeStorage::ensureTableExists()
MenuTreeStorage::safeExecuteSelect in core/lib/Drupal/Core/Menu/MenuTreeStorage.php
Executes a select query while making sure the database table exists.

File

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

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 (DatabaseException $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;
}

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