Skip to content

Conversation

tezvi
Copy link
Contributor

@tezvi tezvi commented Jul 6, 2025

Hello there!

This command is useful for maintaining the integrity of the Moodle database and file system.

NOTICE: After I implemented it I found out that there is already something similar merged to master i.e. file-* commands. However this command is a bit different in a way that it is able to produce various outputs suitable for scripting like json, xml, csv etc. in a centralized AIO way.
Merge if you find it useful 😸

This command helps administrators identify discrepancies between the Moodle
database (mdl_files table) and the physical file storage (moodledata/filedir).
It operates in two primary modes:

  1. db mode (default): Scans the mdl_files table and verifies that each
    file record corresponds to an existing physical file in the filedir. It
    reports database entries for which the physical file is missing.

  2. fs mode: Scans the moodledata/filedir directory and verifies that
    each physical file has a corresponding record in the mdl_files table.
    It reports physical files that are not referenced in the database.

The output can be formatted as plain text, JSON, XML, or CSV, making it
easy to parse or use in other scripts. A summary of the total number and
size of orphaned files can also be displayed.

If file option is given all output will be redirected to the specified file.

Example 1: Check for DB entries missing from the filesystem (default mode).

mooshp file-orphaned

Example 2: Check for filesystem entries missing from the DB.

moosh file-orphaned --mode=fs

Example 3: Output the results in JSON format to a file1 and show a summary.

moosh file-orphaned --output-format=json --file=file1.json --summary

This command is useful for maintaining the integrity of the Moodle database and
file system.

This command helps administrators identify discrepancies between the Moodle database
(mdl_files table) and the physical file storage (moodledata/filedir). It operates in
two primary modes:

db mode (default): Scans the mdl_files table and verifies that each file record
corresponds to an existing physical file in the filedir. It reports database entries
for which the physical file is missing.

fs mode: Scans the moodledata/filedir directory and verifies that each physical file
has a corresponding record in the mdl_files table. It reports physical files that are
 not referenced in the database.

The output can be formatted as plain text, JSON, XML, or CSV, making it easy to parse
 or use in other scripts. A summary of the total number and size of orphaned files can
 also be displayed.

If file option is given all output will be redirected to the specified file.

Example 1: Check for DB entries missing from the filesystem (default mode).

mooshp file-orphaned
Example 2: Check for filesystem entries missing from the DB.

moosh file-orphaned --mode=fs
Example 3: Output the results in JSON format to a file1 and show a summary.

moosh file-orphaned --output-format=json --file=file1.json --summary
@tmuras
Copy link
Owner

tmuras commented Jul 7, 2025

Hi Andrej,

Thanks for the nice implementation including the documentation.
The command is already implemented by:
https://moosh-online.com/commands/#file-check
https://moosh-online.com/commands/#file-dbcheck

@tezvi
Copy link
Contributor Author

tezvi commented Jul 8, 2025

No worries, I figured out it might be a helpful addition with a different implementation 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants