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

johanneshahn’s picture

hi
think its an performance issue

looking at authorize.php an read the first comment.

... This script actually performs the
 * selected operations without loading all of Drupal
...
dww’s picture

@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.

dww’s picture

Assigned: Unassigned » dww
Status: Active » Needs review
StatusFileSize
new3.56 KB

This 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.

dww’s picture

Status: Needs review » Needs work

I 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.

dww’s picture

Status: Needs work » Needs review
StatusFileSize
new4.57 KB

Rerolled 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.

dww’s picture

Status: Needs review » Needs work

I'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.

dww’s picture

Status: Needs work » Needs review
StatusFileSize
new7.98 KB

Major cleanup, standardizing on system_authorized_*() for the function names. Now with real developer docs. Yay. ;)

dww’s picture

Minor typo in a code comment that still referred to system_run_authorized_operation().

dww’s picture

p.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.

dww’s picture

Fixed the @see at the top of authorize.php, too...

Side note: anyone know if you can say: @see authorized-operations to reference a named group/topic?

sun’s picture

+++ modules/system/system.module	27 Oct 2009 10:01:25 -0000
@@ -1450,14 +1450,54 @@ function _system_themes_access($theme) {
+ * @defgroup authorized-operations Authorized operations

The internal @group name should use a underscore, no hyphen.

+++ modules/system/system.module	27 Oct 2009 10:01:25 -0000
@@ -1470,11 +1510,9 @@ function _system_themes_access($theme) {
  * @return
- *   Nothing. This function redirects to authorize.php and does not return.
+ *   The path to authorize.php that the caller should redirect to.
  */
-function system_run_authorized($callback, $file, $arguments = array(), $page_title = NULL) {
-  global $base_url;
-
+function system_authorized_setup($callback, $file, $arguments = array(), $page_title = NULL) {
@@ -1490,12 +1528,31 @@ function system_run_authorized($callback
   if (isset($page_title)) {
     $_SESSION['authorize_operation']['page_title'] = $page_title;
   }
+}

Where is that return value? (just not visible in the diff context?)

+++ modules/system/system.module	27 Oct 2009 10:01:25 -0000
@@ -1470,11 +1510,9 @@ function _system_themes_access($theme) {
+function system_authorized_setup($callback, $file, $arguments = array(), $page_title = NULL) {

Elsewhere, we call this "init" (not setup)?

+++ modules/system/system.module	27 Oct 2009 10:01:25 -0000
@@ -1490,12 +1528,31 @@ function system_run_authorized($callback
+function system_authorized_run($callback, $file, $arguments = array(), $page_title = NULL) {
+  system_authorized_setup($callback, $file, $arguments, $page_title);
+  drupal_goto(system_authorized_get_url());
 }

So no return value at all? ;)

This review is powered by Dreditor.

dww’s picture

Status: Needs review » Needs work

Great review, thanks. I'm on it.

dww’s picture

Status: Needs work » Needs review
StatusFileSize
new5.87 KB
new9.57 KB

- Changed the group name to just "authorize"
- Fixed the @file comment in authorize.php
- Renamed to system_authorized_init()
- Fixed @return to reflect reality

dww’s picture

- Added summary for @defgroup block
- s/your/the user's/ in an @return

sun’s picture

Status: Needs review » Reviewed & tested by the community

Looks very nice :)

webchick’s picture

Status: Reviewed & tested by the community » Fixed

Very nice! Silly bug fixed, and documentation vastly improved. A+++ would commit again.

Committed to HEAD. :)

Status: Fixed » Closed (fixed)
Issue tags: -Update manager

Automatically closed -- issue fixed for 2 weeks with no activity.