-
-
Notifications
You must be signed in to change notification settings - Fork 814
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
CRM-19948: Store Attachment uploader information #11739
Conversation
2f9ec22
to
76e60f8
Compare
65670f7
to
a3f143e
Compare
api/v3/Attachment.php
Outdated
@@ -147,6 +147,7 @@ function civicrm_api3_attachment_create($params) { | |||
$fileDao->copyValues($file); | |||
if (!$id) { | |||
$fileDao->uri = CRM_Utils_File::makeFileName($name); | |||
$fileDao->created_id = CRM_Core_Session::getLoggedInContactID(); |
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 it's better to do this on the spec function - ie
'api.default' => 'user_contact_id',
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.
yeah right .. how could I overlooked it :( Will do it
@monishdeb I understand this PR is a reviewer's commit so if you have tested it I'm Ok with it - although I made one stylistic comment. I think there is a pretty strong precedent for adding this sort of column and while adding columns to big tables should be done cautiously due to the length of time the upgrade script can take (we can't impose 1-2 hour outages every month) my feeling is that the file table is not likely to be massive even for large sites. Regarding the upgrader test - you mean you couldn't just run the upgrade locally? |
Thanks, @eileenmcnaughton for your feedback. I have made the additional fix, also earlier I tested the patch over a multilingual upgrade on my local. And the test build covers the monolingual upgrade, so I think the PR is safe to merge. |
@monishdeb I'm surprised the |
@monishdeb I'm still very confused as to how the arrays managed to stay in the old syntax after being passed through codeGen the first time you did this, and why they are suddenly coming out in the correct syntax now, even though we haven't done any updates to codeGen. |
@colemanw that's because the CodeGen will simply ignore if that file is already present (see here where |
This is incorrect. The Reflection::needsUpdate() check says that:
The problem here is that the equivalence-test ( I suppose there is a legitimate argument that the two files are truly equivalent (because array-syntax differences are trivial). But I can't think of a reason why we'd want to treat them as equivalent for |
@totten the reason for c3fc262 is that our old php beautifier is incapable of processing files with short array syntax. Also, the smarty function |
d91c2d9
to
c74ea2d
Compare
api/v3/Attachment.php
Outdated
'title' => 'Created By Contact ID', | ||
'type' => CRM_Utils_Type::T_INT, | ||
'description' => 'FK to civicrm_contact, who uploaded this file', | ||
'api.default' => 'user_contact_id', |
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 wonder if the File BAO is a more appropriate place to set this default value than the API? Setting it here will only affect apiV3.
a8f8085
to
b9efc25
Compare
* | ||
* @param string $rev | ||
*/ | ||
public function upgrade_5_2_alpha1($rev) { |
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.
@eileenmcnaughton like I was saying if we need to set it to upgrade_5_2_alpha1
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.
CRM/Core/BAO/File.php
Outdated
$fileDAO = new CRM_Core_DAO_File(); | ||
$fileDAO->copyValues($params); | ||
|
||
if (empty($params['created_id'])) { |
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 ought to also be conditional if there is no $params['id']
to avoid overwriting this value on update.
f598621
to
4914b37
Compare
@colemanw @eileenmcnaughton can you please review & merge this PR? (cherrypicked commits from #9761 + additional changes) |
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 is good except for missing hooks.
$fileDAO->created_id = CRM_Core_Session::getLoggedInContactID(); | ||
} | ||
|
||
$fileDAO->save(); |
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 BAO::create() function needs to call pre/post hooks.
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.
oops missed it, thanks for pointing that out.
Added the hook calls. Can you please check now?
@colemanw what does approved mean? How does that fit with 'good to merge' |
@eileenmcnaughton I had been about to merge it but then waned to verify with @totten that the upgrade code was going into the correct place. Got that question answered so now merging. |
This PR changes the Attachment API in order for it to save the current logged in contact ID as the uploader of the file.
The ID is stored in the
created_id
field, which was added to the File entity. OnAttachment.create
, only when adding a new file (i.e. File.id is empty), we set thecreated_id
as logged in contact ID.The
created_id
field is not required and, on delete, it's set to null. This was done because:Note: I couldn't find a way to test the upgrader, so I'm not really sure if it's working. I tried to play with https://github.com/civicrm/civicrm-upgrade-test but didn't have any success