You are here

public function SqlBase::getDatabase in Drupal 10

Same name and namespace in other branches
  1. 8 core/modules/migrate/src/Plugin/migrate/source/SqlBase.php \Drupal\migrate\Plugin\migrate\source\SqlBase::getDatabase()
  2. 9 core/modules/migrate/src/Plugin/migrate/source/SqlBase.php \Drupal\migrate\Plugin\migrate\source\SqlBase::getDatabase()

Gets the database connection object.

Return value

\Drupal\Core\Database\Connection The database connection.

11 calls to SqlBase::getDatabase()
MenuLink::fields in core/modules/menu_link_content/src/Plugin/migrate/source/MenuLink.php
Returns available fields on the source.
MenuLink::hasTranslation in core/modules/menu_link_content/src/Plugin/migrate/source/MenuLink.php
Determines if this menu_link has an i18n translation.
Node::getFieldData in core/modules/node/src/Plugin/migrate/source/d6/Node.php
Retrieves raw field data for a node.
ProfileField::checkRequirements in core/modules/user/src/Plugin/migrate/source/ProfileField.php
Checks if requirements for this plugin are OK.
SqlBase::checkRequirements in core/modules/migrate/src/Plugin/migrate/source/SqlBase.php
Checks if requirements for this plugin are OK.

... See full list

2 methods override SqlBase::getDatabase()
TestSqlBase::getDatabase in core/modules/migrate/tests/src/Unit/SqlBaseTest.php
Gets the database connection object.
TestSqlBase::getDatabase in core/modules/migrate/tests/src/Kernel/SqlBaseTest.php
Gets the database without caching it.

File

core/modules/migrate/src/Plugin/migrate/source/SqlBase.php, line 144

Class

SqlBase
Sources whose data may be fetched via a database connection.

Namespace

Drupal\migrate\Plugin\migrate\source

Code

public function getDatabase() {
  if (!isset($this->database)) {

    // Look first for an explicit state key containing the configuration.
    if (isset($this->configuration['database_state_key'])) {
      $this->database = $this
        ->setUpDatabase($this->state
        ->get($this->configuration['database_state_key']));
    }
    elseif (isset($this->configuration['key'])) {
      $this->database = $this
        ->setUpDatabase($this->configuration);
    }
    elseif ($fallback_state_key = $this->state
      ->get('migrate.fallback_state_key')) {
      $this->database = $this
        ->setUpDatabase($this->state
        ->get($fallback_state_key));
    }
    else {
      $this->database = $this
        ->setUpDatabase([]);
    }
  }
  return $this->database;
}