Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract INI file merging logic in Config class and move to new IniFileChain class. #7312

Merged
merged 17 commits into from Mar 31, 2015

Conversation

diosmosis
Copy link
Member

This is an intermediate step in allowing Config/Plugin\Manager to exist in DI. Will allow reading conifg w/o needing to instantiate Config instance (so we can read Plugins to load list before creating Config instance).

Remaining TODO:

  • revise Config tests for new logic (the tests don't need to test for merging logic)
  • move INI merging tests (and write new ones if needed) to unit test for IniFileChain
  • make sure UI tests pass

@diosmosis diosmosis added Pull Request WIP Indicates the current pull request is still work in progress and not ready yet for a review. Needs Review PRs that need a code review and removed Pull Request WIP Indicates the current pull request is still work in progress and not ready yet for a review. labels Feb 27, 2015
@diosmosis
Copy link
Member Author

@piwik/core-team This change is ready for review; don't merge for any 2.11 release, only 2.12 or later.

@mattab mattab added this to the Piwik 2.12.0 milestone Mar 1, 2015
@mattab
Copy link
Member

mattab commented Mar 1, 2015

Adding 2.12.0 milestone (feel free to add milestone to Pull Requests when they must be merged in particular versions)

@mnapoli
Copy link
Contributor

mnapoli commented Mar 1, 2015

👍

…catch the exception and augment message w/ file being read in IniFileChain. Also includes some mild refactoring to IniFileChain.
$header . "[General]\ndebug = 1\n\n[Tracker]\nanonymize = 2\n\n",
)),

array('sort, common sections before new section', array(
/*TODO: is this test needed?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess this test is needed, is there an issue with it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It tests that the order of the sections is first sections that have data in common w/ global + config, and then data that is only in config.ini.php. I don't think I can easily replicate this behavior, and I'm not sure if it's important. Is it?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's important that sections are stored in config.ini.php in the same order as they are in global.ini.php
this is because when we write the dump to file it should put [database] at top, then general, tracker, debug, and after only the plugins etc. we could also hardcode the order of sections if that's easier

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in most recent commit.

@mattab
Copy link
Member

mattab commented Mar 12, 2015

Looks good to me.

I propose that we merge this for 2.13.0, to give us more time to test this. if you are confident about it and tests, we could merge it sooner

@mattab mattab modified the milestones: Piwik 2.13.0, Piwik 2.12.0 Mar 12, 2015
diosmosis added 2 commits March 12, 2015 03:14
…onfig, the config file is erased. Also sort config sections w/ case insensitive search.
@diosmosis
Copy link
Member Author

Merging in 2.13 is ok w/ me, it would be nice if it could be done as soon as the last minor 2.12 is out. Once this is merged, I will do two more refactorings to get Config + Plugin\Manager stored in DI, then I can make test related code a lot simpler.

@diosmosis
Copy link
Member Author

@mattab Forgot about a bug I found in core while doing this pull request. In Config::array_merge_recursive_distinct (and now IniFileChain::array_merge_recursive_distinct) the code will only merge merge array values if they have the same key. But since the arrays being merged for config data are not associative, nothing ever gets merged. For example:

array_merge_recursive_distinct(
    array(
        'Plugins' => array('CustomAlerts', 'WhiteLabel')
    ),
    array(
        'Plugins' => array('SitesManager', 'CoreAdminHome')
    ),
)

will result in

array('Plugins' => array('SitesManager', 'CoreAdminHome'))

Is this the correct behavior? If not, can we fix it if it means users' common.config.ini.php might behave differently? I'm guessing not, let me know.

@mattab
Copy link
Member

mattab commented Mar 13, 2015

Is this the correct behavior? If not, can we fix it if it means users' common.config.ini.php might behave differently? I'm guessing not, let me know.

It is the correct behavior. In the global.ini.php there are loads of plugins in [Plugins] but imagine a user disables one... we should then not merge the new [Plugins] with the old one or the disabled plugin will not be disabled

@mnapoli
Copy link
Contributor

mnapoli commented Mar 30, 2015

It seems there is this test that fail and then we can merge: https://travis-ci.org/piwik/piwik/jobs/54478316#L610 Maybe that's expected

1) Piwik\Tests\Integration\ReleaseCheckListTest::test_phpFilesStartWithRightCharacter
File /home/travis/build/piwik/piwik/tmp/tmp.config.ini.php does not start with ; <?php exit;
Failed asserting that two strings are equal.
--- Expected
+++ Actual
@@ @@
-'[GeneralSecti'
+'; <?php exit;'

diosmosis added 2 commits March 30, 2015 15:53
…othingIfThereAreNoChanges so it doesn't trigger failure in ReleaseCheckListTest.
@diosmosis diosmosis removed the Needs Review PRs that need a code review label Mar 30, 2015
diosmosis added 2 commits March 30, 2015 16:28
…ings file is completely empty and add test case. Also add type hint to IniFileChain::__construct.
@diosmosis
Copy link
Member Author

UI test failures should be fixed in #7583.

diosmosis added a commit that referenced this pull request Mar 31, 2015
Extract INI file merging logic in Config class and move to new IniFileChain class for future re-use.
@diosmosis diosmosis merged commit b8db68b into master Mar 31, 2015
@diosmosis diosmosis deleted the config_ini_merge_refactor branch March 31, 2015 01:40
diosmosis pushed a commit that referenced this pull request Apr 7, 2015
…ct order. Bug occurs due to incorrect sorting that sorts sections according to which files they appear in, but not where they appear in individual files.
diosmosis pushed a commit that referenced this pull request Apr 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants