Adopting & Checking Links
Adopting existing links #
If your Dub workspace already contains short links for your entries, created manually or before installing the plugin, you can hand them over to the plugin in one pass:
php craft dub/adopt
This matches each link to a Craft entry by its destination URL and sets the entry's externalId on the link, so the plugin manages it from then on. Matching uses the host and path together, so sites on separate domains or subdomains are told apart even when they share a path. A link is left alone if no entry matches, or if two sites on the same host share the path.
Unmatched links are listed, capped at the first ten with a count of the rest. Pass --show-unmatched to see them all, which is worth doing on a workspace holding domains this install does not manage.
Add --dry-run to preview what would be adopted without making any changes:
php craft dub/adopt --dry-run
If some of your Dub links point to an old path prefix, use --rewrite to remap the destination path when matching. It only applies as a fallback, when the link's original path matches no entry. Pass one or more comma-separated from=to prefixes:
php craft dub/adopt --rewrite="/areas-stages/=/venues/"
Checking existing links #
Saving an entry doesn't re-send a short link that hasn't moved, which keeps a resave cheap. The trade-off is that the plugin won't notice a link deleted or edited in the Dub dashboard, leaving the sidebar showing one that no longer resolves.
To find those:
php craft dub/check
It reports three things, and exits non-zero if any of them turn up, so it can be run from cron or CI:
- missing, meaning the link has been deleted at Dub
- drifted, meaning its slug or destination was edited at Dub
- stale, meaning it no longer points where its entry lives
Add --fix to repair missing and drifted links:
php craft dub/check --fix
Each side keeps what it owns. The destination comes from the entry, so Craft's value is pushed back to Dub. The slug belongs to Dub, since a rename there is deliberate and that URL is the one now in circulation, so it is adopted into Craft's record rather than reversed. A link that has gone from Dub entirely is recreated with the slug, destination and archived state Craft still holds, though its click history went with the original.
Stale links aren't repaired by --fix. A short link only moves when its entry is saved, so changing a site's Base URL or the Domain setting leaves existing links pointing at the old place. Nothing is wrong at Dub, and the repair is an ordinary resave:
php craft resave/entries
That sends one request per link that has actually moved, and nothing for the rest.
This is the counterpart to dub/adopt. Adoption brings links that exist at Dub under Craft's management, while dub/check looks the other way, at links Craft thinks it has.
From the control panel #
The same check has a screen at Utilities → Dub Links, for users who look after the links but have no terminal. It reports the same three findings, each named after its entry and linked to it, and Repair links does what --fix does.
It works through the links in batches, reporting as it goes, so a large workspace takes a while rather than running out of time. A run that fails partway leaves what it already found on screen.