SqlBase::getDatabase() falls back to using a database connection keyed as 'migrate' if no explicit configuration, or fallback_state_key, is provided. If it fell back to the 'migrate' key, and no such database connection was defined, it would formerly throw ConnectionNotDefinedException. This was particularly problematic with the migrate_drupal module enabled - the node derivers would cause this exception to be thrown on a general plugin manager getDefinitions() or createInstances(), preventing either API from returning even valid migrations if the derivers were in play.
SqlBase::getDatabase() will now throw RequirementsException when there is no explicit database connection configured and no implicit 'migrate' connection is present. In addition, SqlBase now implements RequirementsInterface, and provides a default checkRequirements() which calls getDatabase() and thus will throw RequirementsException if there is no 'migrate' connection. In situations where you may be invoking a SqlBase-based source plugin and cannot guarantee it has a valid connection, you should catch RequirementsException and proceed accordingly. For example, when invoking a source plugin in a deriver:
Before:
foreach (static::getSourcePlugin('d7_node_type') as $row) {
After:
$node_types = static::getSourcePlugin('d7_node_type');
try {
$node_types->checkRequirements();
}
catch (RequirementsException $e) {
// If the d7_node_type requirements failed, that means we do not have a
// Drupal source database configured - there is nothing to generate.
return $this->derivatives;
}
foreach ($node_types as $row) {
If you have a source plugin derived from SqlBase in which you've implemented RequirementsInterface (and thus a checkRequirements() method), you should remove the dependency on RequirementsInterface and have your checkRequirements() method call its parent.
Before:
abstract class DrupalSqlBase extends SqlBase implements ContainerFactoryPluginInterface, RequirementsInterface, DependentPluginInterface {
...
public function checkRequirements() {
// Our own requirements checking...
}
After:
abstract class DrupalSqlBase extends SqlBase implements ContainerFactoryPluginInterface, DependentPluginInterface {
...
public function checkRequirements() {
// Our own requirements checking...
parent::checkRequirements();
}