You are here

class DefaultDBSourcePlugin in Backup and Migrate 5.0.x

Same name and namespace in other branches
  1. 8.4 src/Plugin/BackupMigrateSource/DefaultDBSourcePlugin.php \Drupal\backup_migrate\Plugin\BackupMigrateSource\DefaultDBSourcePlugin

Defines an default database source plugin.

Plugin annotation


@BackupMigrateSourcePlugin(
  id = "DefaultDB",
  title = @Translation("Default Database"),
  description = @Translation("Back up the Drupal database."),
  locked = true
)

Hierarchy

Expanded class hierarchy of DefaultDBSourcePlugin

File

src/Plugin/BackupMigrateSource/DefaultDBSourcePlugin.php, line 22

Namespace

Drupal\backup_migrate\Plugin\BackupMigrateSource
View source
class DefaultDBSourcePlugin extends SourcePluginBase {

  /**
   * Get the Backup and Migrate plugin object.
   *
   * @return Drupal\backup_migrate\Core\Plugin\PluginInterface
   */
  public function getObject() {

    // Add the default database.
    $info = Database::getConnectionInfo('default', 'default');
    $info = $info['default'];

    // Set a default port if none is set. Because that's what core does.
    $info['port'] = empty($info['port']) ? 3306 : $info['port'];
    if ($info['driver'] == 'mysql') {
      $conf = $this
        ->getConfig();
      foreach ($info as $key => $value) {
        $conf
          ->set($key, $value);
      }
      return new DrupalMySQLiSource($conf);
    }
    return NULL;
  }

  /**
   * {@inheritdoc}
   */
  public function alterBackupMigrate(BackupMigrateInterface $bam, $key, array $options = []) {
    if ($source = $this
      ->getObject()) {
      $bam
        ->sources()
        ->add($key, $source);

      // @todo This needs a better solution.
      $config = [
        'exclude_tables' => [],
        'nodata_tables' => [
          'cache_advagg_minify',
          'cache_bootstrap',
          'cache_config',
          'cache_container',
          'cache_data',
          'cache_default',
          'cache_discovery',
          'cache_discovery_migration',
          'cache_dynamic_page_cache',
          'cache_entity',
          'cache_menu',
          'cache_migrate',
          'cache_page',
          'cache_render',
          'cache_rest',
          'cache_toolbar',
          'sessions',
          'watchdog',
          'webprofiler',
        ],
      ];

      // @todo Allow modules to add their own excluded tables.
      $bam
        ->plugins()
        ->add('db_exclude', new DBExcludeFilter(new Config($config)));
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
DefaultDBSourcePlugin::alterBackupMigrate public function Alter the backup_migrate object to add the source and required services. Overrides SourcePluginBase::alterBackupMigrate
DefaultDBSourcePlugin::getObject public function Get the Backup and Migrate plugin object. Overrides WrapperPluginBase::getObject
PluginBase::$configuration protected property Configuration information passed into the plugin. 1
PluginBase::$pluginDefinition protected property The plugin implementation definition. 1
PluginBase::$pluginId protected property The plugin_id.
PluginBase::DERIVATIVE_SEPARATOR constant A string which is used to separate base plugin IDs from the derivative ID.
PluginBase::getBaseId public function Gets the base_plugin_id of the plugin instance. Overrides DerivativeInspectionInterface::getBaseId
PluginBase::getDerivativeId public function Gets the derivative_id of the plugin instance. Overrides DerivativeInspectionInterface::getDerivativeId
PluginBase::getPluginDefinition public function Gets the definition of the plugin implementation. Overrides PluginInspectionInterface::getPluginDefinition 2
PluginBase::getPluginId public function Gets the plugin_id of the plugin instance. Overrides PluginInspectionInterface::getPluginId
PluginBase::isConfigurable public function Determines if the plugin is configurable.
WrapperPluginBase::calculateDependencies public function Calculates dependencies for the configured plugin. Overrides DependentPluginInterface::calculateDependencies
WrapperPluginBase::defaultConfiguration public function Gets default configuration for this plugin. Overrides ConfigurableInterface::defaultConfiguration
WrapperPluginBase::getConfig public function Return a Backup and Migrate Config object with the plugin configuration.
WrapperPluginBase::getConfiguration public function Gets this plugin's configuration. Overrides ConfigurableInterface::getConfiguration
WrapperPluginBase::setConfiguration public function Sets the configuration for this plugin instance. Overrides ConfigurableInterface::setConfiguration
WrapperPluginBase::__construct public function Constructs a \Drupal\Component\Plugin\PluginBase object. Overrides PluginBase::__construct