Skip to content

PhoenixKit 2.24.0: A task that moves old media folders to their new place

PhoenixKit 2.24.0 adds a command that tidies the media library: it moves the folders modules created before a site set its own folder rules to the place where those rules now put new uploads.

Moving older media folders

A site can tell modules where their attachments go, through the attachments_parent_folder and attachments_folder_name hooks. Folders made before the hooks were set stay where they were. The new mix phoenix_kit.media.reorganize task collects a plan from every enabled module that supports it, compares it with the folders as they are, and moves what is out of place.

By default the task is a dry run. It prints a summary table per module and kind of folder, with columns such as moved, renamed, restored, conflicts, failed and trashed, then the details, and writes nothing. Add --apply to carry the plan out. Other options:

  • --source <module_key> limits the run to one module, and can be given more than once. A key that is unknown or belongs to a disabled module stops the task with an error, instead of quietly doing nothing.
  • --pending-days sets how old a pending folder must be before it counts as stale. The default is 7.

The task runs as the first user with the Owner role. Each move runs in its own transaction. The folder is read again and its file and link counts are checked before and after the write. One failure, conflict or broken module does not stop the run; every outcome appears in the report. Nothing is hard-deleted: a folder is only moved to the trash if it is still empty when the task applies it, and moving a trashed folder out restores what was trashed with it. When a name is already taken, a module can ask for a free name such as “Photos (2)”.

With --apply, the task exits with code 1 if any action failed or hit a conflict, so it can be used in scripts.

For module authors

Modules take part by returning a module from the new optional media_reorganizer/0 callback, which defaults to nil. The contract is documented in PhoenixKit.Modules.Storage.Reorganizer.Source. Actions are plain maps, so a module does not compile against core’s own types.

Upgrading

No migration and no configuration. Update the dependency. Nothing changes on a running site until someone runs the task. Run it without --apply first and read the report.

Full release notes: PhoenixKit 2.24.0

2.24.0 · 16 September 2026

Added

  • Media reorganizer (#815) — moves every module’s legacy media folders to where the host’s attachments_parent_folder / attachments_folder_name hooks now put new ones.
    • mix phoenix_kit.media.reorganize — dry-run by default (prints a per-{source, kind} summary table plus details); --apply writes, --source <module_key> (repeatable) narrows the run, --pending-days sets the stale-pending-folder threshold (default 7). Options are validated before the app starts; an unknown or disabled --source key is an error. Exits 1 when --apply leaves any action :failed or :conflict.
    • PhoenixKit.Modules.Storage.Reorganizer engine — each action runs in its own transaction against a FOR UPDATE re-read of the folder, re-verifies the plan-time file/link counts before and after the write, and never halts the run on a raising source, a failed action or a naming conflict. Nothing is hard-deleted: :trash only soft-deletes a folder still empty at apply time. Moving a trashed folder restores the subtree trashed with it. on_conflict: :suffix picks a free "name (N)".
    • PhoenixKit.Modules.Storage.Reorganizer.Source behaviour — the full contract for module implementations (hook failures, claims, duplicates, pointer back-fill, stale pending folders, query cost) lives in its moduledoc. Actions are plain maps validated by Reorganizer.Action, so a module never compiles against core’s action struct; unknown keys are dropped with one warning.
    • New optional PhoenixKit.Module callback media_reorganizer/0 (default nil), collected from enabled modules by ModuleRegistry.all_media_reorganizers/0.

Fixed

  • Reorganizer summary no longer hides a back-fill’s rename or restore. A move carrying after_move always reports outcome :backfilled, and the renamed / restored columns were derived from that single outcome, so a back-filled action that also renamed or un-trashed its folder counted in neither. Applied actions now carry an engine-internal changes list (:moved / :renamed / :restored) that the summary and the details section read.

PhoenixKit 2.24.0. Install or update: {:phoenix_kit, "~> 2.24"}, then mix deps.get && mix phoenix_kit.update. Full history: CHANGELOG.