Hrm, while looking over the code in update.manager.inc more closely, I realized that the API for system_run_authorized() is a bit wrong. It shouldn't automatically directly call drupal_goto() for you, since it's often (in fact, at this point, always) called from a FAPI submit handler, where it'd be better and cleaner to set $form_state['redirect'] than to have a drupal_goto() directly.
I'm not sure if it should just be a param that determines if the drupal_goto() should happen, or if that should always be the caller's responsibility. Perhaps system_run_authorized() should just return the path to authorize.php for you and it's always your problem to either set $form_state['redirect'] or pass the path off to drupal_goto().
Comments
Comment #1
johanneshahn commentedhi
think its an performance issue
looking at authorize.php an read the first comment.
Comment #2
dww@johanneshahn: No idea what you're talking about. ;) I wrote authorize.php, so I know what it's doing. This issue is only about a question of the API for the system_run_authorized() function that sets up an operation to be performed via authorize.php. Currently, system_run_authorized() directly calls drupal_goto() to redirect you to authorize.php. I'm realizing that so far, all the call sites that invoke system_run_authorized() are inside form submit handlers, in which case they should really be setting $form_state['redirect'] to a path instead of calling drupal_goto() directly. This has nothing to do with performance at all.
Comment #3
dwwThis works fine. It's slightly weird that the function is called "system_run_authorized()", when it's really a bit more like "system_prepare_authorized()" now. Update manager is (obviously) the only call site for this function in core, so I'm not that worried about changing the function signature if we want to make it more DX-friendly.
Comment #4
dwwI asked chx to review this in IRC. He agreed I should just rename the function, since it's not really running anything anymore. A few possibilities:
A) system_setup_authorized()
B) system_prepare_authorized()
C) system_authorize_setup() (to put the verb last, which I guess is something of a standard?)
D) system_authorize_prepare()
E) system_authorize_operation_setup()
...
I'm really not sure what to call it. ;) Any suggestions?
Also, since this is going to conflict with #609728: Skip authorize.php step if webroot files are owned by the httpd user and that's now RTBC, I'll wait to post the new patch until #609728 lands.
Comment #5
dwwRerolled now that #609728: Skip authorize.php step if webroot files are owned by the httpd user is in. I decided to go with "system_setup_authorized" as the function name.
Comment #6
dwwI'm still not thrilled with the DX here, since the function is really doing two things, which is why it's hard to name it. And, Jacob points out that someone looking at the authorize.php stuff and trying to figure out how to use it is going to be confused if there's a "setup" call, but nothing to actually "process" or "run" your operation...
The current proposal is to actually split this up into 3 pieces:
system_setup_authorized_operation() -- does most of what system_run_authorized() does now.
system_get_authorization_url() -- returns you the URL to visit after you setup an authorized operation.
system_run_authorized_operation() -- calls the above two, and does the drupal_goto() for you.
So, if you're in a FAPI submit handler, you just use the 1st two directly. If you're not, you can use the 3rd and let it call the first two.
I'll re-roll, with better docs. Stay tuned.
Comment #7
dwwMajor cleanup, standardizing on system_authorized_*() for the function names. Now with real developer docs. Yay. ;)
Comment #8
dwwMinor typo in a code comment that still referred to system_run_authorized_operation().
Comment #9
dwwp.s. If anyone thinks system_authorized_get_url() is a stupid function, not only is this a nice way to avoid duplicating code in a few different spots, it's also going to need to get more complex as part of #607008: Fix bugs in https support and force using https for authorize.php if available.
Comment #10
dwwFixed the @see at the top of authorize.php, too...
Side note: anyone know if you can say:
@see authorized-operationsto reference a named group/topic?Comment #11
sunThe internal @group name should use a underscore, no hyphen.
Where is that return value? (just not visible in the diff context?)
Elsewhere, we call this "init" (not setup)?
So no return value at all? ;)
This review is powered by Dreditor.
Comment #12
dwwGreat review, thanks. I'm on it.
Comment #13
dww- Changed the group name to just "authorize"
- Fixed the @file comment in authorize.php
- Renamed to system_authorized_init()
- Fixed @return to reflect reality
Comment #14
dww- Added summary for @defgroup block
- s/your/the user's/ in an @return
Comment #15
sunLooks very nice :)
Comment #18
webchickVery nice! Silly bug fixed, and documentation vastly improved. A+++ would commit again.
Committed to HEAD. :)