Skip to content

Instantly share code, notes, and snippets.

@markisatacomputer
Last active May 7, 2018 21:13
Show Gist options
  • Save markisatacomputer/8785fac610bad335d9aa5ecff213ccac to your computer and use it in GitHub Desktop.
Save markisatacomputer/8785fac610bad335d9aa5ecff213ccac to your computer and use it in GitHub Desktop.
Bash script to return a report on referenced nodes
#!/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
@markisatacomputer
Copy link
Author

use like so:

./reference-report.sh test

NOTE: execution time is pretty dang crazy

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment