revolution icon indicating copy to clipboard operation
revolution copied to clipboard

[MODX 3] Media browser uploads file to incorrect path when media source is changed

Open halftrainedharry opened this issue 1 year ago • 3 comments

Bug report

Summary

Under certain conditions, the media browser uploads files to the wrong path after the media source is changed.

Step to reproduce

  • Create a media source. (For example "Images" with basePath/baseUrl = assets/images/.)
  • Create a static resource and select a file from the media browser that is located in a subfolder. (For example assets/images/blue.png.)

bug_media_browser_static_resource

  • Open the media browser again (to select a different file).
  • Change the media source. (For example to "Images".)
  • Click the "Upload Files" button and select a file.
  • Instead of the media source root folder (assets/images/), the file is uploaded to the directory assets/images/assets/images/.

bug_media_browser_wrong_path

Cause of the error

In the media browser code, when the media source is changed, the active node is set to an empty string: this.cm.activeNode = '';

https://github.com/modxcms/revolution/blob/f197da76b44645172dc3f0eb721961fd4f534c04/manager/assets/modext/widgets/system/modx.tree.directory.js#L270-L274

Now when a file is uploaded and the active node is empty, the code uses the value of this.config.openTo for the path (which is set to the path of the file that was selected when the media browser was opened.)

https://github.com/modxcms/revolution/blob/f197da76b44645172dc3f0eb721961fd4f534c04/manager/assets/modext/widgets/system/modx.tree.directory.js#L749-L751

Possible solution

In the media browser code, after the media source is changed, set the active node to the root node of the media source.

https://github.com/modxcms/revolution/blob/f197da76b44645172dc3f0eb721961fd4f534c04/manager/assets/modext/widgets/system/modx.tree.directory.js#L273-L274

if (rn) { rn.setText(sel.getRawValue()); this.cm.activeNode = rn; }

Environment

MODX 3.0.4-pl.

halftrainedharry avatar Feb 23 '24 10:02 halftrainedharry

This issue has been mentioned on MODX Community. There might be relevant details there:

https://community.modx.com/t/binary-static-resources-not-downloading/7555/8

modxcommunity avatar Feb 23 '24 10:02 modxcommunity

On 3.1.0-dev I'm not seeing this happening. Can you create a video capture of your process of reproducing the issue? Also, a screen grab of the media source setup would help as well.

smg6511 avatar Mar 24 '24 05:03 smg6511

On 3.1.0-dev I'm not seeing this happening.

Yes, it looks like this issue is fixed in the current version that's under development. It seems that with the PR #16394, when the media source is changed, the active node gets set again here in the code:

https://github.com/modxcms/revolution/blob/49659246226986a9b117f30de90820dc0f566467/manager/assets/modext/widgets/core/tree/modx.tree.js#L914

halftrainedharry avatar Apr 09 '24 09:04 halftrainedharry