# CLI Scripts

> Command-line maintenance scripts

---

The module ships CLI-only scripts. They are guarded: requested over HTTP (the `modules_v4` directory is inside the web root) they answer `403` instead of running.

| Script | Purpose | Needs a webtrees install + DB? |
| --- | --- | --- |
| `cli/build-link-index.php [--limit=N] [--tree=<id>] [--rebuild] [--flush]` | build/update the link index for the XREF overview | yes |
| `cli/build-uid-index.php [--limit=N] [--tree=<id>] [--rebuild] [--flush] [--force]` | build/update the UID index for UID lookup | yes |
| `cli/refresh-wthb-toc.php [--all] [--lang=<list>] [--clear] [--force]` | refresh the WTHB table of contents cache ([production](wthb-toc-lang)) | yes |
| <a href="https://codeberg.org/bschwede/linkenhancer/src/branch/main/tests/test-text-tag-collector.php" target="_blank" rel="noopener"><code>test-text-tag-collector.php</code></a>
 | standalone unit tests for the text-tag collector | no |
| <a href="https://codeberg.org/bschwede/linkenhancer/src/branch/main/tests/test-link-classifier.php" target="_blank" rel="noopener"><code>test-link-classifier.php</code></a>
 | standalone unit tests for the link classifier (incl. target extraction) | no |
| <a href="https://codeberg.org/bschwede/linkenhancer/src/branch/main/tests/test-uid-tag-collector.php" target="_blank" rel="noopener"><code>test-uid-tag-collector.php</code></a>
 | standalone unit tests for the UID tag collector | no |
| <a href="https://codeberg.org/bschwede/linkenhancer/src/branch/main/tests/test-uid-index-service.php" target="_blank" rel="noopener"><code>test-uid-index-service.php</code></a>
 | standalone unit tests for the UID index service | no |
| `tests/smoke-text-tag-collector.php [limit]` | scan records containing enhanced links, print every captured value | yes |
| <a href="https://codeberg.org/bschwede/linkenhancer/src/branch/main/tests/smoke-migration5.php" target="_blank" rel="noopener"><code>smoke-migration5.php</code></a>
 | SQLite smoke test for Migration5 (UID index schema) | yes |
| `tests/p1-measure.php [--tree=<id>]` | read-only scaling measurement for the XREF overview | yes |

Run them from the webtrees root with the **same PHP version** the instance runs on (webtrees requires PHP 8.3+):

```bash
php modules_v4/linkenhancer/tests/test-text-tag-collector.php
php modules_v4/linkenhancer/tests/smoke-text-tag-collector.php 10
```

Cron example (every 2 hours, 500 records per run):

```
15 */2 * * * cd /path/to/webtrees && php modules_v4/linkenhancer/cli/<name>.php --limit=500 >> /var/log/linkenhancer-<name>.log 2>&1
```
