PHPackages                             dbrabon/file\_adoption - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [File &amp; Storage](/categories/file-storage)
4. /
5. dbrabon/file\_adoption

ActiveDrupal-module[File &amp; Storage](/categories/file-storage)

dbrabon/file\_adoption
======================

Scans the public file directory for orphaned files and adopts them as managed file entities.

v1.4.6(9mo ago)0243↓100%GPL-2.0-or-laterPHPPHP ^8.1

Since Jun 18Pushed 9mo agoCompare

[ Source](https://github.com/dbrabon/file_adoption)[ Packagist](https://packagist.org/packages/dbrabon/file_adoption)[ RSS](/packages/dbrabon-file-adoption/feed)WikiDiscussions main Synced 1mo ago

READMEChangelogDependencies (2)Versions (398)Used By (0)

File Adoption
=============

[](#file-adoption)

File Adoption is a utility module for Drupal that scans the public files directory for files that are not tracked by Drupal's `file_managed` table. Identified "orphaned" files can be registered as managed file entities.

Installation
------------

[](#installation)

1. Place the module in your Drupal installation, typically using Composer: ```
    composer require dbrabon/file_adoption
    ```

    or by copying the module into `modules/custom`.
2. Enable the module from the **Extend** page or with Drush: ```
    ```

drush en file\_adoption

```
 The first cron run after installation automatically performs a full scan of
 `public://`. Run `drush cron` if you want results immediately.
3. Navigate to **Administration → Reports → File Adoption** (`/admin/reports/file-adoption`)
 to configure settings or review the most recent scan results. The page no
 longer runs a scan automatically.

## Configuration

The configuration form offers the following options:

- **Ignore Patterns** – Comma or newline separated patterns relative to
`public://` that should be skipped when scanning. Patterns may contain simple
wildcards (`*`, `?`) which are automatically converted to regular
expressions when the form is saved. The default configuration skips
directories such as:

```

/. public://asset\_injector/.\* public://config\_.\* public://css/.\* public://embed\_buttons/.\* public://favicon.ico public://js/.\* public://media-icons/.\* public://media-youtube/.\* public://oembed\_thumbnails/.\* public://php/.\* public://styles/.\* public://webforms/.\*

```

- Pattern matching is case-insensitive.
- **Enable Adoption** – Automatically adopts up to the number in **Items per adoption batch** during each cron run using the configured settings.
- **Items per adoption batch** – Maximum number of files adopted or displayed per
scan or cron run. All discovered orphans are saved regardless of this
limit. Defaults to 20.
- **Adopt as Temporary** – When checked, newly adopted files are saved as
temporary. Unchecked files become permanent immediately.
- **Ignore Symlinks** – When enabled, symbolic links are skipped during scanning,
preventing loops or slowdowns caused by symlinks.
Symlinks discovered during scanning are still listed under the "Symlinks"
- **Directory Depth** – Maximum directory depth displayed under "Directories".
Directories deeper than this setting are omitted from the summary but files
within them can still be adopted. Valid range is 1–9 and the default is 9.
- **Full-scan interval (hours)** – Number of hours between automatic full scans.
  Set to `0` to run on every cron run. The default is 24 hours.
- **Verbose Logging** – When enabled, additional debug information is written to
the log during scans and adoption. This is off by default. Adoption success
messages are only recorded when verbose logging is enabled. When enabled,
each directory encountered during cron scans is also logged.

The configuration page also shows details gathered from the most recent scan:

- **Directories** – Lists every directory discovered. Directories marked as
ignored are annotated with “(ignored)” and any ignored file names appear in
parentheses. This information is read from the `file_adoption_index` table.
- **Add to Managed Files** – Displays the files scheduled for adoption. Entries
are pulled directly from the `file_adoption_index` table after filtering out
ignored directories and patterns.
- **Run full scan** – Button at the bottom of the form that immediately
executes a full cron-style scan of the public files directory.

Changes are stored in `file_adoption.settings`.

## Cron Integration

Scanning occurs exclusively during cron runs. Upon installation a state flag
causes the next cron run to perform an immediate full scan. The *Full-scan interval* setting
controls how often `hook_cron()` invokes the `FileScanner` service. Each run
records its totals to state so the configuration page can report the last
execution. When **Enable Adoption** is disabled the run simply updates the
`file_adoption_index` table with any discovered orphans. When adoption is
enabled, matching files are registered immediately. Every cron run rebuilds the
`file_adoption_index` table so the most current data is always available.

## Running Tests

These tests rely on Drupal's core testing environment. Install the
development dependencies with Composer so that `drupal/core-dev` and
`phpunit/phpunit` are available. Tests should be executed from the Drupal
project root so that Drupal's PHPUnit configuration is used.

From the module directory you can run:

```bash
../vendor/bin/phpunit -c core modules/custom/file_adoption

```

The tests are located under the `tests/` directory and include kernel tests for the `FileScanner` service and the configuration form.

Uninstall
---------

[](#uninstall)

Uninstalling the module removes all configuration and drops the `file_adoption_index` table so no leftover data remains. If the table ever contains bad data simply uninstall and reinstall the module to rebuild it.

### v2.0.0 – 2025‑07‑11

[](#v200-20250711)

- **Replaced** orphan tracking table – the single `file_adoption_index` table now holds everything:
    - `is_managed` → present in file\_managed
    - `is_ignored` → matches an admin‑defined regex ignore pattern
    - `directory_depth` → number of “/” in the public:// relative path
- Ignore patterns accept full **Perl‑compatible regular expressions** and may include simple wildcards which are converted to regex when the configuration is saved.
- Cron and the “Adopt Now” button both adopt files by selecting `is_managed = 0 AND is_ignored = 0`, up to **Items per adoption batch**.
- The admin UI pulls its *Directories* and *Add to Managed Files* sections directly from `file_adoption_index`, so results appear even while a long full‑disk scan is still running.
- Database update 10012 will:
    1. Drop the obsolete `file_adoption_orphans` table.
    2. Rename old `ignored`/`managed` fields if present.
    3. Add the new `directory_depth` field.

###  Health Score

39

—

LowBetter than 85% of packages

Maintenance59

Moderate activity, may be stable

Popularity14

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity64

Established project with proven stability

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

37

Last Release

295d ago

PHP version history (4 changes)v1.0.0PHP ^8.3

v1.0.1PHP &gt;=8.2

1.0.2PHP ^8.2

v1.3.0PHP ^8.1

### Community

Maintainers

![](https://www.gravatar.com/avatar/d5c31d575b7ef414cc0505443e98f17130d756dec624d7bb2b9406195241e81c?d=identicon)[dbrabon](/maintainers/dbrabon)

---

Top Contributors

[![dbrabon](https://avatars.githubusercontent.com/u/15270992?v=4)](https://github.com/dbrabon "dbrabon (398 commits)")

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/dbrabon-file-adoption/health.svg)

```
[![Health](https://phpackages.com/badges/dbrabon-file-adoption/health.svg)](https://phpackages.com/packages/dbrabon-file-adoption)
```

###  Alternatives

[knplabs/gaufrette

PHP library that provides a filesystem abstraction layer

2.5k39.8M123](/packages/knplabs-gaufrette)[google/cloud-storage

Cloud Storage Client for PHP

34390.8M123](/packages/google-cloud-storage)[illuminate/filesystem

The Illuminate Filesystem package.

15261.6M2.6k](/packages/illuminate-filesystem)[superbalist/flysystem-google-storage

Flysystem adapter for Google Cloud Storage

26320.6M30](/packages/superbalist-flysystem-google-storage)[creocoder/yii2-flysystem

The flysystem extension for the Yii framework

2931.7M61](/packages/creocoder-yii2-flysystem)[flowjs/flow-php-server

PHP library for handling chunk uploads. Works with flow.js html5 file uploads.

2451.6M15](/packages/flowjs-flow-php-server)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
