Repository navigation
Resolved issue where uploads to MSM shared upload directories showed a post_max_size error and left files behind when validation failed - #5445
Draft
robinsowell wants to merge 1 commit into
Conversation
Upload directories shared across all MSM sites are stored with site_id 0. The legacy file_upload_preferences_model only matched the current site_id, while the modern models use site_id IN (0, current). When an upload to a shared directory failed validation, Filemanager::_upload_error() -> file_model::delete_raw_file() found no row and raised "Undefined array key server_path"; the HTML warning broke the drag-and-drop XHR (shown as the generic post_max_size error) and left the partially uploaded file on disk. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Upload directories created with Share Upload Directory on all sites are stored with
site_id0. The modern File models already look them up withsite_id IN (0, current)(Service/File/Upload::uploadTo(), the file and file grid fieldtypes, the filepicker). The legacyFile_upload_preferences_model::get_file_upload_preferences()still filteredsite_id = current, so it never found a shared directory.The visible symptom on MSM sites:
.webpinto a shared directory that allows only Documents.Filemanager::_upload_error()callsfile_model::delete_raw_file(), which looks the directory up through the legacy model and gets an empty result.Undefined array key "server_path"(legacy/models/file_model.php:634). The HTML error output replaces the JSON response, so the drag-and-drop uploader shows the generic "Unexpected error. Check your post_max_size setting" message instead of the real error ("file type not allowed", "exceeds max dimensions", etc.).@unlink()calls run against a null path, so the file that should have been cleaned up stays in the directory. Users report that the upload "errored but uploaded anyway".Non-MSM installs and non-shared directories are unaffected, which is why this is hard to reproduce locally.
Change
get_file_upload_preferences()now filterswhere_in('site_id', [0, current_site_id])unless$ignore_site_idis passed, matching the modern models. This fixesdelete_raw_file()and the other legacy callers that look up a shared directory by ID (Filemanager::fetch_files(), metaweblog, moblog). List callers now include shared directories, which matches the modern file pickers and fieldtypes.parse_upload_path_vars()already handlessite_id0 (no per-site overrides).Tests
Tests/ExpressionEngine/legacy/Models/FileUploadPreferencesModelTest.php: an ID lookup includessite_id0 and returnsserver_path;$ignore_site_idskips the site filter. It fails on7.devwithout the change.Addons/file(232),Service/File(11),Library/Filesystem(10),legacy/Helpers,legacy/Core,legacy/database,legacy/Api: same results before and after.7.dev, unchanged by this PR:GridModelOrderingTest::testOrdersByMultipleGridColumns("Cannot call constructor") andCacheAdapterFallbackToFileTest::testDefaultsToFileAdapter(child process ended unexpectedly). Locally the full suite also stops at about 10% with "The configuration file does not exist.", so it was run by area.