function MenuTreeStorage::safeExecuteSelect

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Menu/MenuTreeStorage.php \Drupal\Core\Menu\MenuTreeStorage::safeExecuteSelect()
  2. 10 core/lib/Drupal/Core/Menu/MenuTreeStorage.php \Drupal\Core\Menu\MenuTreeStorage::safeExecuteSelect()
  3. 11.x core/lib/Drupal/Core/Menu/MenuTreeStorage.php \Drupal\Core\Menu\MenuTreeStorage::safeExecuteSelect()

Executes a select query while making sure the database table exists.

Parameters

\Drupal\Core\Database\Query\SelectInterface $query: The select object to be executed.

Return value

\Drupal\Core\Database\StatementInterface|null A prepared statement, or NULL if the query is not valid.

Throws

\Exception Thrown if the table could not be created or the database connection failed.

1 call to MenuTreeStorage::safeExecuteSelect()
MenuTreeStorage::menuNameInUse in core/lib/Drupal/Core/Menu/MenuTreeStorage.php
Determines whether a specific menu name is used in the tree.

File

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

Class

MenuTreeStorage
Provides a menu tree storage using the database.

Namespace

Drupal\Core\Menu

Code

protected function safeExecuteSelect(SelectInterface $query) {
    try {
        return $query->execute();
    } catch (\Exception $e) {
        // If there was an exception, try to create the table.
        if ($this->ensureTableExists()) {
            return $query->execute();
        }
        // Some other failure that we can not recover from.
        throw $e;
    }
}

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