Posted by yhahn on December 16, 2009 at 5:31pm
14 followers
| Project: | Strongarm |
| Version: | 6.x-2.0-beta3 |
| Component: | Code |
| Category: | task |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | needs work |
Issue Summary
Strongarm currently cannot affect variables that are used very early in the Drupal bootstrap process. We should make a list of all of them and where possible / appropriate, find ways to allow Strongarm to affect them.
Comments
#1
I am sure I will find more, but at a quick glance I could not seem to proceed without errors in common.inc with "theme_default" variable in the strongarm group.
#2
I would also like to point out that many modules are defining constants that receive variable_get() values within the vody of the main module file. (eg: define('LDAPAUTH_LOGIN_CONFLICT', variable_get('ldapauth_login_conflict', LDAPAUTH_CONFLICT_LOG)); within ldapauth.module)
The module files are included before calling the init() hook thus the module defined constants end up with some default values instead of the strongarm'ed version of the variable.
#3
For modules that do that, just file a bug against it. Constant is something that's unchanging, but variables can change.
#4
Here are the variables: cache_inc, page_cache_fastpath, lock_inc, reverse_proxy, dev_query, session_inc, cache_flush_cache, cache, language_count, language_default, and site_frontpage
#5
though, site_frontpage has a little hack.
#6
Is the site_frontpage hack a good way to workaround this issue? It forces the re-execution of custom_url_rewrite_inbound which I'm not willing to do (too expensive). In our case Drupal is integrated into a larger site that includes other tools (moodle for one) and I use custom_url_rewrite_inbound to tie the systems together. There are easy ways to prevent going back through the path init process, but this seems like a larger question to be considered in any work to address the early variables issue.
#7
language_negotiation is one too, but calling drupal_init_language should reset the language variable. Testing it out to see if has any side effects, I suspect it may be too late for some things though.
#8
Quickie not much tested patch, I still suspect it's too late to effect some things.
the variable is the one that determines how language is determined (based on path, domain, etc).
#9
My 'hack' solution was in hook_strongarm() to variable_set() all 'boot' variables that are undefined since I wanted to 'strongarm' them and more importantly have them stored in code. I am going under the assumption that all my 'boot' modules followed the recommended practice and prefixed their variables with the name of the module.
I am not sure this 'hack' would be applicable for everyone. The below code is just some of my solution, which also includes caching the $strongarm data so that it is not rebuilt on every page request.
One catch to my solution is once a 'boot' variable is set and any changes to the 'boot' variable in-code won't automatically be applied. The Strongarm admin page (admin/settings/strongarm) still gives the user the option to apply any changes to a 'boot' variable.
I hope this helps.
~jake
/**
* Implementation of hook_strongarm().
*/
function mymodule_strongarm() {
// Boot modules
$result = db_query("SELECT name FROM {system} WHERE type='module' AND status=1 AND bootstrap=1 ORDER BY name");
$boot_modules = array();
while ($record = db_fetch_array($result)) {
$boot_modules[] = $record['name'];
}
$boot_modules_re = '/^('. implode('|', $boot_modules) .')_/';
// Use a unique id to determine if a variable is undefined.
$undefined = uniqid();
$variables = array(
// My very large array of almost all my entire site configuration stored in code.
);
$strongarms = array();
// Convert variables array to strongarm object.
foreach ($variables as $name => $value) {
// Set undefined boot variables.
if ( preg_match($boot_modules_re, $name) && variable_get($name, $undefined) == $undefined) {
drupal_set_message( t('Boot variable %name was strongarmed and set.', array('%name' => $name)) );
variable_set($name, $value);
}
$strongarm = new stdClass;
$strongarm->api_version = 1;
$strongarm->name = $name;
$strongarm->value = $value;
$strongarms[$name] = $strongarm;
}
return $strongarms;
}
#10
Strongarm integration with Boost suffers from this. An issue has been created: #933662: Strongarm Support.
#11
sub
#12
subscribing
#13
#14
language_content_type_[node-type] can be added to the list for the case where it is used to determine the accessibility of the "Translate" tab on nodes.
#15
sub
#16
subscribing
#17
Add glossary module to the list.
#18
If you thought for a moment that using strongarm on locale_custom_strings_en for string replacements in t() was a good idea (looks at hefox)... You'd be wrongo!
hefox and I dug through after assuming it would work, and found the opposite to be true. No good workaround as of yet, other than ditching strongarm in favor of a same language .po file translation.
#19
If you have variables that need loaded at boot time move their initialization to hook_boot instead of hook_init, would this work?
Note, I don't use strongarm (yet) but I am here because of #1132958-1: Access denied on xmlsitemap/rebuild.
#20
I got hit with this and page caching.
My personal take on a solution is to have a blacklist of variables which strongarm will not set. Explain why if people try. I expect a solution for people wanting to have non db variables that can be used earlier in the bootstrap is to define them in settings.php
#21
This will be deprecated with #1094598: Performance issues from strongarm_init() tmk