Last active
May 7, 2018 21:13
-
-
Save markisatacomputer/8785fac610bad335d9aa5ecff213ccac to your computer and use it in GitHub Desktop.
Bash script to return a report on referenced nodes
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 | |
# | |
# takes an argument of pantheon environment and | |
# returns output of all entites targeted in entityreference fields | |
# | |
# | |
# | |
PANTHEON_ENV="$1" | |
ALL=() | |
# 1. Get all the entity reference table names | |
referencefields=`drush @pantheon.exploratorium.$PANTHEON_ENV field-info fields | grep entityreference` | |
reftables=${referencefields//entityreference/} | |
# 2. Get entities referenced - one field at a time so we don't run out of memory... | |
query="select distinct n.nid, n.title from node as n" | |
for table in ${reftables}; do | |
qry="$query join field_data_${table} on n.nid = field_data_${table}.${table}_target_id" | |
while read nid name; do | |
ALL[nid]=$name | |
done < <($(drush @pantheon.exploratorium.$PANTHEON_ENV sql-connect) -e "${qry}" -rCN) | |
done | |
# 3. Print em all out | |
for i in "${!ALL[@]}"; do | |
printf "%s\t%s\n" "$i" "${ALL[$i]}" | |
done | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
use like so:
./reference-report.sh test
NOTE: execution time is pretty dang crazy