As allready mentioned in #868828: Capture role visibility settings in fe_block?, I guess there is a need to rework the export format to be more readable, better comparable and to support the features UI better.
My suggestion ist to build an export format like that:
//...
$export['menu-menu-application'] = array(
'module' => 'menu',
'delta' => 'menu-application',
'custom' => '0',
'visibility' => '0',
'pages' => '',
'title' => '',
'cache' => '-1',
'themes' => array(
'mycustom' => array(
'theme' => 'mycustom',
'status' => 0,
'weight' => '-49',
'region' => '',
),
'rubik' => array(
'theme' => 'rubik',
'status' => 0,
'weight' => '-54',
'region' => '',
),
),
'roles' => array(
'admin' => '4',
'authenticated user' => '2',
),
'node_types' => array(
'story',
),
);
//...
This format would make the code
- ... more readable, as the theme specifc settings and role/node_type settings are directly associated within the block array.
- ... better comparable (in git diff e.g.) as we have only one place for all block info, and it is not split in several theme arrays.
- ... work with the Features UI, so we can see which block settings already are exported, as options array and export array share the same keys.
I'll attach a reowkr patch for that in the next commit, that allready implements the role visibility code of #868828: Capture role visibility settings in fe_block?.
Comments
Comment #1
derhasi commentedAnd there's the patch for the rework.
Comment #3
pfrenssenI really love this idea. It would be a dramatic improvement over the current export format and I don't see any drawbacks. I'd love to get this in. I have two initial remarks:
_features_sanitize()Also the tests should pass and we should provide some additional tests, for example to test the conversion of the old export format to the new.
A lot of code has moved in this patch (understandably) which makes the patch quite hard to read atm. If you can manage to separate out the role visibility and get the tests to pass I'll review this in more detail.
Comment #4
derhasi commentedSo, there's a new patch:
Will post a separate patch for role visibility in the given issue soon.
Comment #5
pfrenssenGreat! Let's see what the bot says.
Comment #6
derhasi commentedI just recognized, using
_features_sanitize()also removes all empty values. That is a bad idea in my opinion, as this will make the code less readable. But first, let's see how the test runs.Comment #7
pfrenssenThe Features-module itself uses it so I guess we should follow suit. We do lose some code legibility, but on the other hand we win consistency, and patch readability.
Comment #9
derhasi commentedFeatures itself does not use _features_sanitize in components. It only uses it for comparing stuff and building hash values.
Besides, with using it, there will be a lot of information lost, and we would need to do a lot more work for providing the right default empty value (is it "", or 0 or "0"). Additionally we won't be able to recognize if a value simply wasn't avaiable, when the feature was created, or if the settings was left empty by purpose.
Attached an example for readability and information loss.
Without features sanitize.
With features sanitize
Comment #10
derhasi commentedHm, ok, the machine_name handling was not correct. Here's a patch that fixes that.
Additionally I replaced _features_sanitize() with ksort(). In any subarray, I allready made sure the information is sorted properly.
// Run testbot run ;)
edit: dumb me -- commented out the ksort :/ --- ok, will wait for testbot, before fixing it
Comment #11
pfrenssenOK I guess you're right, if Features runs the data through
_features_sanitize()when it is doing the comparisons we don't really need it here.ksort()is not sufficient btw, it does not recurse through the arrays when sorting.Comment #13
derhasi commentedksort()in this case ishould be sufficient, as all sub arrays (currently "themes", "node_types") are allready sorted (@see_fe_block_get_block_node_types()and_fe_block_active_themes()).Fixed some bugs occuring in the last patch, that caused the test to fail:
Comment #14
vinmassaro commentedThank you guys for all the work being done here. We are relying heavily on Features Extra for initial block configurations in our university deployment. Will the work being done here require re-exporting of blocks and block configuration once it is committed?
Comment #15
pfrenssen@vinmassaro, no the goal is to keep it transparent. It will support both the old and new export formats. When you update your features it will be converted to the new format automatically.
Comment #16
derhasi commentedSo it is.
@vinmassaro, do you use the "very old" version ( the version without a 'version' element in the export?). If so, it was great if you could provide a test with an example feature for that old version.
Comment #17
vinmassaro commentedWe were running pfrenssen's sandbox code before it was moved into Features Extra. We're now running the latest dev version.
Comment #18
derhasi commented@vinmassaro, ah ok ... so it is the version=1.0. For that pfrenssen already wrote a basic test. The patch passed that in #13.
Comment #19
derhasi commented@pfrenssen, did you have time to review it? Would be great if we could push it to dev soon, so we can build other patches on top of it ;)
Comment #20
vinmassaro commented@derhasi any idea if this restructuring fixes the bug I am seeing in #1830180?
Comment #21
derhasi commented@vinmassaro, I guess so. As then the code should not have duplicate information (spread in different themes) that might be a reason for that bug. At least we'll get a better info array to debug that behaviour.
Comment #22
vinmassaro commented@derhasi I'm going to try to test your patch out later today so we can get some action in here.
Comment #23
pfrenssenI hope to be able to review this soon, am a little tied up with work atm.
Comment #24
vinmassaro commentedHere are my findings after applying patch from #13 to 7.x-1.x. I am running Features 7.x-2.0-beta1. I patched and re-exported my feature since it showed as overridden.
1. When editing any of the blocks with exported block settings, the visibility section is not editable:

