Ticket #1713 (new New feature)

Opened 20 months ago

Last modified 2 weeks ago

Config class refactoring

Reported by: vipsoft Owned by: vipsoft
Priority: critical Milestone: 1.7.2 - Piwik 1.7.2
Component: Core Keywords:
Cc: Sensitive: no

Description (last modified by vipsoft) (diff)

Increase abstraction and reduce runtime dependence on Zend Framework. This provides a more uniform interface for core and plugin developers.

That is:

  • use Piwik_Config::getInstance() instead of Zend_Registry::get('config')
  • use Piwik_Config::getInstance() instead of Piwik_Tracker_Config::getInstance()

Read individual setting or entire section:

$value = Piwik_Config::getInstance()->section['option'];

$section = Piwik_Config::getInstance()->section;

Change individual setting or entire section:

Piwik_Config_Writer::getInstance()->section = $newSection;

Piwik_Config_Writer::getInstance()->section['option'] = $value;

Split/move core/Config.ini.php into:

  • Config/Abstract.php - base class
  • Config.php - config reader; can set but does not save
  • Config/Writer.php - config reader/writer; will save changes

Remove core/Config/Ini.php and core/Tracker/Config.php.

Impact:

  • not backwards compatible because Zend_Config isn't used to represent array options
  • 3rd party plugins affected: TBD

Must prevent recurrence of #1945. (Ideally, repair config.ini.php, perhaps by comparing against global.ini.auto-backup-before-update.php to isolate which General settings were actually custom.)

Change History

  Changed 20 months ago by vipsoft

Another thought: could we drop the .ini format and switch to pure php? We could use var_export when writing. This allows us to eliminate the dependency on parse_ini_file() -- and the workaround when it is disabled. Loading would be faster and it is cacheable by APC.

  Changed 20 months ago by matt

Refactoring sounds great. However I vote for keeping INI format for now, as it is universal. Editing php arrays for config is not as friendly, and also wouldn't easily support comments.

  Changed 19 months ago by vipsoft

  • milestone changed from Features requests 1.x or 2.x to 1.2 - Piwik 1.2

  Changed 17 months ago by vipsoft

  • description modified (diff)

  Changed 14 months ago by vipsoft

  • owner set to vipsoft

  Changed 11 months ago by vipsoft

  • milestone changed from 1.6 Piwik 1.6 to 1.x - Piwik 1.x

  Changed 6 months ago by vipsoft

(In [5484]) refs #1713

  Changed 6 months ago by vipsoft

  • description modified (diff)

  Changed 6 months ago by vipsoft

  • description modified (diff)

  Changed 6 months ago by vipsoft

  • description modified (diff)

Quick grep shows the following non-core plugins are affected:

  • CASLogin
  • ClickHeat
  • DoNotTrack
  • EntryPage
  • Gall
  • GeoIPMap
  • HttpAuthLogin
  • KSVisitorImport
  • LdapLogin
  • Maps
  • MobileAnalytics
  • OpenIDLogin
  • OxidPlugin
  • Signup

  Changed 5 months ago by vipsoft

(In [5537]) refs #1713 - create branch for review

  Changed 5 months ago by matt

How do you plan to deal with the affected plugins? will you repackage all plugins to solve the bug and require an update?

I wouldn't put high priority since it won't add any feature, fix a bug and it breaks all plugins.

Otherwise looks good, always nice to simplify code base!

  Changed 5 months ago by vipsoft

This would probably be a good time to fix/repackage all the affected plugins since 3rd party plugins aren't routinely tested for compatibility.

Also:

  • blog and/or post to piwik-hackers before this makes it into a release
  • an update script would disable known affected 3rd party plugins

  Changed 5 months ago by vipsoft

(In [5586]) refs #1713 - to matt for review/feedback

  Changed 5 months ago by matt

Wow, nice work Anthon! long due change indeed :) Review:

  • isMacOs && Ip.test.php changes are probably unrelated to this change
  • Did you check that password in config files still work when it contains <>&"' characters (I saw that html decode call was removed in plugins/DBStats/API.php
  • To go forward with this proposal, we must first ensure that all plugins are updated and packaged for the new version.
    • OR, what do you think about making the old format Zend_Registry::get('config')->General->anonymous_user_enable_use_segments_API still working for "READ" operations? Ie. we could add a fake config object that would reroute to the Piwik_Config::getInstance() equivalent? I suppose that by doing so, most plugins would not need repackaging since most plugins would only READ values from the file. The goal would be to make this commit less painful and less risky and not require all existing plugin users to upgrade their third party plugins after the piwik core update. What do you think?

  Changed 5 months ago by vipsoft

  • Yes, there are some unrelated changes there. It just happens that my dev environment was MacOS X. I'll merge the unrelated changes into trunk this weekend.
  • DBStats/API.php was double decoding. It predates [1165].

