Closed (fixed)
Project:
Drupal core
Version:
8.0.x-dev
Component:
cron system
Priority:
Normal
Category:
Task
Assigned:
Unassigned
Reporter:
Created:
8 Jan 2014 at 10:11 UTC
Updated:
29 Jul 2014 at 23:16 UTC
Jump to comment: Most recent, Most recent file
Comments
Comment #1
damiankloip commentedHere is a start on this.
Comment #2
dawehneroh, can we clean this up?
?Yes?
Comment #4
damiankloip commentedTalked about this on IRC, to chance the user nicely, we may need to look at another follow up issue to allow this, as it's kind of it's own problem.
Converted the rest of the drupal_cron_run() usage and injected things.
Comment #5
dawehnerWe usually try to document a bit more.
It would be great to at least at a todo. In additional we could at least get the current user from the container.
This @see is quite pointless to be honest, this is just hook_cron implementation. if you want to understand more, look into hook_cron.
Comment #6
damiankloip commentedMade those docs changes and rerolled after the context/config patch.
I didn't change the user stuff yet. There seems like not much point in doing that right now? As it will not change the user anyway. Added a todo for that (missed it from the interdiff, sorry, just realised!).
Comment #7
dawehnerThis is indeed something which have to tackle in a an additional issue (which is not a follow up technically).
Comment #8
tim.plunkettIs it worth writing a unit test?
Missing param doc blocks
Um, whaaaat? I guess the bottom line should have a @todo as well. Is this what is causing #2108623: Installing via the UI no longer logs in user 1 every time?
Comment #9
damiankloip commentedThanks, will fix those.
Comment #10
damiankloip commentedOk, updated the constructor docblock, and added the @todo near the end of the run() method.
I would prefer not to unit test this right now, as we have lots of procedural calls still, which we cannot really fix right now. So we would have to do the function hack for drupal_save_session, drupal_set_time_limit, watchdog, watchdog_exception, oh and the constants that are used. We could move these out into separate methods etc.. and then override in a test but this seems like a lot of effort just for eeking out a unit test and something we would have to remove again later.
We have appropriate test coverage for this, just not unit tests. We can add this at a later date (I'll add a follow up issue when this is in). How does that sound?
Comment #11
dawehner+1!!
Comment #12
sunJust inject the current_user service...?
Comment #13
damiankloip commentedOh, there's a current_user service?! ;)
So, we inject the current_user service, then what? You can't switch users this way. So any services that use the current_user service will not be synchonrized. This is what the @todo about the current user pertains to. If it was that easy, I think we would have just done that...
Also, rerolled patch.
Comment #14
dawehnerWhen we wrote the current_user service I know that people told me that switching the current user during a request forth and back is an edge case. HAHAH
Comment #15
berdirThen you were told by the wrong people ;) I know there are use cases like this, an issue to add a function to wrap this has been open since forever. I have no clue how to be able to do this with the current_user service.
The only thing I can think of would be to stop injecting the user and inject the authentication manager and get the user from that, not offering a service for the current user (we can still have Drupal::currentUser()), then we can replace the user there and also offer something like #287292: Add functionality to impersonate a user on the authentication manager. But that would be another non-trivial API change around all this.
Comment #16
ParisLiakos commentedcurrent_user service is synchronized, so all you need is a setCurrentUser() method in your object and it will be updated by the DIC.
we just need to make sure that every object that has current_user as a dependency has this method. Then the service would be updated everywhere, no?
Or thats not the problem?
Comment #17
damiankloip commentedYes, we know that part :) this doesn't help us actually change the user though. As we'd only get the user object. This discussion is escalating and should definitely move to a separate issue.
Comment #18
ParisLiakos commentedI am not sure i agree
The correct thing to do imo is make Cron service ContainerAware and instead of manipulating the $user global it should do sth like:
but a followup is fine with me, because this might open a can of worms
Comment #19
ParisLiakos commentedprobably though we already have this followup created #2108623: Installing via the UI no longer logs in user 1 every time
i suspect the same with @tim.plunkett
so, lets move on here
Comment #20
berdirAgreed. Already making the cron path a normal route was a win for modules like elysia_cron, as they don't have to ship their own cron.php anymore, this is even better, they can just replace the service and it then all cron executions will use their implemention. Right now, they have to do all kinds of tricks to prevent the default cron being executed.
+1 to RTBC.
Comment #21
alexpottCommitted 9da7e4c and pushed to 8.x. Thanks!
Comment #22
dawehner... Well this just works in cases of services, but sadly not on plugins which also uses the accounts all over the place.
Comment #23
ParisLiakos commentedah, yes didnt think of that.
well then we need to make plugin managers do this job, or something like what Berdir suggested in #15
Comment #24
les limPosted change notice: https://drupal.org/node/2181921
Comment #25
jibranThanks for the change notice @Les Lim.
Comment #26
Crell commentedOoo... I only just saw this because of the change notice. I like. As a follow-up, could we refactor the run() method? It's still extremely fugly. (Switching hook_cron to an event would probably be harder to get away with at this point, but something we should still look into doing.)
Comment #27
berdir@Crell: I don't think events is a good match here, I'd rather see plugins. Events would make it hard for modules like Elysia cron/Ultimate cron, that allow to configure each hook implementation differently. But I doubt that's a 8.x task :)