Closed (fixed)
Project:
Drupal core
Version:
8.0.x-dev
Component:
comment.module
Priority:
Normal
Category:
Task
Assigned:
Reporter:
Created:
13 Dec 2013 at 13:51 UTC
Updated:
12 Aug 2014 at 23:20 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
larowlanShould this go on the storage controller because its related to storage?
Comment #2
andypostThere are a lot of debates about it in issues about
EntityQueryconversionI think if the function could use "universal"
QueryFactoryit should live in manager because storage independent.Once query involves sql-specific (db_query() for example) - should be places in swappable storage
Comment #3
larowlanYes, you are right
Comment #4
roderikThere's an ORDER BY a certain expression in comment_get_thread(), to make the speed bearable. So it goes into swappable storage afaict.
This is going to be part of CommentStorageInterface (which still needs work) in #2068331: Convert comment SQL queries to the Entity Query API - so I guess this one can be closed.
Comment #5
roderikActually - #2068331: Convert comment SQL queries to the Entity Query API grew way too large, so I'll reverse strategy, and split out comment_get_thread() into here.
For your review. I reshuffled the code/arguments a bit to allow for the possibility of not applying PagerSelectExtender.
One possibly outstanding issue is the call to \Drupal::currentUser() that's inside CommentStorage::loadThread() now.
Could we just make that into an argument 'has admin rights' to pass into the method?
Maybe even sneak that as a bitmask into the $mode argument?
Comment #6
roderikretitling
Comment #7
roderikReroll after PSR-4
Comment #8
slashrsm commentedLooks good. Just one minor comment.
Let's move $comments assignment out of condition.
Comment #9
roderikAlright, no contest here.
(Spotted it but had no opinion so left as-is)
Comment #10
slashrsm commentedLooks good.
Comment #11
alexpottThese are not nodes.
Comment #12
roderikHummm they're very much not.
Comment #13
larowlanBack to rtbc
Comment #14
larowlanComment #15
roderik"Wait, what was I thinking... This is not even true."
/me strips off part of an earlier addition to comments
Comment #16
roderikcrosspost, sorry larowlan discovered another minimal thing :)
Comment #17
roderikReroll for #2228763 (replaced field_id by field_name occurrences on 2 lines).
Comment #18
roderikComment #19
roderikStill having the feeling that using a Drupal::currentUser() call inside CommentStorage will/should be shot down. See #5.
Here's a suggested patch: don't check user access inside loadThread() but require a extra flag to display unpublished comments. (This would open up the possibility for using 'non admin' displays for admin users too. And other flags like 'include to-be-moderated comments'.)
By the way, the patch doesn't look like it but I did check for other uses of COMMENT_MODE_FLAT / COMMENT_MODE_THREADED. I don't think there are any other places (yet) that should assume COMMENT_ACCESS_MODE_ADMIN could even be an input value.
(Except a possible future change to comment_new_page_count() - but not yet. I think there may be a bug in there that potentially returns the wrong page number for admin users, but getting into that is way out of scope for this issue.)
Comment #20
roderikOops, forgot to check my own loadThread() calls. Interdiff from 17 included.
Side effect of this patch:
comment_node_update_indexcan never read unpublished comments by mistake. I guess that's a good thing.Comment #22
slashrsm commentedComment #23
slashrsm commented20: 2156089-20-comment-get-thread.patch queued for re-testing.
Comment #24
alexpottThe change to add
COMMENT_ACCESS_MODE_ADMINand not makecomment_get_thread()determine if the current user has the administer comments permission needs a change notice.Comment #25
slashrsm commentedChange record need to be created before or after this goes in?
Comment #26
larowlanBefore and saved as a draft
Comment #27
roderikRerolled:
changed some comments for COMMENT_MODE_FLAT -> CommentManagerInterface::COMMENT_MODE_FLAT;
moved COMMENT_ACCESS_MODE_ADMIN into CommentManagerInterface because that's where the other constants are now.
This means that now, CommentStorage is dependent on CommentManagerInterface where it wasn't before... ('use' statement added during reroll).
Change notice will be added to https://www.drupal.org/node/2299799 soon. This means the change notice will document more than one not-yet-committed issue.
Comment #29
roderikFixing my own include...
Comment #30
slashrsm commentedComment #31
alexpott#2281475: Deprecate comment_new_page_count() and move it functionality into Comment storage controller got in first.
Comment #32
slashrsm commentedComment #33
slashrsm commentedWas very simple re-roll.
Comment #34
alexpottI'm not sure about this. Using bitwise operator to join this together with the threaded and flat mode is kinda weird because you can't join them together... why are we doing this? The service already has the current user service. If we need to do this then lets add an argument to loadThread to include admin comments if the user has access.
Comment #35
slashrsm commentedDone.
Comment #37
slashrsm commentedMeh... broken diff. Should be fine now. Interdiff from #35 is still valid.
Comment #38
andypostgetDisplayOrdinal()method does not pass any additional parameters, and both functions should be unified.suppose "include_unpublished" better because it affects not only admins
Comment #40
larowlanFixes 40
Comment #42
larowlandoh
Comment #43
marcingy commentedLooks good
Comment #44
roderikInterdiff #1: backed out references to COMMENT_ACCESS_MODE_ADMIN in code comments.
interdiff #2: sorry for causing the confusion guys, but I'm backing out the whole part referring to this flag/function argument. I promise to post the reverse interdiff-2.txt in a followup patch with attribution.
Answers:
#34/alexpott
We didn't have the current user service at the time I added this into the patch, and I (still newbie) mistakenly thought we could not have it. (From the combination of an old andypost comment and me agreeing that including $currentuser is weird.)
It seems that assumption is wrong**. So now that we have the current user service, this part is indeed not necessary. And shouldn't be included in this issue.
#38/andypost
You're right.
On top of that, I think getNewCommentPageNumber() should be unified with those functions, even though it isn't now. (In other words: since it doesn't do the same permission check, I think that Drupal contains a bug where a link to the wrong page number for new comments could be output for admin users.)
I'll take care of that in the followup issue, and extend the tests to... test my suspicion.
--
** I can understand it if $currentuser doesn't actually contain a 'static' user but a 'proxy object' that always gets the active user. That's still unclear to me, but w/e.
Comment #45
andypost@roderik Awesome! just a small nitpick
it is
I'd better use view builder here like formatter does
$build = $this->viewBuilder->viewMultiple($comments);Also needs follow-up to get rid of the function
comment_view_multiple()Comment #46
roderikOK done.
Doesn't ring a bell here. Is D8 deprecating comment_view_multiple() ( and comment_view() ) the same way we did with comment_load[_multiple]()? I'll open a follow-up when I understand.
Also: comment_prepare_thread(). Last month I didn't understand how to get rid of it but now it seems logical to me to move it into CommentViewBuilder::viewMultiple(). In the same follow-up. Or did you mean that?
Comment #47
roderikPreempting testbot fail now #1498662: Refactor comment entity properties to multilingual is in
Comment #48
slashrsm commentedComment #50
andypostProper fix for table name and
$comments_per_page- why new implementation uses default argument with value 0?Also fixed table alias after #1498662: Refactor comment entity properties to multilingual
Comment #51
slashrsm commentedComment #52
roderikThanks for fixing. (I will keep falling away for some days because of work.)
Per #5: comment_get_thread() always applied paging (PagerSelectExtender). While we are nailing down interfaces here,
Opinions on that, welcome. I do appreciate these detailed reviews because it makes me feel safer to actually experiment with changes like this :)
Comment #53
alexpottWhy have we swapped this around? Plus we don't need the bitwise operations anymore.
Lets add the fact that they are keyed by ID.
Comment #54
roderikComment #55
slashrsm commentedComment #57
slashrsm commentedRe-roll.
Comment #58
marcingy commentedLooks good
Comment #59
alexpottre #54.3 Well, normally we deprecate and then remove in separate patches - since this gives a chance for module developers to convert but I can not imagine this is a widely used function.
Committed 6e6f2c6 and pushed to 8.x. Thanks!
+1 for the British spelling of favour in the issue title :)