core/modules/path/src/Plugin/migrate/D7PathAliasDeriver.php | 11 +++++++---- core/modules/path/src/Plugin/migrate/source/d7/UrlAlias.php | 10 ++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/core/modules/path/src/Plugin/migrate/D7PathAliasDeriver.php b/core/modules/path/src/Plugin/migrate/D7PathAliasDeriver.php index 8a23b107a4..cb8bcc6091 100644 --- a/core/modules/path/src/Plugin/migrate/D7PathAliasDeriver.php +++ b/core/modules/path/src/Plugin/migrate/D7PathAliasDeriver.php @@ -104,9 +104,9 @@ public function getDerivativeDefinitions($base_plugin_definition) { $query->condition('n.nid', $inner_select, 'IN'); $query->groupBy('type'); $query->groupBy('name'); - // @todo use the count? $query->addExpression('COUNT(*)', 'count'); - $aliases_grouped_by_bundle = array_reduce($query->execute()->fetchAllAssoc('type'), function (array $carry, $row) { + $rows = $query->execute()->fetchAllAssoc('type'); + $aliases_grouped_by_bundle = array_reduce($rows, function (array $carry, $row) { $carry[$row->type] = $row->name; return $carry; }, []); @@ -121,9 +121,9 @@ public function getDerivativeDefinitions($base_plugin_definition) { $query->groupBy('vid'); $query->groupBy('machine_name'); $query->groupBy('name'); - // @todo use the count? $query->addExpression('COUNT(*)', 'count'); - $aliases_grouped_by_bundle = array_reduce($query->execute()->fetchAllAssoc('machine_name'), function (array $carry, $row) { + $rows = $query->execute()->fetchAllAssoc('machine_name'); + $aliases_grouped_by_bundle = array_reduce($rows, function (array $carry, $row) { $carry[$row->machine_name] = $row->name; return $carry; }, []); @@ -139,6 +139,9 @@ public function getDerivativeDefinitions($base_plugin_definition) { $this->derivatives[$derivative_id] = $base_plugin_definition; $this->derivatives[$derivative_id]['source']['entity_type_id'] = $entity_type_id; $this->derivatives[$derivative_id]['source']['bundle'] = $bundle_id; + if (isset($rows) && isset($rows[$bundle_id]) && isset($rows[$bundle_id]->count)) { + $this->derivatives[$derivative_id]['source']['__count_at_discovery_time'] = (int) $r[$bundle_id]->count; + } $this->derivatives[$derivative_id]['label'] = $this->t('@label of @type @entity-type-label', [ '@label' => $base_plugin_definition['label'], '@type' => $bundle_label, diff --git a/core/modules/path/src/Plugin/migrate/source/d7/UrlAlias.php b/core/modules/path/src/Plugin/migrate/source/d7/UrlAlias.php index 908dd5f5fe..390df7639b 100644 --- a/core/modules/path/src/Plugin/migrate/source/d7/UrlAlias.php +++ b/core/modules/path/src/Plugin/migrate/source/d7/UrlAlias.php @@ -17,6 +17,16 @@ class UrlAlias extends UrlAliasBase { use D7PathAliasDeriverTrait; + /** + * {@inheritdoc} + */ + public function count($refresh = FALSE) { + if (!$refresh && isset($this->migration->getSourceConfiguration()['__count_at_discovery_time'])) { + return $this->migration->getSourceConfiguration()['__count_at_discovery_time']; + } + return (int) $this->query()->countQuery()->execute()->fetchField(); + } + /** * {@inheritDoc} */