Code Duplication    Length = 61-61 lines in 2 locations

eZ/Bundle/EzPublishMigrationBundle/Command/LegacyStorage/RegenerateUrlAliasesCommand.php 2 locations

@@ 325-385 (lines=61) @@
322
     *
323
     * @see \eZ\Bundle\EzPublishMigrationBundle\Command\LegacyStorage\RegenerateUrlAliasesCommand::restoreCustomLocationAliases()
324
     */
325
    protected function doRestoreCustomLocationAliases()
326
    {
327
        $totalCount = $this->getTotalBackupCount(static::CUSTOM_ALIAS_BACKUP_TABLE);
328
        $passCount = ceil($totalCount / $this->bulkCount);
329
        $createdAliasCount = 0;
330
        $conflictCount = 0;
331
332
        if ($totalCount === 0) {
333
            $this->output->writeln(
334
                'Could not find any backed up custom Location URL aliases, nothing to restore.'
335
            );
336
            $this->output->writeln('');
337
338
            return;
339
        }
340
341
        $queryBuilder = $this->connection->createQueryBuilder();
342
        $queryBuilder
343
            ->select('*')
344
            ->from(static::CUSTOM_ALIAS_BACKUP_TABLE)
345
            ->orderBy('id', 'ASC');
346
347
        $this->output->writeln("Restoring {$totalCount} custom URL alias(es).");
348
349
        $progressBar = $this->getProgressBar($totalCount);
350
        $progressBar->start();
351
352
        for ($pass = 0; $pass <= $passCount; ++$pass) {
353
            $rows = $this->loadPassData($queryBuilder, $pass);
354
355
            foreach ($rows as $row) {
356
                try {
357
                    $this->setMigrationTable();
358
                    $this->urlAliasHandler->createCustomUrlAlias(
359
                        $row['location_id'],
360
                        $row['path'],
361
                        (bool)$row['forwarding'],
362
                        $row['language_code'],
363
                        (bool)$row['always_available']
364
                    );
365
                    $createdAliasCount += 1;
366
                    $this->setDefaultTable();
367
                } catch (ForbiddenException $e) {
368
                    $conflictCount += 1;
369
                } catch (Exception $e) {
370
                    $this->setDefaultTable();
371
                    throw $e;
372
                }
373
            }
374
375
            $progressBar->advance(count($rows));
376
        }
377
378
        $progressBar->finish();
379
380
        $this->output->writeln('');
381
        $this->output->writeln(
382
            "Done. Restored {$createdAliasCount} custom URL alias(es) " .
383
            "with {$conflictCount} conflict(s)."
384
        );
385
        $this->output->writeln('');
386
    }
387
388
    /**
@@ 772-832 (lines=61) @@
769
     *
770
     * @see \eZ\Bundle\EzPublishMigrationBundle\Command\LegacyStorage\RegenerateUrlAliasesCommand::restoreGlobalAliases()
771
     */
772
    protected function doRestoreGlobalAliases()
773
    {
774
        $totalCount = $this->getTotalBackupCount(static::GLOBAL_ALIAS_BACKUP_TABLE);
775
        $passCount = ceil($totalCount / $this->bulkCount);
776
        $createdAliasCount = 0;
777
        $conflictCount = 0;
778
779
        if ($totalCount === 0) {
780
            $this->output->writeln(
781
                'Could not find any backed up global URL aliases, nothing to restore.'
782
            );
783
            $this->output->writeln('');
784
785
            return;
786
        }
787
788
        $queryBuilder = $this->connection->createQueryBuilder();
789
        $queryBuilder
790
            ->select('*')
791
            ->from(static::GLOBAL_ALIAS_BACKUP_TABLE)
792
            ->orderBy('id', 'ASC');
793
794
        $this->output->writeln("Restoring {$totalCount} custom URL alias(es).");
795
796
        $progressBar = $this->getProgressBar($totalCount);
797
        $progressBar->start();
798
799
        for ($pass = 0; $pass <= $passCount; ++$pass) {
800
            $rows = $this->loadPassData($queryBuilder, $pass);
801
802
            foreach ($rows as $row) {
803
                try {
804
                    $this->setMigrationTable();
805
                    $this->urlAliasHandler->createGlobalUrlAlias(
806
                        $row['resource'],
807
                        $row['path'],
808
                        (bool)$row['forwarding'],
809
                        $row['language_code'],
810
                        (bool)$row['always_available']
811
                    );
812
                    $createdAliasCount += 1;
813
                    $this->setDefaultTable();
814
                } catch (ForbiddenException $e) {
815
                    $conflictCount += 1;
816
                } catch (Exception $e) {
817
                    $this->setDefaultTable();
818
                    throw $e;
819
                }
820
            }
821
822
            $progressBar->advance(count($rows));
823
        }
824
825
        $progressBar->finish();
826
827
        $this->output->writeln('');
828
        $this->output->writeln(
829
            "Done. Restored {$createdAliasCount} custom URL alias(es) " .
830
            "with {$conflictCount} conflict(s)."
831
        );
832
        $this->output->writeln('');
833
    }
834
835
    /**