I was trying to avoid cruft in the code base, but I agree a backward compatibility layer would reduce headaches. I'll look into this.

  Changed 5 months ago by vipsoft

in [5608], added backward compatibility layer

  Changed 5 months ago by matt

Great :) After adding this layer, what are the plugins that still need updating? is there any at all? If so, can we scheduled this for Piwik 1.8? Can you think of any other risk in this change? Thanks!!

  Changed 5 months ago by vipsoft

  • milestone changed from 1.x - Piwik 1.x to 1.8 Piwik 1.8

Should work with the aforementioned plugins. I'll be busy testing this weekend. Otherwise looking good for 1.8

  Changed 5 months ago by vipsoft

(In [5615]) refs #1713 - naming inconsistency with Config.php

  Changed 3 months ago by matt

See also the double quotes bug in #2968

  Changed 3 months ago by vipsoft

(In [5951]) refs #1713 - merge dev branch to trunk (config class refactoring)

  Changed 3 months ago by vipsoft

(In [5952]) refs #1713 - fix svn property on core/Config/Compat.php

  Changed 3 months ago by vipsoft

  • milestone changed from 1.8 Piwik 1.8 to 1.7.x - Piwik 1.7.2

  Changed 3 months ago by vipsoft

(In [5954]) refs #1713 - partially resolve regression from the merge

  Changed 3 months ago by vipsoft

(In [5955]) refs #1713, refs #1331 - workaround for auto-update

  Changed 3 months ago by vipsoft

(In [5957]) refs #1713 - rollback this file to r5454; workaround for #1331

  Changed 3 months ago by matt

(In [5959]) Refs #1713 Fixing NOTICE when element not in config file

  Changed 3 months ago by matt

Great code cleanup and getting rid of akward code for sure :)

I notice that the trunk is broken, many integration tests fail - do you see the same behavior on your local box?

for some reason Jenkins fails at webtests when it should fail in the unit/integration tests, not sure why?

Thanks

  Changed 3 months ago by matt

(In [5960]) Refs #1713 fixes changing SU email

  Changed 3 months ago by matt

(In [5961]) Refs #1713 Admin settings were not saved

  Changed 3 months ago by vipsoft

I don't yet know why the integration tests pass on dev6 but fail locally.

  Changed 3 months ago by matt

OK, I can help investigate in ~ 1 hour if you're still stuck!

  Changed 3 months ago by matt

  • On rewriting the config file, the sections are not put back in the order they were in. It is important that sections are written in the order found in global.ini.php (ie. superuser, then database, etc.)

  Changed 3 months ago by matt

  • Running integration tests is overwriting the local config.ini.php !! not so good, I lost my local mods

EDIT: Strange I just lost my [Tracker] section. Thanks to Eclipse local history I could restore :)

  Changed 3 months ago by matt

  • Install is broken too..: No entry is registered for key 'config'

  Changed 3 months ago by vipsoft

(In [5967]) refs #1713 - fix installation; will have to workaround #1331 some other way

  Changed 3 months ago by vipsoft

(In [5968]) refs #1713 - splitting reader/writer just isn't possible with the way integration tests run

  Changed 3 months ago by vipsoft

(In [5971]) refs #1713 - fix installation and workaround #1331 (deja vu?)

  Changed 3 months ago by vipsoft

To do:

  • broken one click update; I'll narrow this down today
  • re-write sections in original order, appending new sections at the end
  • investigate disappearing section (was it the same as global.in?)

  Changed 3 months ago by vipsoft

(In [5980]) refs #1713, refs #1331 - this should fix the one click update

  Changed 2 months ago by vipsoft

(In [5987]) refs #1713

  Changed 2 months ago by matt

(In [6000]) Refs #1713

  • keep sections that don't exist inglobal.ini.php (prevent NOTICE).
  • save sections in order that they appear in global.ini.php

  Changed 2 months ago by matt

(In [6002]) Refs #1713

  • Ignoring local config.ini.php when running tests
  • Disable IP Anonymisation if it's enabled on dev box (was causing some integration tests fail)

  Changed 2 months ago by vipsoft

(In [6011]) refs #1713 - refactor for testability

  Changed 2 months ago by vipsoft

(In [6012]) refs #1713 - add unit test for dumpConfig()

  Changed 2 months ago by vipsoft

(In [6021]) refs #1713 - update the dirty bit and sorting tests

  Changed 2 months ago by vipsoft

Four of the tests are failing.

  • local copy (different), cached get - this is suboptimal
  • local copy, cached set local, new section - this is a bug
  • local copy, cached set global, new section - this is a bug
  • sort, common sections before new section - this is a bug

  Changed 2 months ago by vipsoft

(In [6022]) refs #1713 - aha, bad tests

  Changed 2 months ago by vipsoft

(In [6023]) refs #1713 - fix problem with new sections not being added; comment out two tests where writer is sub-optimal (i.e., it writes out a new config file even if there is no change)

  Changed 2 months ago by matt

