diff --git a/web/modules/custom/ballerup_d7_migration/scripts/webform_redirects.php b/web/modules/custom/ballerup_d7_migration/scripts/webform_redirects.php new file mode 100644 index 000000000..c96300641 --- /dev/null +++ b/web/modules/custom/ballerup_d7_migration/scripts/webform_redirects.php @@ -0,0 +1,194 @@ +getStorage('redirect'); + +$redirect_base_url = 'http://formular.ballerup.dk'; +$added = 0; +$skipped = 0; +$repository = \Drupal::service('redirect.repository'); + +foreach ($webform_urls as $url) { + $existing = $repository->findBySourcePath($url); + if (!empty($existing)) { + print_r('Redirect for URL ' . $url . ' already exists.' . PHP_EOL); + $skipped++; + continue; + } + + /** @var \Drupal\redirect\Entity\Redirect $redirect */ + $redirect = $storage->create(); + $redirect->setSource($url); + $redirect->setRedirect($redirect_base_url . '/' . $url); + $redirect->setStatusCode(301); + $redirect->save(); + print_r('Added redirect for URL ' . $url . PHP_EOL); + $added++; +} +print_r(sprintf('Webforms redirects adding finished: total: %d, added %d, skipped %d', count($webform_urls), $added, $skipped) . PHP_EOL); + + +