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

dev/core#1565 Throwing an API_Exception if uploaded file fails to move with APIv3 #16444

Closed
wants to merge 3 commits into from

Conversation

albionbrown
Copy link
Contributor

@albionbrown albionbrown commented Jan 31, 2020

Overview

When creating an attachment using APIv3, the civicrm_api3_attachment_create function copies the file to the custom file upload directory. However, there is no error checking currently.

Before

The file would attempt to be copied and the original removed.
copy($moveFile, $path); unlink($moveFile);

If the directory is non-writable, the file would be lost.

After

if (!copy($moveFile, $path)) { throw new API_Exception("Cannot copy uploaded file ".$moveFile." to ".$path); } unlink($moveFile);

Now, an API_Exception is thrown before the file is removed.

@civicrm-builder
Copy link

Can one of the admins verify this patch?

@civibot
Copy link

civibot bot commented Jan 31, 2020

(Standard links)

@civibot civibot bot added the master label Jan 31, 2020
@albionbrown
Copy link
Contributor Author

I have only made changes to api/v3/Attachment.php. I'm not sure where the test file conflict has come from but I assume it can be resolved easily.

@eileenmcnaughton
Copy link
Contributor

@albionbrown it looks like the code is applied to the wrong branch or something - maybe checkout a clean copy of master & cherry-pick your patch on & force-push?

@albionbrown
Copy link
Contributor Author

I'll try again today. Shall we close this PR?

@colemanw
Copy link
Member

colemanw commented Feb 3, 2020

It looks like your master branch has gotten messed up because you committed df77575 and then did git pull which did a merge commit. You also seem to have done an unrelated commit d4581b3 after that.

Also it appears you created this PR from master instead of a branch, which is a recipe for mess. I'll close this so you can create a branch for this PR.

To reboot the whole shebang, you can do:

git checkout master
git reset HEAD~4
git pull upstream master
git checkout -b apiException
git cherry-pick df775751fb69289de1dc0567d1c5b0b8872c487c
git push -uf origin apiException

It will give you a link to opening a new PR.

Note, if it tries to create another merge commit during step 3, cancel it and do step 2 again. Reset as far back as you need to so it will pull cleanly without prompting you to create a merge commit. Change step 2 to git reset HEAD~9999 if you need to.

@colemanw colemanw closed this Feb 3, 2020
@albionbrown
Copy link
Contributor Author

Thanks for having a look @colemanw. Out of curiosity, is it preferable to create a new fork when going to create a new PR or can I just use the same one I forked last time but just need to update it?

@albionbrown
Copy link
Contributor Author

Ok I think I'm going to have to delete my repo and fork again because I realised what I've done now.

@albionbrown
Copy link
Contributor Author

Created new PR #16465

@colemanw
Copy link
Member

colemanw commented Feb 4, 2020

@albionbrown I've created thousands of PRs and only ever had one fork :)
git reset is magic for getting you out of trouble. In the worst case I suppose you could delete your own master branch and then check it out again from upstream, but I've never found it necessary to do that either.

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

Successfully merging this pull request may close these issues.

4 participants