Skip to content

Commit

Permalink
Fix warnings on migrate rollback (#4774)
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiu-cristea committed Jun 15, 2021
1 parent 09c3314 commit e436955
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 18 deletions.
13 changes: 5 additions & 8 deletions src/Drupal/Commands/core/MigrateRunnerCommands.php
Original file line number Diff line number Diff line change
Expand Up @@ -402,17 +402,14 @@ public function rollback(?string $migrationIds = null, array $options = ['all' =
$this->logger()->error(dt('No migrations found.'));
}

$executableOptions = [];
foreach (['feedback', 'idlist', 'progress'] as $option) {
if ($options[$option]) {
$executableOptions[$option] = $options[$option];
}
}

$executableOptions = array_intersect_key(
$options,
array_flip(['feedback', 'idlist', 'progress'])
);
foreach ($list as $migrations) {
// Rollback in reverse order.
$migrations = array_reverse($migrations);
foreach ($migrations as $migrationId => $migration) {
foreach ($migrations as $migration) {
$executable = new MigrateExecutable($migration, $this->getMigrateMessage(), $this->output(), $executableOptions);
// drush_op() provides --simulate support.
drush_op([$executable, 'rollback']);
Expand Down
20 changes: 16 additions & 4 deletions src/Drupal/Migrate/MigrateExecutable.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class MigrateExecutable extends MigrateExecutableBase
/**
* Frequency (in items) at which progress messages should be emitted.
*
* @var int
* @var int|null
*/
protected $feedback;

Expand All @@ -75,7 +75,7 @@ class MigrateExecutable extends MigrateExecutableBase
*
* @var bool
*/
protected $showTotal = false;
protected $showTotal;

/**
* List of specific source IDs to import.
Expand Down Expand Up @@ -108,7 +108,7 @@ class MigrateExecutable extends MigrateExecutableBase
/**
* Whether to delete rows missing from source after an import.
*
* @var bool|null
* @var bool
*/
protected $deleteMissingSourceRows;

Expand Down Expand Up @@ -155,13 +155,25 @@ class MigrateExecutable extends MigrateExecutableBase
public function __construct(MigrationInterface $migration, MigrateMessageInterface $message, OutputInterface $output, array $options = [])
{
Timer::start('migrate:' . $migration->getPluginId());

// Provide sane defaults.
$options += [
'idlist' => null,
'limit' => null,
'feedback' => null,
'timestamp' => false,
'total' => false,
'delete' => false,
'progress' => true,
];

$this->idlist = MigrateUtils::parseIdList($options['idlist']);

parent::__construct($migration, $message);

$this->output = $output;
$this->limit = $options['limit'];
$this->feedback = $options['feedback'] ?? 0;
$this->feedback = $options['feedback'];
$this->showTimestamp = $options['timestamp'];
$this->showTotal = $options['total'];
$this->deleteMissingSourceRows = $options['delete'];
Expand Down
6 changes: 3 additions & 3 deletions tests/functional/WatchdogTailTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ public function testWatchdogTail()
do {
$iteration++;
$expected_output[$iteration] = "watchdog tail iteration $iteration.";
$this->drush('php-eval', ["\\Drupal::logger('drush')->notice('{$expected_output[$iteration]}');"]);
$this->drush('php-eval', ["Drupal::logger('drush')->notice('{$expected_output[$iteration]}');"]);
sleep(2);
$output = $childDrushProcess->getIncrementalOutput();
$this->assertContains($expected_output[$iteration], $output);
$this->assertStringContainsString($expected_output[$iteration], $output);
if ($iteration > 1) {
$this->assertNotContains($expected_output[$iteration - 1], $output);
$this->assertStringNotContainsString($expected_output[$iteration - 1], $output);
}
} while ($iteration < 3);
}
Expand Down
5 changes: 2 additions & 3 deletions tests/integration/CustomLibraryCommandsAndGeneratorsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,8 @@ class CustomLibraryCommandsAndGeneratorsTest extends UnishIntegrationTestCase
*/
public function testCustomLibraryCommandsAndGenerators(): void
{
$this->drush('list');
$this->assertStringContainsString('custom_cmd', $this->getOutput());
$this->assertStringContainsString('Auto-discoverable custom command', $this->getOutput());
$this->drush('custom_cmd', [], ['help' => null]);
$this->assertStringContainsString('Auto-discoverable custom command. Used for Drush testing.', $this->getOutput());
$this->drush('custom_cmd');
$this->assertStringContainsString('Hello world!', $this->getOutput());
$this->drush('generate', ['list']);
Expand Down

0 comments on commit e436955

Please sign in to comment.