Skip to content
Snippets Groups Projects

Feature/istwcms 6151 ocardena create redirection from wcsm2 to wcsm3

3 unresolved threads

Summary of changes:

  • Refactor MigrateSubscriber class to have each functionality on a different method.
  • Create a new method to create redirections for taxonomies and nodes entities.

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
126 }
127
128 /**
129 * Updates the entity alias and creates a redirect if needed.
130 *
131 * This function updates the alias of a given entity and creates a redirect
132 * from the old alias to the new one. It takes into consideration the pathauto
133 * state of the entity.
134 *
135 * @param object $entity
136 * The entity to update the alias for.
137 * @param object $row
138 * The migration row containing the old path information.
139 */
140 public function updateEntityAlias($entity, $row) {
85 141 // Get old entity id.
  • 170 *
    171 * @param object $entity
    172 * The entity for which the redirect is being created.
    173 * @param string $old_alias
    174 * The old alias path to redirect from.
    105 175 */
    106 public static function getSubscribedEvents() {
    107 return [
    108 MigrateEvents::POST_ROW_SAVE => ['onPostRowSave'],
    109 ];
    176 public function updateAliasRedirect($entity, $old_alias) {
    177 // Get new alias and create redirection from old path to new path.
    178 $entity = $this->entityTypeManager->getStorage($entity->getEntityTypeId())->load($entity->id());
    179 $new_alias = $entity->path->alias;
    180 try {
    181 if ($new_alias !== $old_alias) {
  • 178 $entity = $this->entityTypeManager->getStorage($entity->getEntityTypeId())->load($entity->id());
    179 $new_alias = $entity->path->alias;
    180 try {
    181 if ($new_alias !== $old_alias) {
    182 $entity_path = $entity->getEntityTypeId() == 'node' ? $entity->getEntityTypeId() : 'taxonomy/term';
    183 // Create a redirect from the old alias to the new alias.
    184 $redirect = Redirect::create([
    185 'redirect_source' => substr($old_alias, 1),
    186 'redirect_redirect' => 'internal:/' . $entity_path . '/' . $entity->id(),
    187 'language' => $entity->language()->getId(),
    188 'status_code' => 301,
    189 ]);
    190 $redirect->save();
    191 }
    192 }
    193 catch (Exception $e) {
  • Ozle Cardenas added 1 commit

    added 1 commit

    • 3a18bf13 - feature/ISTWCMS-6151-ocardena: validate paths before TryCatch

    Compare with previous version

  • Ozle Cardenas assigned to @ibiki and unassigned @jpconsta

    assigned to @ibiki and unassigned @jpconsta

  • Ozle Cardenas requested review from @ibiki

    requested review from @ibiki

  • Eric Bremner added 22 commits

    added 22 commits

    • 3a18bf13...e104ab7f - 18 commits from branch 1.0.x
    • 732b4496 - feature/ISTWCMS-6151-ocardena: create redirections from wcsm2 to wcsm3
    • f7c8d102 - feature/ISTWCMS-6151-ocardena: create redirects after save new aliases.
    • cdc62ee0 - feature/ISTWCMS-6151-ocardena: fix logger dependency injection.
    • 2a20ced0 - feature/ISTWCMS-6151-ocardena: validate paths before TryCatch

    Compare with previous version

  • Eric Bremner added 1 commit

    added 1 commit

    • d576181a - ISTWCMS-6151: coding standards

    Compare with previous version

  • Eric Bremner mentioned in commit 04dd1b3d

    mentioned in commit 04dd1b3d

  • merged

  • Please register or sign in to reply
    Loading