-
Notifications
You must be signed in to change notification settings - Fork 109
Fix: Replace attachment file IDs when copying markdown files #7298
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
Fix: Replace attachment file IDs when copying markdown files #7298
Conversation
max-nextcloud
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks a lot for bringing this up and addressing it right away. 🥇
I have one comment. Please check if I'm mistaken - just read the code and did not try it myself.
As I said in the comment... a unit test might come in handy to ensure the function works as desired. If you need further help with writing it let me know.
lib/Service/AttachmentService.php
Outdated
| foreach ($fileIdMapping as $mapping) { | ||
| $patterns[] = '/(\[[^\]]+\]\(\S+\/f\/)' . $mapping[0] . '/'; | ||
| // Replace `[title](URL/f/sourceId` with `[title](URL/f/targetId` | ||
| $replacements[] = '${1}' . $mapping[1]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this will drop the trailing / as it's included in the patterns but not in the replacements.
As this is a public static method and the arguments are not very complex it seems like a good candidate for a unit test. You'd have to mock getContent and putContent on target similarly to how it's done in the testReplaceAttachmentFolderId test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahh... my bad... the / is ending the regexp. Unit test would still be nice - but now i see that this probably works well as is.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, I added a unit test for replaceAttachmentFileIds. It actually helped catch a couple issues with my original regex too.
bdf1626 to
205b6aa
Compare
…pying markdown files Signed-off-by: Peter Birrer <[email protected]>
Head branch was pushed to by a user without write access
205b6aa to
b0617cb
Compare
|
Thanks so much for taking care of this @pbirrer! Much appreciated 🫶 |
|
/backport to stable31 |
|
/backport to stable30 |
|
Hello there, We hope that the review process is going smooth and is helpful for you. We want to ensure your pull request is reviewed to your satisfaction. If you have a moment, our community management team would very much appreciate your feedback on your experience with this PR review process. Your feedback is valuable to us as we continuously strive to improve our community developer experience. Please take a moment to complete our short survey by clicking on the following link: https://cloud.nextcloud.com/apps/forms/s/i9Ago4EQRZ7TWxjfmeEpPkf6 Thank you for contributing to Nextcloud and we hope to hear from you soon! (If you believe you should not receive this message, you can add yourself to the blocklist.) |
📝 Summary
When copying markdown files, the attachment IDs embedded in the file content were not updated to match the newly created attachments. This PR fixes that by:
AttachmentService::copyAttachments()to return a map of old to new file IDs.AttachmentService::replaceAttachmentFileIds()to update these references in the file content.🏁 Checklist
npm run lint/npm run stylelint/composer run cs:check)