The web tests do not fail, but trunk install is broken currently

"SQLSTATE[42S02]: Base table or view not found: 1146 Table 'piwik_trunk_testsvn1.piwik_option' doesn't exist"

  Changed 2 months ago by vipsoft

(In [6028]) refs #1713 - remove Config destruct()

  Changed 2 months ago by vipsoft

(In [6029]) refs #1713 - set() should set dirty bit

  Changed 2 months ago by vipsoft

(In [6034]) refs #1713 - not so lightweight anymore, but still an improvement by unifying Zend_Config and Piwik_Tracker_Config

  Changed 2 months ago by matt

Feedback

  • Great work. Maintaining BC and simplifying code and interfaces, big win for the software maintainability and plugin developers.
  • Do you know why the webtest was not failing when trunk was broken? Is it because the webtest was disabled maybe?
  • It looks good for me, is the ticket now fixed or are there pending tasks?

Thanks for your nice follow up too, that was a tricky large core change :)

  Changed 2 months ago by matt

  • priority changed from normal to critical

I noticed a bug:

  • when the config.ini.php contains a value the same as global.ini.php, it gets deleted at the next config file write.
  • this is causing some frustration, because it means opening the file global.ini.php every time again to enable some custom features
  • the solution would be that once a value has been modified in config.ini.php, it is always left there, even when the value is set to the same as in global.ini.php

  Changed 2 months ago by vipsoft

It's intentional and is a result of array_unmerge.

  Changed 2 months ago by matt

I think it's more usable if we leave the values in the file... it's common to switch 1 to 0 to 1 etc. if the line has to be fully written each time, it's not practical. I vote for revert and do it like before, thoughts?

  Changed 2 months ago by vipsoft

This would reintroduce #1945 where changing a local setting programmatically would copy the rest of the section.

  Changed 2 months ago by matt

OK, maybe we can keep track of which config elements were first read from config.ini.php, keep a flag for those, and always write them out in config.ini.php?

  Changed 2 months ago by matt

(In [6075]) refs #1713 removing login=root from global.ini.php or it is removed from config.ini.php on rewrite if SU login is root

  Changed 2 months ago by vipsoft

(In [6109]) refs #1713 - workaround php 5.1.x - php 5.2.0 reference bugs when config is returned by reference

  Changed 2 months ago by vipsoft

(In [6111]) refs #1713 - tracker config did not previously throw exceptions (BC); revert [6107] and part of [6103]

  Changed 2 months ago by matt

Thanks for the better fix!!

follow-up: ↓ 67   Changed 8 weeks ago by matt

Open critical issues related to the new config:

  • login=root and salt=XX are not in the config file on rewrite. During the update to 1.7.2-rc the login=root and salt=xx should be copied to the config./ini.php (or it prevents Super User login!! CRITICAL)
  • for usability it is important to leave the modified config settings in config.ini.php so as to avoid users to go back and forth between config and global files

@vipsoft Do you think these could be tackled in next days as to be able to release 1.7.2 ? Thanks!!

  Changed 7 weeks ago by matt

  • Maybe it would be possible to remove Zend/Config files from libs/Zend ?

in reply to: ↑ 65 ; follow-up: ↓ 68   Changed 7 weeks ago by vipsoft

Replying to matt:

Open critical issues related to the new config: * login=root and salt=XX are not in the config file on rewrite. During the update to 1.7.2-rc the login=root and salt=xx should be copied to the config./ini.php (or it prevents Super User login!! CRITICAL) * for usability it is important to leave the modified config settings in config.ini.php so as to avoid users to go back and forth between config and global files @vipsoft Do you think these could be tackled in next days as to be able to release 1.7.2 ? Thanks!!

I think I understand the first issue. A core/Updates/ script should suffice.

I understand the potential usability issue in the second case, but I can't think of any easy fix at the moment.

Replying to matt:

* Maybe it would be possible to remove Zend/Config files from libs/Zend ?

Off-hand, I'm going to say yes it's possible, but I haven't tried.

in reply to: ↑ 67   Changed 7 weeks ago by matt

A core/Updates/ script should suffice.

OK

I understand the potential usability issue in the second case, but I can't think of any easy fix at the moment.

My idea was to remove the array_unmerge, and instead, write out only the settings that are currently written out in the local config.ini.php (not remove any setting or add any new one from global).

eg. This could be done by checking configLocal before when writing out the config file?

  Changed 7 weeks ago by vipsoft

array_unmerge solves the problem of #1945, where changing one setting in a section would copy the rest of the section, such that the entire section was duplicated in local config.ini.php.

  Changed 2 weeks ago by matt

  • milestone changed from 1.7.x - Piwik 1.7.2 to 1.7.2 - Piwik 1.7.2
Note: See TracTickets for help on using tickets.