After discussing with Gábor, i created this patch which splits install_complete() into two parts:
install_finalize();
install_complete();
The finalizing step - calling _profile_final() is moved into finalize().
This enabled splitting a logic of installation - doing ANYTHING and displaying maintenance page.
Installation profiles can now do anything including doing redirects and then redirect to install.php?install_finalized=1
Simple check is added to install_main() to ensure installation is not triggered again.
See this image: http://www.gliffy.com/pubdoc/1221894/L.jpg for the workflow.
Use case:
- once autolocale is finished, it will create a batch during _final() phase of the installation profile, import all translations and redirect back to install.php?install_finalized=1
| Comment | File | Size | Author |
|---|---|---|---|
| #9 | install.php__6.patch | 3.68 KB | meba |
| #6 | install.php__5.patch | 3.49 KB | meba |
| #5 | install.php__3.patch | 3.22 KB | meba |
| #2 | install.php__2.patch | 2.95 KB | meba |
| install.php__1.patch | 2.83 KB | meba |
Comments
Comment #1
gábor hojtsySo the motivation of this is to be able to have HTTP requests inbetween the "install finalization" and the "completed page", to import all translations for enabled modules as an example. You seem to solve this by either returning a message from the "hook_profile_final()", to signify that installation is ready, or redirecting to a different page in that function, and sometime later redirecting back to the "?install_final=1" page to get the "completed" page.
Some notes:
- How would some other operation work in install.php? What URL will it allow to run?
- You have some misleading references to $_SESSION['install_final'] which should be $_GET[...] I guess
Comment #2
meba commentedFixing missing reference to _GET
You can do anything you want in _final(). You can even redirect to www.google.com as long as you are sure that google.com then redirects to /install.php?install_finalized=1. This is an example, the main purpose will be for batch operations i think.
Comment #3
gábor hojtsyI was concerned about possible problems with the live Drupal being called to do stuff, but because it seems this stage is only called when Drupal is fully built, it should not be a problem. But a custom profile message is not possible to set with this solution (which should be possible somehow).
Comment #4
meba commentedYou are right. The only option is to support $_GET['profile_message'], but i don't know, that will restrict profile message to be plain text or restricted html...
Comment #5
meba commentedAdding support for profile_message after redirect.
Comment #6
meba commentedProfile message doesn't need to be passed via $_GET, sessions are properly initialized during _final() and during _complete(), so we can pass it via $_SESSION. Attaching new patch.
Thanks to Gábor for the idea.
Comment #7
dries commentedIt would be great if either Neil or Steven could comment on this.
Comment #8
gábor hojtsyI have put a lot of thought the last two days into whether we require this split at all. As a matter of fact, install profile developers were told to redirect from profile_final() if they needed to display wizards or do any extra processing in installation. Because it was not possible to get back to the "install complete" screen later (no URL to display that screen), people were told to present their install complete screen after that redirection on their own. This worked with Drupal 5.
Now with Drupal 6, automatic interface translation importing functionality is supposed to end up in Drupal core. So we either need (a) default.profile to support automatic importing or (b) have an alternate install profile in core which supports automatic importing. Either case, we need to run code in multiple HTTP requests (a batch) and get back to an "install complete" screen at the end. If we would ship an alternate install profile for this, a hackish redirection out of the installation process might be workable (but I doubt it will be nicely accepted into core). However, automatic translation importing seems to be something core to the system, which should be supported by all install profiles with an international target userbase, so we will surely have to build that into default.profile. Unless we can run other HTTP requests before install_complete() is called, we cannot do batch importing in the default profile. But install_main() and install_complete() runs through in one HTTP request, so the database setup and the "install complete" screen is done on the same request. It is not possible to add requests inbetween.
This patch has the value to allow more HTTP requests between the database setup and the "complete" screen, by allowing a redirection to Drupal paths and then possibly redirecting back to the stock "complete screen", or by displaying a custom install screen as before. The accessibility of the stock "install complete" screen by an URL is what is new.
Whether the solution presented is nice or not is up for review. Whether a similar solution is required for us to step ahead with automatic translation importing is evident.
Comment #9
meba commentedRerolling, because install_complete() needs to be aware of myprofile_profile_defaults(). Adding two lines to initial checks. I hope this is clean, i am not aware of better solution now.
Comment #10
dries commentedI understand the use-case, but I'd still like to see this checked with Neil and/or Steven -- they did a lot of work on the installer and have a good amount of background information that we might benefit from.
Isn't the goal to build the auto-locale module into the installer? As there is already a locale step in the installer shouldn't the auto-locale code be moved into install.php? Shouldn't we simply build this into the existing state machine?
Comment #11
dries commentedRelated patch: http://drupal.org/node/141637
Comment #12
gábor hojtsyOK, continue on that patch. It seems to have superior solutions (adding the custom installer states concept). It might already be ready for comitting, although the concept of states are not really clear to me. meba, could you try adapting autolocale to the state concept introduced there (ie. add a state of "importing translations"). I wonder if we can keep staying in the profile (install.php on the URL) while running the importing batch, so the user can see the task list. That would be nice usability-wise.
Comment #13
yched commentedI wonder if we can keep staying in the profile (install.php on the URL) while running the importing batch, so the user can see the task list. That would be nice usability-wise.
Yes, I tried to design the batch API so that this is possible - update.php currently works that way. See the second param ($url) for batch_process().
This is in fact possible because update.php bypasses FAPI submission workflow (which would otherwise handle batch_process itself, redirecting it to the 'regular' '/batch' processing page).
I'm not exactly sure how install.php behaves FAPI-wise, so this might need some investigation (difficult for me right now, I'm away from my coding environment)
Comment #14
yched commentedOK, install.php does use FAPI submission workflow - looking at how update.php works, I incorrectly assumed that separate scripts (not index.php-based) could not.
This means install.php's _submit callbacks are not supposed to use batch_process, and you currently don't get the opportunity to specify a custom url for the progress bar page. I'll try to refactor batch_set / batch_process API a little bit to allow for this - will do that when I come back to my coding environment in a few days. Sorry about that.
Comment #15
gábor hojtsyyched, no need to look into it. We can (and should) reuse an update.php like batch workflow (we already have code which works nicely with that). The new install states in the works allow bypassing all of the installer and get control of specific steps to run batch operations. Because the admin user is already created and logged in at the time of importing, we can also neatly restrict the batch to the admin user. So everything works nicely there.
Comment #16
yched commentedI still think it's a shame that batching in form submits does not let you specify a custom processing page. Seems like an unneeded limitation, only coming from my misconception that standalone scripts could not use the full fledged FAPI processing workflow, and had to hack their way around it like update.php does.
I'm glad to hear it does not get in the way of pre-final batches during install, but I fear there might be other cases where this bites us (and _forces_ us out of FAPI neatness into custom $_POST hacking). Or, put in another way : because of this, it seems we could currently not convert update.php to a clean FAPI workflow if we wanted to.
I perfectly understand if you prefer to keep things as they are now, though, and I will not move on this if you do not wish me to.
Comment #17
gábor hojtsyI just said it is not required by what we do *now*. What we would rather need is to be able to run batch API anonymously (with update.php), as posted elsewhere. That is a pressing issue to fix, or otherwise it is not possible anymore to run an update without being authenticated.
Comment #18
yched commentedGot it. Not easy for me to test / roll patches just now, but I submitted a possible fix in the original batch thread : http://www.drupal.org/node/127539