DB Query for Pages that use a Certain Fieldable Panel Pane (Drupal 7)

In Drupal 7, the DB structure of the panel-related tables has been hard to grasp (I am glad to see Drupal 8 cleaned up a lot of clutters and simplified its structure). If you look into it, it makes sense but it can be sketchy to figure something out. One of the things I looked into recently was to find node pages that use certain fieldable panel panes. Since a particular FFP creates some layout issues so that how many pages, I needed to search how many pages use it by querying DB directly. I’m on Pantheon; I can apply this query through a terminus + drush command.

$ terminus drush site.env -- sql-query "SELECT n.nid, ua.alias, sp.*, pp.pid, pp.did
FROM panelizer_entity pe
JOIN node n ON pe.entity_id = n.nid AND pe.entity_type = 'node' 
  AND n.vid = pe.revision_id
JOIN panels_pane pp ON pe.did = pp.did
JOIN (
  SELECT CONCAT('vuuid:', fv.vuuid) subtype, ff.fpid 
  FROM fieldable_panels_panes ff
  JOIN fieldable_panels_panes_revision fv 
    ON ff.vid = fv.vid AND ff.bundle = 'ffp name goes here..') sp 
  ON pp.subtype = sp.subtype
JOIN (
  SELECT alias, SUBSTRING(source, LOCATE('/', source)+1) entity_id 
  FROM url_alias WHERE source LIKE 'node%') ua
  ON n.nid = ua.entity_id
WHERE n.status = 1 
GROUP BY n.nid, pp.pid"

Leave a comment