addOption(
'--newer-into-older',
null,
InputOption::VALUE_NONE,
'By default, this command will merge older contacts and activity into the newer. Use this flag to reverse that behavior.'
)
->addOption(
'--contact-ids',
null,
InputOption::VALUE_REQUIRED,
'Comma separated list of contact IDs to deduplicate. If not provided, all contacts will be deduplicated. Example: --contact-ids=23,3,11'
)
->setHelp(
<<<'EOT'
The %command.name% command will dedpulicate contacts based on unique identifier values.
php %command.full_name%
EOT
);
}
protected function execute(InputInterface $input, OutputInterface $output): int
{
$newerIntoOlder = (bool) $input->getOption('newer-into-older');
$contactIds = array_filter(explode(',', $input->getOption('contact-ids')));
$duplicateCount = count($contactIds);
$progressBar = new ProgressBar($output, $duplicateCount);
$stopwatch = new Stopwatch();
if (!$contactIds) {
$output->writeln('No contacts to deduplicate.');
return Command::FAILURE;
}
$output->writeln("{$duplicateCount} contacts passed to deduplicate");
$progressBar->setFormat('debug');
$progressBar->start();
$stopwatch->start('deduplicate');
$contacts = $this->contactDeduper->getContactsByIds($contactIds);
$this->contactDeduper->deduplicateContactBatch($contacts, $newerIntoOlder, fn () => $progressBar->advance());
$progressBar->finish();
$event = $stopwatch->stop('deduplicate');
$output->writeln("Duration: {$event->getDuration()} ms, Memory: {$event->getMemory()} bytes");
return Command::SUCCESS;
}
}