protected function execute(InputInterface $input, OutputInterface $output)
{
/** @var $repo Repo */
$em = $this->getContainer()->get('doctrine.orm.entity_manager');
$repo = $this->getContainer()->get('knp_bundles.github_repository_api');
$page = 1;
$pager = new Pagerfanta(new DoctrineORMAdapter($em->getRepository('KnpBundlesBundle:Bundle')->queryAllSortedBy('updatedAt'), false));
$pager->setMaxPerPage(100)->setCurrentPage($page, false, true);
if (1 === $page) {
$output->writeln(sprintf('[%s] Loaded <comment>%d</comment> bundles from the DB', date('d-m-y H:i:s'), $pager->getNbResults()));
}
do {
/** @var $bundle Bundle */
foreach ($pager->getCurrentPageResults() as $bundle) {
// Check that API not failed
if (!$repo->updateCommits($bundle)) {
// Sleep a while, and check again
sleep(60);
$repo->updateCommits($bundle);
}
$em->persist($bundle);
}
$output->writeln(sprintf('[%s] Migrated %d from %d bundles', date('d-m-y H:i:s'), $page * 100, $pager->getNbResults()));
$em->flush();
++$page;
} while ($pager->hasNextPage() && $pager->setCurrentPage($page, false, true));
return 0;
}