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

derhasi’s picture

Status: Active » Needs review
StatusFileSize
new20.73 KB

And there's the patch for the rework.

Status: Needs review » Needs work

The last submitted patch, fe_block_settings_export_rework-1820142-1.patch, failed testing.

pfrenssen’s picture

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

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.

derhasi’s picture

Status: Needs work » Needs review
StatusFileSize
new18.63 KB

So, there's a new patch:

  • excluded role visibility patch
  • implemented features_sanitize for the export block. ($data should already be sanitized)
  • patch file relative to the module folder

Will post a separate patch for role visibility in the given issue soon.

pfrenssen’s picture

Great! Let's see what the bot says.

derhasi’s picture

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

pfrenssen’s picture

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

Status: Needs review » Needs work

The last submitted patch, fe_block_settings_export_rework-1820142-4.patch, failed testing.

derhasi’s picture

Status: Needs work » Needs review
StatusFileSize
new28.14 KB
new14.19 KB

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

fe_block_without__features_sanitize.png

With features sanitize

fe_block_with_features_sanitize.png

derhasi’s picture

Hm, 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

pfrenssen’s picture

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

Status: Needs review » Needs work

The last submitted patch, fe_block_settings_export_rework-1820142-10.patch, failed testing.

derhasi’s picture

ksort() 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:

  • old version defaults where not converted allways (implemented hook_default_fe_block_settings_alter() to fix that)
  • _fe_block_info_by_theme() may not hold a static cache of _block_rehash(), as revert and features_get_component_states may be called in the same php process, so removed static cache again (it was not part of the old code anyway)
vinmassaro’s picture

Status: Needs work » Needs review

Thank 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?

pfrenssen’s picture

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

derhasi’s picture

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

vinmassaro’s picture

We were running pfrenssen's sandbox code before it was moved into Features Extra. We're now running the latest dev version.

derhasi’s picture

@vinmassaro, ah ok ... so it is the version=1.0. For that pfrenssen already wrote a basic test. The patch passed that in #13.

derhasi’s picture

@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 ;)

vinmassaro’s picture

@derhasi any idea if this restructuring fixes the bug I am seeing in #1830180?

derhasi’s picture

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

vinmassaro’s picture

@derhasi I'm going to try to test your patch out later today so we can get some action in here.

pfrenssen’s picture

I hope to be able to review this soon, am a little tied up with work atm.

vinmassaro’s picture

StatusFileSize
new31.9 KB
new23.63 KB

Here 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:
empty visibility

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

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:

  $export['sharethis-sharethis_block'] = array(
    'cache' => '1',
    'custom' => '0',
    'delta' => 'sharethis_block',
    'module' => 'sharethis',
    'node_types' => array(
      0 => 'event',
      1 => 'news',
    ),
    'pages' => 'news/*
videos/*
slideshow/*',
    'themes' => array(
      'seven' => array(
        'theme' => 'yale_standard',
        'status' => '1',
        'weight' => '-16',
        'region' => 'content',
      ),
      'yale_boxed' => array(
        'theme' => 'yale_standard',
        'status' => '1',
        'weight' => '-16',
        'region' => 'content',
      ),
      'yale_standard' => array(
        'theme' => 'yale_standard',
        'status' => '1',
        'weight' => '-16',
        'region' => 'content',
      ),
      'yale_wide' => array(
        'theme' => 'yale_standard',
        'status' => '1',
        'weight' => '-16',
        'region' => 'content',
      ),
    ),
    'title' => '',
    'visibility' => '1',
  );
pfrenssen’s picture

StatusFileSize
new9.98 KB
new20.24 KB

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

vinmassaro’s picture

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

vinmassaro’s picture

I 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. $theme in 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.

pfrenssen’s picture

StatusFileSize
new9.79 KB
new24.25 KB

New version of the patch:

  • Fixes problem from #24
  • Bumped export format to 2.0, it is a significant change after all :)
  • Replaced the calls to the evil _block_rehash() function with a faster version that does not write all blocks to the database without reason. This sped up the export of my test feature from 5.7 seconds to 0.8 seconds.
  • Sorted the theme specific settings.
  • Documentation improvements.
  • Renamed some variables and a function.
  • Small optimizations.

Still have to look at importing and the backwards compatibility layer.

Status: Needs review » Needs work

The last submitted patch, fe_block_settings_export_rework-1820142-28.patch, failed testing.

pfrenssen’s picture

Did some performance benchmarking by running drush fl on a site with 35 enabled features and 3 themes:

Before (with _block_rehash()):

  1. 2m3.760s
  2. 1m57.917s

After (with _fe_block_get_blocks()):

  1. 0m6.873s
  2. 0m6.937s

This is amazingly 17.5x faster!

vinmassaro’s picture

Awesome! 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.

pfrenssen’s picture

Status: Needs work » Needs review
StatusFileSize
new24.07 KB

Aww 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!

pfrenssen’s picture

New benchmarks of time drush fl:

without patch:

  1. 1m51.628s
  2. 2m9.683s

with patch from #32:

  1. 0m8.060s
  2. 0m7.917s

Still 15x faster than before, can't say I'm very disappointed :D

vinmassaro’s picture

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

pfrenssen’s picture

Status: Needs review » Fixed

Awesome news! This has been committed to 7.x-1.x-dev: 8cc38ed. Thanks!!

derhasi’s picture

Great. thank you for your excessive reviews ;)

Status: Fixed » Closed (fixed)

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