Feature/istwcms 6151 ocardena create redirection from wcsm2 to wcsm3
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
Activity
assigned to @cpettiro
added 1 commit
- e860ec16 - feature/ISTWCMS-6151-ocardena: fix logger dependency injection.
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. What do you think about using php array destructuring? Then we can use variable names like $nid and $tid just to make them easy to read and understand without context.
Hey @jpconsta the problem it's that the third argument just will exist if the entity is a taxonomy item so it will generate warnings for undefined key.
i could validate the entity type and then get those variables using array destructuring but i think the code will need to do more things for the same.
let me know what do you thing.
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) { changed this line in version 3 of the diff
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) { I think is missing \Exception here.
Edited by Joao Paulo Constantinochanged this line in version 3 of the diff
added 1 commit
- 3a18bf13 - feature/ISTWCMS-6151-ocardena: validate paths before TryCatch
requested review from @ibiki
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
Toggle commit list-
3a18bf13...e104ab7f - 18 commits from branch
mentioned in commit 04dd1b3d