Exponential 5.x Kernel 7.5.40 Exponential New Stack (Symfony-based) Kernel — PHP Class Reference

EzPublishMigrationBundle/Command/LegacyStorage/RegenerateUrlAliasesCommand.php
Go to the documentation of this file.
1 <?php
2
7 namespace eZ\Bundle\EzPublishMigrationBundle\Command\LegacyStorage;
8
9 use eZ\Publish\API\Repository\Exceptions\ForbiddenException;
10 use eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Gateway as UrlAliasGateway;
11 use eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler as UrlAliasHandler;
12 use eZ\Publish\Core\Persistence\Legacy\Handler as LegacyStorageEngine;
13 use eZ\Publish\SPI\Persistence\Content\UrlAlias;
14 use Doctrine\DBAL\Query\QueryBuilder;
15 use Doctrine\DBAL\Schema\Schema;
16 use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
17 use Symfony\Component\Console\Input\InputArgument;
18 use Symfony\Component\Console\Input\InputInterface;
19 use Symfony\Component\Console\Helper\ProgressBar;
20 use Symfony\Component\Console\Output\OutputInterface;
21 use RuntimeException;
22 use Exception;
23 use PDO;
24
28 class RegenerateUrlAliasesCommand extends ContainerAwareCommand
29 {
30 const MIGRATION_TABLE = '__migration_ezurlalias_ml';
31 const CUSTOM_ALIAS_BACKUP_TABLE = '__migration_backup_custom_alias';
32 const GLOBAL_ALIAS_BACKUP_TABLE = '__migration_backup_global_alias';
33
35 protected $contentService;
36
38 protected $nameSchemaResolver;
39
41 protected $urlAliasHandler;
42
44 protected $urlAliasGateway;
45
47 protected $connection;
48
50 protected $bulkCount;
51
53 protected $output;
54
55 protected $actionSet = [
56 'full' => true,
57 'autogenerate' => true,
58 'backup-custom' => true,
59 'restore-custom' => true,
60 'backup-global' => true,
61 'restore-global' => true,
62 ];
63
64 protected function configure()
65 {
66 $this
67 ->setName('ezplatform:regenerate:legacy_storage_url_aliases')
68 ->setDescription(
69 '[DEPRECATED] Regenerates Location URL aliases (autogenerated) and migrates custom Location ' .
70 'and global URL aliases with Legacy Storage Engine'
71 )
72 ->addArgument(
73 'action',
74 InputArgument::REQUIRED,
75 'Action to perform, one of: full, autogenerate, backup-custom, restore-custom, backup-global, restore-global'
76 )
77 ->addArgument(
78 'bulk-count',
79 InputArgument::OPTIONAL,
80 'Number of items (Locations, URL aliases) processed at once',
81 50
82 )
83 ->setHelp(
84 <<<EOT
85 <error>This command is deprecated, use the ezplatform:urls:regenerate-aliases command instead.</error>
86 The command <info>%command.name%</info> regenerates URL aliases for Locations
87 and migrates existing custom Location and global URL aliases to a separate database table. Separate
88 table must be named '__migration_ezurlalias_ml' and should be created manually to be identical (but
89 empty) as the existing table 'ezurlalias_ml' before the command is executed.
90
91 After the script finishes, to complete migration the table should be renamed to 'ezurlalias_ml'
92 manually.
93
94 Using available options for 'action' argument, you can backup custom Location and global URL aliases
95 separately and inspect them before restoring them to the migration table. They will be stored in
96 backup tables named '__migration_backup_custom_alias' and '__migration_backup_global_alias' (created
97 automatically).
98
99 It is also possible to skip custom Location and global URL aliases altogether and regenerate only
100 automatically created URL aliases for Locations (use 'autogenerate' action to achieve this).
101
102 <error>During the script execution the database should not be modified.</error>
103
104 Since this script can potentially run for a very long time, to avoid memory exhaustion run it in
105 production environment using <info>--env=prod</info> switch.
106
107 EOT
108 );
109 }
110
111 protected function execute(InputInterface $input, OutputInterface $output)
112 {
113 @trigger_error(
114 sprintf(
115 '%s is deprecated since 6.7.8. Use the ezplatform:urls:regenerate-aliases command instead.',
116 $this->getName()
117 ),
118 E_USER_DEPRECATED
119 );
120 $output->writeln('<error>This command is deprecated, use the ezplatform:urls:regenerate-aliases command instead.</error>');
121
122 $this->checkStorage();
123
124 $action = $input->getArgument('action');
125 $this->bulkCount = $input->getArgument('bulk-count');
126
127 if (!isset($this->actionSet[$action])) {
128 throw new RuntimeException(
129 "Action '{$action}' is not supported, use one of: " .
130 implode(', ', array_keys($this->actionSet))
131 );
132 }
133
134 if ($action === 'full' || $action === 'backup-custom') {
135 $this->backupCustomLocationAliases();
136 }
137
138 if ($action === 'full' || $action === 'backup-global') {
139 $this->backupGlobalAliases();
140 }
141
142 if ($action === 'full' || $action === 'autogenerate') {
143 $this->generateLocationAliases();
144 }
145
146 if ($action === 'full' || $action === 'restore-custom') {
147 $this->restoreCustomLocationAliases();
148 }
149
150 if ($action === 'full' || $action === 'restore-global') {
151 $this->restoreGlobalAliases();
152 }
153 }
154
155 protected function initialize(InputInterface $input, OutputInterface $output)
156 {
158 $databaseHandler = $this->getContainer()->get('ezpublish.connection');
160 $gateway = $this->getContainer()->get('ezpublish.persistence.legacy.url_alias.gateway');
162 $persistenceHandler = $this->getContainer()->get('ezpublish.api.persistence_handler');
164 $innerRepository = $this->getContainer()->get('ezpublish.api.inner_repository');
166 $repository = $this->getContainer()->get('ezpublish.api.repository');
167
168 $administratorUser = $repository->getUserService()->loadUser(14);
169 $repository->getPermissionResolver()->setCurrentUserReference($administratorUser);
170
171 $this->contentService = $repository->getContentService();
172 $this->nameSchemaResolver = $innerRepository->getNameSchemaService();
173 $this->urlAliasHandler = $persistenceHandler->urlAliasHandler();
174 $this->urlAliasGateway = $gateway;
175 $this->connection = $databaseHandler->getConnection();
176 $this->output = $output;
177 }
178
182 protected function checkStorage()
183 {
184 $storageEngine = $this->getContainer()->get('ezpublish.api.storage_engine');
185
186 if (!$storageEngine instanceof LegacyStorageEngine) {
187 throw new RuntimeException(
188 'Expected to find Legacy Storage Engine but found something else.'
189 );
190 }
191 }
192
198 protected function setDefaultTable()
199 {
200 $this->urlAliasGateway->setTable(UrlAliasGateway::TABLE);
201 }
202
208 protected function setMigrationTable()
209 {
210 $this->urlAliasGateway->setTable(static::MIGRATION_TABLE);
211 }
212
216 protected function backupCustomLocationAliases()
217 {
218 $table = static::CUSTOM_ALIAS_BACKUP_TABLE;
219
220 if (!$this->tableExists($table)) {
221 $this->createCustomLocationUrlAliasBackupTable();
222 }
223
224 if (!$this->isTableEmpty($table)) {
225 throw new RuntimeException(
226 "Table '{$table}' contains data. " .
227 "Ensure it's empty or non-existent (it will be automatically created)."
228 );
229 }
230
231 $this->doBackupCustomLocationAliases();
232 }
233
239 protected function doBackupCustomLocationAliases()
240 {
241 $totalCount = $this->getTotalLocationCount();
242 $passCount = ceil($totalCount / $this->bulkCount);
243 $customAliasCount = 0;
244 $customAliasPathCount = 0;
245
246 if ($totalCount === 0) {
247 $this->output->writeln('Could not find any Locations, nothing to backup.');
248 $this->output->writeln('');
249
250 return;
251 }
252
253 $queryBuilder = $this->connection->createQueryBuilder();
254 $queryBuilder
255 ->select('node_id', 'parent_node_id', 'contentobject_id')
256 ->from('ezcontentobject_tree')
257 ->where($queryBuilder->expr()->neq('node_id', 1))
258 ->orderBy('depth', 'ASC')
259 ->addOrderBy('node_id', 'ASC');
260
261 $this->output->writeln("Backing up custom URL alias(es) for {$totalCount} Location(s).");
262
263 $progressBar = $this->getProgressBar($totalCount);
264 $progressBar->start();
265
266 for ($pass = 0; $pass <= $passCount; ++$pass) {
267 $rows = $this->loadLocationData($queryBuilder, $pass);
268
269 foreach ($rows as $row) {
270 $customAliases = $this->urlAliasHandler->listURLAliasesForLocation(
271 $row['node_id'],
272 true
273 );
274
275 $customAliasCount += count($customAliases);
276 $customAliasPathCount += $this->storeCustomAliases($customAliases);
277 }
278
279 $progressBar->advance(count($rows));
280 }
281
282 $progressBar->finish();
283
284 $this->output->writeln('');
285 $this->output->writeln(
286 "Done. Backed up {$customAliasCount} custom URL alias(es) " .
287 "with {$customAliasPathCount} path(s)."
288 );
289 $this->output->writeln('');
290 }
291
295 protected function restoreCustomLocationAliases()
296 {
297 $mainTable = static::MIGRATION_TABLE;
298 $backupTable = static::CUSTOM_ALIAS_BACKUP_TABLE;
299
300 if (!$this->tableExists($mainTable)) {
301 throw new RuntimeException(
302 "Could not find main URL alias migration table '{$mainTable}'. " .
303 'Ensure that table exists (you will have to create it manually).'
304 );
305 }
306
307 if (!$this->tableExists($backupTable)) {
308 throw new RuntimeException(
309 "Could not find custom Location URL alias backup table '{$backupTable}'. " .
310 "Ensure that table is created by 'backup-custom' action."
311 );
312 }
313
314 $this->doRestoreCustomLocationAliases();
315 }
316
322 protected function doRestoreCustomLocationAliases()
323 {
324 $totalCount = $this->getTotalBackupCount(static::CUSTOM_ALIAS_BACKUP_TABLE);
325 $passCount = ceil($totalCount / $this->bulkCount);
326 $createdAliasCount = 0;
327 $conflictCount = 0;
328
329 if ($totalCount === 0) {
330 $this->output->writeln(
331 'Could not find any backed up custom Location URL aliases, nothing to restore.'
332 );
333 $this->output->writeln('');
334
335 return;
336 }
337
338 $queryBuilder = $this->connection->createQueryBuilder();
339 $queryBuilder
340 ->select('*')
341 ->from(static::CUSTOM_ALIAS_BACKUP_TABLE)
342 ->orderBy('id', 'ASC');
343
344 $this->output->writeln("Restoring {$totalCount} custom URL alias(es).");
345
346 $progressBar = $this->getProgressBar($totalCount);
347 $progressBar->start();
348
349 for ($pass = 0; $pass <= $passCount; ++$pass) {
350 $rows = $this->loadPassData($queryBuilder, $pass);
351
352 foreach ($rows as $row) {
353 try {
354 $this->setMigrationTable();
355 $this->urlAliasHandler->createCustomUrlAlias(
356 $row['location_id'],
357 $row['path'],
358 (bool)$row['forwarding'],
359 $row['language_code'],
360 (bool)$row['always_available']
361 );
362 ++$createdAliasCount;
363 $this->setDefaultTable();
364 } catch (ForbiddenException $e) {
365 ++$conflictCount;
366 } catch (Exception $e) {
367 $this->setDefaultTable();
368 throw $e;
369 }
370 }
371
372 $progressBar->advance(count($rows));
373 }
374
375 $progressBar->finish();
376
377 $this->output->writeln('');
378 $this->output->writeln(
379 "Done. Restored {$createdAliasCount} custom URL alias(es) " .
380 "with {$conflictCount} conflict(s)."
381 );
382 $this->output->writeln('');
383 }
384
393 protected function loadPassData(QueryBuilder $queryBuilder, $pass)
394 {
395 $queryBuilder->setFirstResult($pass * $this->bulkCount);
396 $queryBuilder->setMaxResults($this->bulkCount);
397
398 $statement = $queryBuilder->execute();
399
400 $rows = $statement->fetchAll(PDO::FETCH_ASSOC);
401
402 return $rows;
403 }
404
412 protected function storeCustomAliases(array $aliases)
413 {
414 $pathCount = 0;
415
416 foreach ($aliases as $alias) {
417 $paths = $this->combinePaths($alias->pathData);
418 $pathCount += count($paths);
419
420 foreach ($paths as $path) {
421 $this->storeCustomAliasPath(
422 $alias->destination,
423 $path,
424 reset($alias->languageCodes),
425 $alias->alwaysAvailable,
426 $alias->forward
427 );
428 }
429 }
430
431 return $pathCount;
432 }
433
443 protected function storeCustomAliasPath(
444 $locationId,
445 $path,
446 $languageCode,
447 $alwaysAvailable,
448 $forwarding
449 ) {
450 $queryBuilder = $this->connection->createQueryBuilder();
451
452 $queryBuilder->insert(static::CUSTOM_ALIAS_BACKUP_TABLE);
453 $queryBuilder->values(
454 [
455 'id' => '?',
456 'location_id' => '?',
457 'path' => '?',
458 'language_code' => '?',
459 'always_available' => '?',
460 'forwarding' => '?',
461 ]
462 );
463 $queryBuilder->setParameter(0, 0);
464 $queryBuilder->setParameter(1, $locationId);
465 $queryBuilder->setParameter(2, $path);
466 $queryBuilder->setParameter(3, $languageCode);
467 $queryBuilder->setParameter(4, (int)$alwaysAvailable);
468 $queryBuilder->setParameter(5, (int)$forwarding);
469
470 $queryBuilder->execute();
471 }
472
497 protected function combinePaths(array $pathData)
498 {
499 $paths = [];
500 $levelData = array_shift($pathData);
501 $levelElements = $this->extractPathElements($levelData);
502
503 if (!empty($pathData)) {
504 $nextElements = $this->combinePaths($pathData);
505
506 foreach ($levelElements as $element1) {
507 foreach ($nextElements as $element2) {
508 $paths[] = $element1 . '/' . $element2;
509 }
510 }
511
512 return $paths;
513 }
514
515 return $levelElements;
516 }
517
525 protected function extractPathElements(array $levelData)
526 {
527 $elements = [];
528
529 if (isset($levelData['translations']['always-available'])) {
530 // NOP entry
531 $elements[] = $levelData['translations']['always-available'];
532 } else {
533 // Language(s) entry
534 $elements = array_values($levelData['translations']);
535 }
536
537 return $elements;
538 }
539
543 protected function generateLocationAliases()
544 {
545 $tableName = static::MIGRATION_TABLE;
546
547 if (!$this->tableExists($tableName)) {
548 throw new RuntimeException(
549 "Could not find main URL alias migration table '{$tableName}'. " .
550 'Ensure that table exists (you will have to create it manually).'
551 );
552 }
553
554 if (!$this->isTableEmpty($tableName)) {
555 throw new RuntimeException("Table '{$tableName}' contains data.");
556 }
557
558 $this->doGenerateLocationAliases();
559 }
560
566 protected function doGenerateLocationAliases()
567 {
568 $totalLocationCount = $this->getTotalLocationCount();
569 $totalContentCount = $this->getTotalLocationContentCount();
570 $passCount = ceil($totalLocationCount / $this->bulkCount);
571 $publishedAliasCount = 0;
572
573 if ($totalLocationCount === 0) {
574 $this->output->writeln('Could not find any Locations, nothing to generate.');
575 $this->output->writeln('');
576
577 return;
578 }
579
580 $queryBuilder = $this->connection->createQueryBuilder();
581 $queryBuilder
582 ->select('node_id', 'parent_node_id', 'contentobject_id')
583 ->from('ezcontentobject_tree')
584 ->where($queryBuilder->expr()->neq('node_id', 1))
585 ->orderBy('depth', 'ASC')
586 ->addOrderBy('node_id', 'ASC');
587
588 $this->output->writeln(
589 "Publishing URL aliases for {$totalLocationCount} Location(s) " .
590 "with {$totalContentCount} Content item(s) in all languages."
591 );
592
593 $progressBar = $this->getProgressBar($totalLocationCount);
594 $progressBar->start();
595
596 for ($pass = 0; $pass <= $passCount; ++$pass) {
597 $rows = $this->loadLocationData($queryBuilder, $pass);
598
599 foreach ($rows as $row) {
600 $publishedAliasCount += $this->publishAliases(
601 $row['node_id'],
602 $row['parent_node_id'],
603 $row['contentobject_id']
604 );
605 }
606
607 $progressBar->advance(count($rows));
608 }
609
610 $progressBar->finish();
611
612 $this->output->writeln('');
613 $this->output->writeln("Done. Published {$publishedAliasCount} URL alias(es).");
614 $this->output->writeln('');
615 }
616
620 protected function backupGlobalAliases()
621 {
622 $table = static::GLOBAL_ALIAS_BACKUP_TABLE;
623
624 if (!$this->tableExists($table)) {
625 $this->createGlobalUrlAliasBackupTable();
626 }
627
628 if (!$this->isTableEmpty($table)) {
629 throw new RuntimeException(
630 "Table '{$table}' contains data. " .
631 "Ensure it's empty or non-existent (it will be automatically created)."
632 );
633 }
634
635 $this->doBackupGlobalAliases();
636 }
637
643 protected function doBackupGlobalAliases()
644 {
645 $aliases = $this->urlAliasHandler->listGlobalURLAliases();
646 $totalCount = count($aliases);
647 $pathCount = 0;
648
649 if ($totalCount === 0) {
650 $this->output->writeln('Could not find any global URL aliases, nothing to backup.');
651 $this->output->writeln('');
652
653 return;
654 }
655
656 $this->output->writeln("Backing up {$totalCount} global URL aliases.");
657
658 $progressBar = $this->getProgressBar($totalCount);
659 $progressBar->start();
660
661 foreach ($aliases as $alias) {
662 $pathCount += $this->storeGlobalAlias($alias);
663 $progressBar->advance();
664 }
665
666 $progressBar->finish();
667
668 $this->output->writeln('');
669 $this->output->writeln(
670 "Done. Backed up {$totalCount} global URL alias(es) " .
671 "with {$pathCount} path(s)."
672 );
673 $this->output->writeln('');
674 }
675
683 protected function storeGlobalAlias(UrlAlias $alias)
684 {
685 $paths = $this->combinePaths($alias->pathData);
686
687 foreach ($paths as $path) {
688 $this->storeGlobalAliasPath(
689 $alias->destination,
690 $path,
691 reset($alias->languageCodes),
692 $alias->alwaysAvailable,
693 $alias->forward
694 );
695 }
696
697 return count($paths);
698 }
699
709 protected function storeGlobalAliasPath(
710 $resource,
711 $path,
712 $languageCode,
713 $alwaysAvailable,
714 $forwarding
715 ) {
716 $queryBuilder = $this->connection->createQueryBuilder();
717
718 $queryBuilder->insert(static::GLOBAL_ALIAS_BACKUP_TABLE);
719 $queryBuilder->values(
720 [
721 'id' => '?',
722 'resource' => '?',
723 'path' => '?',
724 'language_code' => '?',
725 'always_available' => '?',
726 'forwarding' => '?',
727 ]
728 );
729 $queryBuilder->setParameter(0, 0);
730 $queryBuilder->setParameter(1, 'module:' . $resource);
731 $queryBuilder->setParameter(2, $path);
732 $queryBuilder->setParameter(3, $languageCode);
733 $queryBuilder->setParameter(4, (int)$alwaysAvailable);
734 $queryBuilder->setParameter(5, (int)$forwarding);
735
736 $queryBuilder->execute();
737 }
738
742 protected function restoreGlobalAliases()
743 {
744 $table = static::MIGRATION_TABLE;
745 $backupTable = static::GLOBAL_ALIAS_BACKUP_TABLE;
746
747 if (!$this->tableExists($table)) {
748 throw new RuntimeException(
749 "Could not find main URL alias migration table '{$table}'. " .
750 'Ensure that table exists (you will have to create it manually).'
751 );
752 }
753
754 if (!$this->tableExists($backupTable)) {
755 throw new RuntimeException(
756 "Could not find global URL alias backup table '$backupTable'. " .
757 "Ensure that table is created by 'backup-global' action."
758 );
759 }
760
761 $this->doRestoreGlobalAliases();
762 }
763
769 protected function doRestoreGlobalAliases()
770 {
771 $totalCount = $this->getTotalBackupCount(static::GLOBAL_ALIAS_BACKUP_TABLE);
772 $passCount = ceil($totalCount / $this->bulkCount);
773 $createdAliasCount = 0;
774 $conflictCount = 0;
775
776 if ($totalCount === 0) {
777 $this->output->writeln(
778 'Could not find any backed up global URL aliases, nothing to restore.'
779 );
780 $this->output->writeln('');
781
782 return;
783 }
784
785 $queryBuilder = $this->connection->createQueryBuilder();
786 $queryBuilder
787 ->select('*')
788 ->from(static::GLOBAL_ALIAS_BACKUP_TABLE)
789 ->orderBy('id', 'ASC');
790
791 $this->output->writeln("Restoring {$totalCount} custom URL alias(es).");
792
793 $progressBar = $this->getProgressBar($totalCount);
794 $progressBar->start();
795
796 for ($pass = 0; $pass <= $passCount; ++$pass) {
797 $rows = $this->loadPassData($queryBuilder, $pass);
798
799 foreach ($rows as $row) {
800 try {
801 $this->setMigrationTable();
802 $this->urlAliasHandler->createGlobalUrlAlias(
803 $row['resource'],
804 $row['path'],
805 (bool)$row['forwarding'],
806 $row['language_code'],
807 (bool)$row['always_available']
808 );
809 ++$createdAliasCount;
810 $this->setDefaultTable();
811 } catch (ForbiddenException $e) {
812 ++$conflictCount;
813 } catch (Exception $e) {
814 $this->setDefaultTable();
815 throw $e;
816 }
817 }
818
819 $progressBar->advance(count($rows));
820 }
821
822 $progressBar->finish();
823
824 $this->output->writeln('');
825 $this->output->writeln(
826 "Done. Restored {$createdAliasCount} custom URL alias(es) " .
827 "with {$conflictCount} conflict(s)."
828 );
829 $this->output->writeln('');
830 }
831
843 protected function publishAliases($locationId, $parentLocationId, $contentId)
844 {
845 $content = $this->contentService->loadContent($contentId);
846
847 $urlAliasNames = $this->nameSchemaResolver->resolveUrlAliasSchema($content);
848
849 foreach ($urlAliasNames as $languageCode => $name) {
850 try {
851 $this->setMigrationTable();
852 $this->urlAliasHandler->publishUrlAliasForLocation(
853 $locationId,
854 $parentLocationId,
855 $name,
856 $languageCode,
857 $content->contentInfo->alwaysAvailable
858 );
859 $this->setDefaultTable();
860 } catch (Exception $e) {
861 $this->setDefaultTable();
862 throw $e;
863 }
864 }
865
866 return count($urlAliasNames);
867 }
868
877 protected function loadLocationData(QueryBuilder $queryBuilder, $pass)
878 {
879 $queryBuilder->setFirstResult($pass * $this->bulkCount);
880 $queryBuilder->setMaxResults($this->bulkCount);
881
882 $statement = $queryBuilder->execute();
883
884 $rows = $statement->fetchAll(PDO::FETCH_ASSOC);
885
886 return $rows;
887 }
888
894 protected function getTotalLocationCount()
895 {
896 $platform = $this->connection->getDatabasePlatform();
897
898 $queryBuilder = $this->connection->createQueryBuilder();
899 $queryBuilder
900 ->select($platform->getCountExpression('node_id'))
901 ->from('ezcontentobject_tree')
902 ->where(
903 $queryBuilder->expr()->neq(
904 'node_id',
905 UrlAliasHandler::ROOT_LOCATION_ID
906 )
907 );
908
909 return $queryBuilder->execute()->fetchColumn();
910 }
911
917 protected function getTotalLocationContentCount()
918 {
919 $platform = $this->connection->getDatabasePlatform();
920
921 $queryBuilder = $this->connection->createQueryBuilder();
922 $queryBuilder
923 ->select($platform->getCountExpression('DISTINCT contentobject_id'))
924 ->from('ezcontentobject_tree')
925 ->where(
926 $queryBuilder->expr()->neq(
927 'node_id',
928 UrlAliasHandler::ROOT_LOCATION_ID
929 )
930 );
931
932 return $queryBuilder->execute()->fetchColumn();
933 }
934
942 protected function getTotalBackupCount($table)
943 {
944 $platform = $this->connection->getDatabasePlatform();
945
946 $queryBuilder = $this->connection->createQueryBuilder();
947 $queryBuilder
948 ->select($platform->getCountExpression('id'))
949 ->from($table);
950
951 return (int)$queryBuilder->execute()->fetchColumn();
952 }
953
957 protected function createCustomLocationUrlAliasBackupTable()
958 {
959 $schema = new Schema();
960
961 $table = $schema->createTable(static::CUSTOM_ALIAS_BACKUP_TABLE);
962
963 $table->addColumn('id', 'integer', ['autoincrement' => true]);
964 $table->addColumn('location_id', 'integer');
965 $table->addColumn('path', 'text');
966 $table->addColumn('language_code', 'string');
967 $table->addColumn('always_available', 'integer');
968 $table->addColumn('forwarding', 'integer');
969 $table->setPrimaryKey(['id']);
970
971 $queries = $schema->toSql($this->connection->getDatabasePlatform());
972
973 foreach ($queries as $query) {
974 $this->connection->exec($query);
975 }
976 }
977
981 protected function createGlobalUrlAliasBackupTable()
982 {
983 $schema = new Schema();
984
985 $table = $schema->createTable(static::GLOBAL_ALIAS_BACKUP_TABLE);
986
987 $table->addColumn('id', 'integer', ['autoincrement' => true]);
988 $table->addColumn('resource', 'text');
989 $table->addColumn('path', 'text');
990 $table->addColumn('language_code', 'string');
991 $table->addColumn('always_available', 'integer');
992 $table->addColumn('forwarding', 'integer');
993 $table->setPrimaryKey(['id']);
994
995 $queries = $schema->toSql($this->connection->getDatabasePlatform());
996
997 foreach ($queries as $query) {
998 $this->connection->exec($query);
999 }
1000 }
1001
1009 protected function tableExists($name)
1010 {
1011 return $this->connection->getSchemaManager()->tablesExist([$name]);
1012 }
1013
1021 protected function isTableEmpty($name)
1022 {
1023 $queryBuilder = $this->connection->createQueryBuilder();
1024 $queryBuilder
1025 ->select($this->connection->getDatabasePlatform()->getCountExpression('*'))
1026 ->from($name);
1027
1028 $count = $queryBuilder->execute()->fetchColumn();
1029
1030 return $count == 0;
1031 }
1032
1040 protected function getProgressBar($maxSteps)
1041 {
1042 $progressBar = new ProgressBar($this->output, $maxSteps);
1043 $progressBar->setFormat(
1044 ' %current%/%max% [%bar%] %percent:3s%% %elapsed:6s%/%estimated:-6s% %memory:6s%'
1045 );
1046
1047 return $progressBar;
1048 }
1049 }
eZ\Bundle\EzPublishMigrationBundle\Command\LegacyStorage\RegenerateUrlAliasesCommand
Definition: EzPublishMigrationBundle/Command/LegacyStorage/RegenerateUrlAliasesCommand.php:29
eZ\Bundle\EzPublishMigrationBundle\Command\LegacyStorage\RegenerateUrlAliasesCommand\storeCustomAliasPath
storeCustomAliasPath( $locationId, $path, $languageCode, $alwaysAvailable, $forwarding)
Stores custom URL alias data for $path to the backup table.
Definition: EzPublishMigrationBundle/Command/LegacyStorage/RegenerateUrlAliasesCommand.php:443
eZ\Bundle\EzPublishMigrationBundle\Command\LegacyStorage\RegenerateUrlAliasesCommand\publishAliases
publishAliases($locationId, $parentLocationId, $contentId)
Publishes URL aliases in all languages for the given parameters.
Definition: EzPublishMigrationBundle/Command/LegacyStorage/RegenerateUrlAliasesCommand.php:843
eZ\Bundle\EzPublishMigrationBundle\Command\LegacyStorage\RegenerateUrlAliasesCommand\tableExists
tableExists($name)
Checks if database table $name exists.
Definition: EzPublishMigrationBundle/Command/LegacyStorage/RegenerateUrlAliasesCommand.php:1009
eZ\Bundle\EzPublishMigrationBundle\Command\LegacyStorage\RegenerateUrlAliasesCommand\loadPassData
loadPassData(QueryBuilder $queryBuilder, $pass)
Loads Location data for the given $pass.
Definition: EzPublishMigrationBundle/Command/LegacyStorage/RegenerateUrlAliasesCommand.php:393
eZ\Bundle\EzPublishMigrationBundle\Command\LegacyStorage\RegenerateUrlAliasesCommand\doRestoreCustomLocationAliases
doRestoreCustomLocationAliases()
Restores custom Location URL aliases from the backup table.
Definition: EzPublishMigrationBundle/Command/LegacyStorage/RegenerateUrlAliasesCommand.php:322
eZ\Bundle\EzPublishMigrationBundle\Command\LegacyStorage\RegenerateUrlAliasesCommand\isTableEmpty
isTableEmpty($name)
Checks if database table $name is empty.
Definition: EzPublishMigrationBundle/Command/LegacyStorage/RegenerateUrlAliasesCommand.php:1021
eZ\Bundle\EzPublishMigrationBundle\Command\LegacyStorage\RegenerateUrlAliasesCommand\doGenerateLocationAliases
doGenerateLocationAliases()
Internal method for generating URL aliases.
Definition: EzPublishMigrationBundle/Command/LegacyStorage/RegenerateUrlAliasesCommand.php:566
eZ\Bundle\EzPublishMigrationBundle\Command\LegacyStorage\RegenerateUrlAliasesCommand\$urlAliasGateway
$urlAliasGateway
Definition: EzPublishMigrationBundle/Command/LegacyStorage/RegenerateUrlAliasesCommand.php:44
eZ\Bundle\EzPublishMigrationBundle\Command\LegacyStorage\RegenerateUrlAliasesCommand\MIGRATION_TABLE
const MIGRATION_TABLE
Definition: EzPublishMigrationBundle/Command/LegacyStorage/RegenerateUrlAliasesCommand.php:30
eZ\Bundle\EzPublishMigrationBundle\Command\LegacyStorage\RegenerateUrlAliasesCommand\getTotalLocationContentCount
getTotalLocationContentCount()
Returns total number of Content objects having a Location in the database.
Definition: EzPublishMigrationBundle/Command/LegacyStorage/RegenerateUrlAliasesCommand.php:917
eZ\Bundle\EzPublishMigrationBundle\Command\LegacyStorage\RegenerateUrlAliasesCommand\GLOBAL_ALIAS_BACKUP_TABLE
const GLOBAL_ALIAS_BACKUP_TABLE
Definition: EzPublishMigrationBundle/Command/LegacyStorage/RegenerateUrlAliasesCommand.php:32
eZ\Bundle\EzPublishMigrationBundle\Command\LegacyStorage\RegenerateUrlAliasesCommand\$urlAliasHandler
$urlAliasHandler
Definition: EzPublishMigrationBundle/Command/LegacyStorage/RegenerateUrlAliasesCommand.php:41
eZ\Bundle\EzPublishMigrationBundle\Command\LegacyStorage\RegenerateUrlAliasesCommand\CUSTOM_ALIAS_BACKUP_TABLE
const CUSTOM_ALIAS_BACKUP_TABLE
Definition: EzPublishMigrationBundle/Command/LegacyStorage/RegenerateUrlAliasesCommand.php:31
eZ\Bundle\EzPublishMigrationBundle\Command\LegacyStorage\RegenerateUrlAliasesCommand\$connection
$connection
Definition: EzPublishMigrationBundle/Command/LegacyStorage/RegenerateUrlAliasesCommand.php:47
eZ\Bundle\EzPublishMigrationBundle\Command\LegacyStorage\RegenerateUrlAliasesCommand\$output
$output
Definition: EzPublishMigrationBundle/Command/LegacyStorage/RegenerateUrlAliasesCommand.php:53
eZ\Bundle\EzPublishMigrationBundle\Command\LegacyStorage\RegenerateUrlAliasesCommand\createGlobalUrlAliasBackupTable
createGlobalUrlAliasBackupTable()
Creates database table for custom URL alias backup.
Definition: EzPublishMigrationBundle/Command/LegacyStorage/RegenerateUrlAliasesCommand.php:981
eZ\Bundle\EzPublishMigrationBundle\Command\LegacyStorage\RegenerateUrlAliasesCommand\createCustomLocationUrlAliasBackupTable
createCustomLocationUrlAliasBackupTable()
Creates database table for custom Location URL alias backup.
Definition: EzPublishMigrationBundle/Command/LegacyStorage/RegenerateUrlAliasesCommand.php:957
eZ\Bundle\EzPublishMigrationBundle\Command\LegacyStorage\RegenerateUrlAliasesCommand\backupCustomLocationAliases
backupCustomLocationAliases()
Backups custom Location URL aliases the custom URL alias backup table.
Definition: EzPublishMigrationBundle/Command/LegacyStorage/RegenerateUrlAliasesCommand.php:216
eZ\Bundle\EzPublishMigrationBundle\Command\LegacyStorage\RegenerateUrlAliasesCommand\doBackupCustomLocationAliases
doBackupCustomLocationAliases()
Internal method for backing up custom Location URL aliases.
Definition: EzPublishMigrationBundle/Command/LegacyStorage/RegenerateUrlAliasesCommand.php:239
eZ\Bundle\EzPublishMigrationBundle\Command\LegacyStorage\RegenerateUrlAliasesCommand\doBackupGlobalAliases
doBackupGlobalAliases()
Internal method for backing up global URL aliases.
Definition: EzPublishMigrationBundle/Command/LegacyStorage/RegenerateUrlAliasesCommand.php:643
eZ\Bundle\EzPublishMigrationBundle\Command\LegacyStorage\RegenerateUrlAliasesCommand\execute
execute(InputInterface $input, OutputInterface $output)
Definition: EzPublishMigrationBundle/Command/LegacyStorage/RegenerateUrlAliasesCommand.php:111
eZ\Bundle\EzPublishMigrationBundle\Command\LegacyStorage\RegenerateUrlAliasesCommand\checkStorage
checkStorage()
Checks that configured storage engine is Legacy Storage Engine.
Definition: EzPublishMigrationBundle/Command/LegacyStorage/RegenerateUrlAliasesCommand.php:182
eZ\Bundle\EzPublishMigrationBundle\Command\LegacyStorage\RegenerateUrlAliasesCommand\restoreCustomLocationAliases
restoreCustomLocationAliases()
Restores custom Location URL aliases from the backup table.
Definition: EzPublishMigrationBundle/Command/LegacyStorage/RegenerateUrlAliasesCommand.php:295
eZ\Bundle\EzPublishMigrationBundle\Command\LegacyStorage\RegenerateUrlAliasesCommand\storeGlobalAlias
storeGlobalAlias(UrlAlias $alias)
Stores given global URL $alias to the global URL alias backup table.
Definition: EzPublishMigrationBundle/Command/LegacyStorage/RegenerateUrlAliasesCommand.php:683
eZ\Bundle\EzPublishMigrationBundle\Command\LegacyStorage\RegenerateUrlAliasesCommand\combinePaths
combinePaths(array $pathData)
Combines path data to an array of URL alias paths.
Definition: EzPublishMigrationBundle/Command/LegacyStorage/RegenerateUrlAliasesCommand.php:497
eZ\Bundle\EzPublishMigrationBundle\Command\LegacyStorage\RegenerateUrlAliasesCommand\backupGlobalAliases
backupGlobalAliases()
Backups global URL aliases the custom URL alias backup table.
Definition: EzPublishMigrationBundle/Command/LegacyStorage/RegenerateUrlAliasesCommand.php:620
eZ\Bundle\EzPublishMigrationBundle\Command\LegacyStorage\RegenerateUrlAliasesCommand\extractPathElements
extractPathElements(array $levelData)
Returns all path element strings found for the given path $levelData.
Definition: EzPublishMigrationBundle/Command/LegacyStorage/RegenerateUrlAliasesCommand.php:525
eZ\Bundle\EzPublishMigrationBundle\Command\LegacyStorage\RegenerateUrlAliasesCommand\$actionSet
$actionSet
Definition: EzPublishMigrationBundle/Command/LegacyStorage/RegenerateUrlAliasesCommand.php:55
eZ\Bundle\EzPublishMigrationBundle\Command\LegacyStorage\RegenerateUrlAliasesCommand\setMigrationTable
setMigrationTable()
Sets storage gateway to the migration table.
Definition: EzPublishMigrationBundle/Command/LegacyStorage/RegenerateUrlAliasesCommand.php:208
eZ\Bundle\EzPublishMigrationBundle\Command\LegacyStorage\RegenerateUrlAliasesCommand\$bulkCount
$bulkCount
Definition: EzPublishMigrationBundle/Command/LegacyStorage/RegenerateUrlAliasesCommand.php:50
eZ\Bundle\EzPublishMigrationBundle\Command\LegacyStorage\RegenerateUrlAliasesCommand\getTotalLocationCount
getTotalLocationCount()
Returns total number of Locations in the database.
Definition: EzPublishMigrationBundle/Command/LegacyStorage/RegenerateUrlAliasesCommand.php:894
eZ\Bundle\EzPublishMigrationBundle\Command\LegacyStorage\RegenerateUrlAliasesCommand\loadLocationData
loadLocationData(QueryBuilder $queryBuilder, $pass)
Loads Location data for the given $pass.
Definition: EzPublishMigrationBundle/Command/LegacyStorage/RegenerateUrlAliasesCommand.php:877
eZ\Bundle\EzPublishMigrationBundle\Command\LegacyStorage\RegenerateUrlAliasesCommand\setDefaultTable
setDefaultTable()
Sets storage gateway to the default table.
Definition: EzPublishMigrationBundle/Command/LegacyStorage/RegenerateUrlAliasesCommand.php:198
eZ\Bundle\EzPublishMigrationBundle\Command\LegacyStorage\RegenerateUrlAliasesCommand\configure
configure()
Definition: EzPublishMigrationBundle/Command/LegacyStorage/RegenerateUrlAliasesCommand.php:64
eZ\Bundle\EzPublishMigrationBundle\Command\LegacyStorage\RegenerateUrlAliasesCommand\storeCustomAliases
storeCustomAliases(array $aliases)
Stores given custom $aliases to the custom alias backup table.
Definition: EzPublishMigrationBundle/Command/LegacyStorage/RegenerateUrlAliasesCommand.php:412
eZ\Bundle\EzPublishMigrationBundle\Command\LegacyStorage\RegenerateUrlAliasesCommand\$contentService
$contentService
Definition: EzPublishMigrationBundle/Command/LegacyStorage/RegenerateUrlAliasesCommand.php:35
eZ\Bundle\EzPublishMigrationBundle\Command\LegacyStorage\RegenerateUrlAliasesCommand\doRestoreGlobalAliases
doRestoreGlobalAliases()
Restores global URL aliases from the backup table.
Definition: EzPublishMigrationBundle/Command/LegacyStorage/RegenerateUrlAliasesCommand.php:769
eZ\Bundle\EzPublishMigrationBundle\Command\LegacyStorage\RegenerateUrlAliasesCommand\generateLocationAliases
generateLocationAliases()
Generates URL aliases from the Location and Content data to the migration table.
Definition: EzPublishMigrationBundle/Command/LegacyStorage/RegenerateUrlAliasesCommand.php:543
eZ\Bundle\EzPublishMigrationBundle\Command\LegacyStorage\RegenerateUrlAliasesCommand\storeGlobalAliasPath
storeGlobalAliasPath( $resource, $path, $languageCode, $alwaysAvailable, $forwarding)
Stores global URL alias data for $path to the backup table.
Definition: EzPublishMigrationBundle/Command/LegacyStorage/RegenerateUrlAliasesCommand.php:709
eZ\Bundle\EzPublishMigrationBundle\Command\LegacyStorage\RegenerateUrlAliasesCommand\getTotalBackupCount
getTotalBackupCount($table)
Return the number of rows in the given $table (on ID column).
Definition: EzPublishMigrationBundle/Command/LegacyStorage/RegenerateUrlAliasesCommand.php:942
eZ\Bundle\EzPublishMigrationBundle\Command\LegacyStorage\RegenerateUrlAliasesCommand\restoreGlobalAliases
restoreGlobalAliases()
Restores global URL aliases from the backup table.
Definition: EzPublishMigrationBundle/Command/LegacyStorage/RegenerateUrlAliasesCommand.php:742
eZ\Bundle\EzPublishMigrationBundle\Command\LegacyStorage\RegenerateUrlAliasesCommand\getProgressBar
getProgressBar($maxSteps)
Returns configured progress bar helper.
Definition: EzPublishMigrationBundle/Command/LegacyStorage/RegenerateUrlAliasesCommand.php:1040
eZ\Bundle\EzPublishMigrationBundle\Command\LegacyStorage\RegenerateUrlAliasesCommand\$nameSchemaResolver
$nameSchemaResolver
Definition: EzPublishMigrationBundle/Command/LegacyStorage/RegenerateUrlAliasesCommand.php:38
eZ\Publish\API\Repository\Exceptions\ForbiddenException
An Exception which is thrown if an operation cannot be performed by a service although the current us...
Definition: API/Repository/Exceptions/ForbiddenException.php:16
eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Handler
The UrlAlias Handler provides nice urls management.
Definition: Core/Persistence/Legacy/Content/UrlAlias/Handler.php:32
eZ\Publish\Core\Persistence\Legacy\Handler
The main handler for Legacy Storage Engine.
Definition: Core/Persistence/Legacy/Handler.php:32
eZ\Publish\SPI\Persistence\Content\UrlAlias
UrlAlias models one url alias path element separated by '/' in urls.
Definition: SPI/Persistence/Content/UrlAlias.php:17
eZ\Bundle\EzPublishMigrationBundle\Command\LegacyStorage
Definition: CleanUpRelationTypeEqZeroCommand.php:7
eZ\Publish\Core\Persistence\Legacy\Content\UrlAlias\Gateway
Definition: Persistence/Legacy/Content/UrlAlias/Gateway/DoctrineDatabase.php:7
eZ\Publish\SPI\Persistence\Content\UrlAlias
Definition: SPI/Persistence/Content/UrlAlias/Handler.php:7
Copyright © 1998 – 2026 7x. All rights reserved. Licensed under the GNU GPLv2+.