diff --git a/src/AliasTypeBatchUpdateInterface.php b/src/AliasTypeBatchUpdateInterface.php index 5f518ac..03f3929 100644 --- a/src/AliasTypeBatchUpdateInterface.php +++ b/src/AliasTypeBatchUpdateInterface.php @@ -21,7 +21,7 @@ interface AliasTypeBatchUpdateInterface extends AliasTypeInterface { public function batchUpdate($action, &$context); /** - * Gets called to batch delete all entries. + * Gets called to batch delete all aliases created by pathauto. * * @param array $context * Batch context. diff --git a/src/Plugin/pathauto/AliasType/EntityAliasTypeBase.php b/src/Plugin/pathauto/AliasType/EntityAliasTypeBase.php index 9412a93..121f04b 100644 --- a/src/Plugin/pathauto/AliasType/EntityAliasTypeBase.php +++ b/src/Plugin/pathauto/AliasType/EntityAliasTypeBase.php @@ -224,11 +224,11 @@ class EntityAliasTypeBase extends ContextAwarePluginBase implements AliasTypeInt } $query->range(0, 100); - $aliases = $query->execute()->fetchAll(\PDO::FETCH_ASSOC); + $pids_by_id = $query->execute()->fetchAllKeyed(); - $this->bulkDelete($aliases); - $context['sandbox']['count'] += count(array_values($aliases)); - $context['sandbox']['current'] = max(array_values($aliases)); + $this->bulkDelete($pids_by_id); + $context['sandbox']['count'] += count($pids_by_id); + $context['sandbox']['current'] = max($pids_by_id); $context['results']['deletions'][] = $this->getLabel(); if ($context['sandbox']['count'] != $context['sandbox']['total']) { @@ -281,23 +281,20 @@ class EntityAliasTypeBase extends ContextAwarePluginBase implements AliasTypeInt } /** - * Delete the URL aliases for multiple entities. + * Deletes the URL aliases for multiple entities. * - * @param array $aliases - * An array of entity aliases. Each alias is an array with two keys: id (the entity ID) and pid (the alias ID). + * @param int[] $pids_by_id + * A list of path IDs keyed by entity ID. */ - protected function bulkDelete(array $aliases) { - foreach ($aliases as $alias) { - $id_to_pid[$alias['id']] = $alias['pid']; - } - + protected function bulkDelete(array $pids_by_id) { $collection = 'pathauto_state.' . $this->getEntityTypeId(); - $states = $this->keyValue->get($collection)->getMultiple(array_keys($id_to_pid)); + $states = $this->keyValue->get($collection)->getMultiple(array_keys($pids_by_id)); - foreach (array_keys($id_to_pid) as $id) { - // Skip if pathauto processing is disabled. + $pids = []; + foreach ($pids_by_id as $id => $pid) { + // Only delete aliases that were created by this module. if (isset($states[$id]) && $states[$id] == PathautoState::CREATE) { - $pids[] = $id_to_pid[$id]; + $pids[] = $pid; } } \Drupal::service('pathauto.alias_storage_helper')->deleteMultiple($pids);