2. I am exporting region settings for four themes. Only one theme is being set after enabling the feature:

Here's is what is happening in code. The value for key 'theme' appears that it should match for each theme but yale_standard is being set for each one:
Comment #25
pfrenssenI have reviewed the exporting part. but still have to do the importing and the converter for the old export format. It looks great! You did major refactoring and cleanup of the code too, awesome work!
I only looked at the code for now, still have to actually run it. I also still want to check the bug reported by vinmassaro in #24.
Updated patch contains documentation cleanups, some small optimizations and I renamed two functions.
Comment #26
vinmassaro commented@pfrenssen: Please ignore the first part of #24. I just realized it is from a misbehaving Chrome extension.
I just tested your patch in #25 and when exporting my feature under the new version, it tries to change all of my region visibility settings to the same theme (as seen in #24). The page visibility bug I am seeing in http://drupal.org/node/1830180 appears to be fixed now.
Comment #27
vinmassaro commentedI am having trouble tracing back the issue in #24. I *think* it is caused by
_fe_block_info_by_theme()in the patch from #25.$themein this function only has one value and it is set to your currently enabled theme. This is then set as the value for each 'theme' key.Comment #28
pfrenssenNew version of the patch:
Still have to look at importing and the backwards compatibility layer.
Comment #30
pfrenssenDid some performance benchmarking by running drush fl on a site with 35 enabled features and 3 themes:
Before (with _block_rehash()):
After (with _fe_block_get_blocks()):
This is amazingly 17.5x faster!
Comment #31
vinmassaro commentedAwesome! As I mentioned earlier, we are really dependent on Features Extra in our university D7 install, so your work on this issue is much appreciated. I will be testing this updated patch today or tomorrow and will let you know how it works out.
Comment #32
pfrenssenAww it was too good to be true. This patch removes the drupal_static() from _fe_block_get_blocks(). A bit slower now but at least the tests pass.
@vinmassaro: excellent! I'm looking forward to it!
Comment #33
pfrenssenNew benchmarks of
time drush fl:without patch:
with patch from #32:
Still 15x faster than before, can't say I'm very disappointed :D
Comment #34
vinmassaro commentedThis patch is working great. I applied the patch and re-exported my feature, and the code changes looked correct. I then installed the feature and the block configurations and visibility settings are correct. The block settings file is way cleaner. Very nice work!
Comment #35
pfrenssenAwesome news! This has been committed to 7.x-1.x-dev: 8cc38ed. Thanks!!
Comment #36
derhasi commentedGreat. thank you for your excessive reviews ;)