Last active
March 8, 2018 14:15
-
-
Save bserem/60160a3d932ef69ec85ff7b7c1aa3ce8 to your computer and use it in GitHub Desktop.
Mass import redirects in Drupal 8 from CSV
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
i=0 | |
cat redir.csv| while read line | |
do | |
let "i++" | |
rsource=`echo $line | cut -d ',' -f1` | |
rtarget=`echo $line | cut -d ',' -f2` | |
redirect='use Drupal\redirect\Entity\Redirect;Redirect::create(["redirect_source" => "'$rsource | |
if [[ $rtarget = *"http"* ]]; then | |
redirect+='", "redirect_redirect" => "'$rtarget | |
else | |
redirect+='", "redirect_redirect" => "internal:'$rtarget | |
fi | |
redirect+='", "language" => "und", "status_code" => "301",])->save();' | |
#echo $redirect | |
drush ev "$redirect" | |
echo $i $rsource' to ' $rtarget ' added.' | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment