- Issue created by @kwfinken
I am trying to use this to programmatically create redirects that don't exist, so I execute the following code:
<?php use Drupal\redirect\Entity\Redirect as redirectEntity; use Drupal\redirect\RedirectRepository; //... other stuff $allLimitingInterfaces = $limitingInterfacesQuery->execute()->fetchAll(); //add redirects for all old style queries $redirectRepository = \Drupal::service('redirect.repository'); foreach($allLimitingInterfaces as $LI){ if(is_null($redirectRepository->findMatchingRedirect('/tgif/limiting', ['interface' => $LI->SearchQueryString],Language::LANGCODE_NOT_SPECIFIED))) { $redirect = redirectEntity::create(); $redirect->setSource('tgif/limiting', ['interface' => $LI->SearchQueryString]); $redirect->setRedirect(Url::fromRoute('msul_tgif_star_xml_client.limiting_interface',['interfaceName'=>$LI->SearchQueryString])->toString()); $redirect->setLanguage = Language::LANGCODE_NOT_SPECIFIED; $redirect->setStatusCode('301'); $redirect->save(); } }
The first time through, everything seems to work, the redirects are created and they work; but on subsequent executions, the findMatchingRedirect
returns null even for all the redirects that were created in the previous run, thus causing an error when it tries to recreate an existing redirect.
Looking in the DB, it appears that the hash generated when the entity is created when does not match the hash generated within the findMatchingRedirect method, so the query in /src/RedirectRepository.php line 81 is returning null.
Active
1.9
Code