Code Duplication    Length = 61-61 lines in 2 locations

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

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