Wingman for Craft CMS

Wingman is a Craft 6 plugin. Craft 6 is still in beta, and so is Wingman (6.0.0-beta.1) — try it on staging first and use caution on production sites.

Health, backfill and orphans

Utilities → Wingman (and php artisan craft:wingman:status) shows, per model:

ColumnMeaning
RowsRows in the model's table, without global scopes, not counting soft-deleted rows
With elementsRows that have a live (not trashed) element
Missing elementsRows without one. Backfill fixes these
Orphaned linksElements whose row is gone, or that were never linked to a row

Backfill

Rows written before the model was registered, or written with raw queries that skip Eloquent's events, have no element. Backfill creates them:

  • in chunks, looking links up a chunk at a time;
  • without writing anything back to your rows (no updated_at bumps, no observers);
  • skipping rows that already have an element (live or trashed) and soft-deleted rows.

More than 500 missing elements, and the button says Queue backfill: the work goes to a queue job (one per model at a time) that reports progress in the Queue Manager. From the command line:

php artisan craft:wingman:backfill Customer --dry-run
php artisan craft:wingman:backfill Customer
php artisan craft:wingman:backfill --queue      # every model, as queue jobs

Orphans

Core keeps elements in step with Eloquent's events. A row deleted with a raw query, a truncate, or by another application never fires them, and its element is left behind. Delete orphans deletes those elements for good (there's no row to restore them from), along with their relations.

php artisan craft:wingman:cleanup Customer --dry-run
php artisan craft:wingman:cleanup Customer

Never counted as orphans:

  • elements of a soft-deleted row (the row still exists);
  • rows hidden by a global scope;
  • links to a different model type, such as after a morph map change. Their rows may well exist, so Wingman won't touch them.

More plugins

Pairs well with Wingman