Fatal error: Declaration of Drupal\migrate_upgrade\MigrateUpgradeDrushRunner::create(Psr\Container\ContainerInterface $container, $options = Array) must be compatible with Drupal\Core\DependencyInjection\ContainerInjectionInterface::create(Symfony\Component\DependencyInjection\ContainerInterface $container)
Below is MigrateUpgradeCommands.php
file
where I am creating an instance of new MigrateUpgradeDrushRunner() and passing two arguments $options
and $this->logger
class MigrateUpgradeCommands extends DrushCommands {
/**
* Logger service.
*
* @var \Drupal\Core\Logger\LoggerChannelInterface
*/
protected $logger;
/**
* MigrateUpgradeCommands constructor.
*
* @param \Drupal\Core\State\StateInterface $state
* State service.
* @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $loggerChannelFactoryInterface
* The logger.factory service.
*/
public function __construct(StateInterface $state, LoggerChannelFactoryInterface $loggerFactory) {
$this->state = $state;
$this->logger = $loggerFactory->get('drush');
}
/**
* Perform one or more upgrade processes.
*
* @command migrate:upgrade
*
* @usage drush migrate-upgrade --legacy-db-url='mysql://root:[email protected]/d6'
* Upgrade a Drupal 6 database to Drupal 8
* @usage drush migrate-upgrade --legacy-db-key='drupal_7'
* Upgrade Drupal 7 database where the connection to Drupal 7 has already
* been created in settings.php ($databases['drupal_7'])
* @usage drush migrate-upgrade --legacy-db-url='mysql://root:[email protected]/d7' --configure-only --migration-prefix=d7_custom_ --legacy-root=https://www.example.com
* Generate migrations for a custom migration from Drupal 7 to Drupal 8
*
* @validate-module-enabled migrate_upgrade
*
* @aliases migrate-upgrade, mup
*
* @throws \Exception
* When an error occurs.
*/
public function upgrade(array $options = []) {
$runner = new MigrateUpgradeDrushRunner($options, $this->logger);
$runner->configure();
if ($options['configure-only']) {
$runner->export();
}
else {
$runner->import();
$this->state->set('migrate_drupal_ui.performed', \Drupal::time()->getRequestTime());
}
// Remove the global database state.
$this->state->delete('migrate.fallback_state_key');
}
}
Now file MigrateUpgradeDrushRunner.php
class MigrateUpgradeDrushRunner implements ContainerInjectionInterface {
/**
* Logger channel.
*
* @var \Drupal\Core\Logger\LoggerChannelInterface
*/
protected $logger;
public static function create(ContainerInterface $container, $options = []) {
return new static(
$container->get('logger.factory'),
$options
);
}
/**
* MigrateUpgradeDrushRunner constructor.
*
* @param array $options
* Drush options parameters.
* @param \Drupal\Core\Logger\LoggerChannelInterface $logger
* Drush logger.
*/
public function __construct(array $options = [], LoggerChannelInterface $logger) {
$this->setOptions($options);
$this->logger = $logger;
}
}
Basically, how can I inject Container into MigrateUpgradeDrushRunner
so that I can fetch logger.factory service and pass it in the construct ?
create
.$logger
argument to your create method.$options
form__construct
andcreate
arguments and add setter and getter function for the protected$options
variable. You can also define theMigrateUpgradeDrushRunner
as a service and inject it to theMigrateUpgradeCommands
. Read more about services and dependency injection in Drupal 8: drupal.org/docs/8/api/services-and-dependency-injection/…