Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH ensure file title constructed from original filename #633

Merged
merged 1 commit into from
Aug 21, 2024

Conversation

satrun77
Copy link
Contributor

@satrun77 satrun77 commented Aug 21, 2024

Description

When uploading a file that uses a characters other than English letters, the codebase is going to santise the file name and rename it, this going to change filename from الطالب لعائلتك.docx to something which features digital characters, for instance 66b034bf7ca15.docx. When the File object is saved, the new file name is used to populate the Title field.

This PR is to ensure the Title field is populated from the original file name الطالب لعائلتك.docx instead of the new name 66b034bf7ca15.docx

Manual testing steps

  • Get a sample file which features Arabic characters in its file name. For instance الطالب لعائلتك.docx.
  • In the CMS, go to the "Files" area and upload the file mentioned in the previous step
  • When this file is uploaded, you should see the Filename change from الطالب لعائلتك.docx to something which features digital characters, for instance 66b034bf7ca15.docx.
  • The title should reflect the original filename.

Issues

Pull request checklist

  • The target branch is correct
  • All commits are relevant to the purpose of the PR (e.g. no debug statements, unrelated refactoring, or arbitrary linting)
    • Small amounts of additional linting are usually okay, but if it makes it hard to concentrate on the relevant changes, ask for the unrelated changes to be reverted, and submitted as a separate PR.
  • The commit messages follow our commit message guidelines
  • The PR follows our contribution guidelines
  • Code changes follow our coding conventions
  • This change is covered with tests (or tests aren't necessary for this change)
  • Any relevant User Help/Developer documentation is updated; for impactful changes, information is added to the changelog for the intended release
  • CI is green

@satrun77 satrun77 force-pushed the pull/non-english-filename branch from f11e062 to 70ad6c4 Compare August 21, 2024 02:13
@satrun77 satrun77 marked this pull request as ready for review August 21, 2024 02:13
Copy link
Member

@GuySartorelli GuySartorelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for submitting this. Unfortunately I can see a few problems with this approach.

This approach relies on a non-existent field OriginalName which only gets populated on file upload.

This means for any files created programatically the functionality won't work.

This also breaks the ability to remove the title to reset to the name of the file.

Please try again with an approach that:

  1. Doesn't add new db fields, but also doesn't rely on non-existent fields
  2. Works when creating files programatically
  3. Allows content authors to clear the title and have it reset to the file name

@satrun77 satrun77 force-pushed the pull/non-english-filename branch from 70ad6c4 to eb47e40 Compare August 21, 2024 02:49
Copy link
Member

@GuySartorelli GuySartorelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent, thank you! Just a few small things to tidy up

src/File.php Outdated Show resolved Hide resolved
src/File.php Outdated Show resolved Hide resolved
@satrun77
Copy link
Contributor Author

Thanks for submitting this. Unfortunately I can see a few problems with this approach.

This approach relies on a non-existent field OriginalName which only gets populated on file upload.

This means for any files created programatically the functionality won't work.

This also breaks the ability to remove the title to reset to the name of the file.

Please try again with an approach that:

  1. Doesn't add new db fields, but also doesn't rely on non-existent fields
  2. Works when creating files programatically
  3. Allows content authors to clear the title and have it reset to the file name

How about this update? The issue is with the Upload class. Not sure what you mean by Works when creating files programatically? but if you setup the Upload code programmatically, it should populate title with original file name.

If CMS author clear the title and save, it will use the transformed file name to populate the title.

@satrun77 satrun77 force-pushed the pull/non-english-filename branch from eb47e40 to 9584c31 Compare August 21, 2024 02:56
@GuySartorelli
Copy link
Member

When I said "creating files programatically" I meant creating a file record directly in PHP, and setting its content via the PHP API - without any user interaction. This doesn't use Upload at all.
The way you've implemented it now allows that. 👍

@GuySartorelli GuySartorelli changed the base branch from 2.2 to 2 August 21, 2024 02:59
@GuySartorelli
Copy link
Member

Just letting CI run, and gonna test it locally. If it all passes, I'll be happy to merge.

Copy link
Member

@GuySartorelli GuySartorelli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, and works great locally. Thanks!

@GuySartorelli GuySartorelli merged commit 6b6fcbc into silverstripe:2 Aug 21, 2024
8 checks passed
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