@robocoder opened this Issue on September 20th 2010 Contributor

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

@robocoder commented on September 20th 2010 Contributor

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.

@mattab commented on September 21st 2010 Member

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.

@robocoder commented on November 26th 2011 Contributor

(In [5484]) refs #1713

@robocoder commented on December 8th 2011 Contributor

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

  • CASLogin
  • ClickHeat
  • DoNotTrack
  • EntryPage
  • Gall
  • GeoIPMap
  • HttpAuthLogin
  • KSVisitorImport
  • LdapLogin
  • Maps
  • MobileAnalytics
  • OpenIDLogin
  • OxidPlugin
  • Signup
@robocoder commented on December 8th 2011 Contributor

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

@mattab commented on December 12th 2011 Member

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!

@robocoder commented on December 21st 2011 Contributor

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
@robocoder commented on December 21st 2011 Contributor

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

@mattab commented on December 22nd 2011 Member

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?
@robocoder commented on December 23rd 2011 Contributor
  • 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.

@robocoder commented on December 23rd 2011 Contributor

in [5608], added backward compatibility layer

@mattab commented on December 24th 2011 Member

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

@robocoder commented on December 24th 2011 Contributor

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

@robocoder commented on December 25th 2011 Contributor

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

@mattab commented on February 25th 2012 Member

See also the double quotes bug in #2968

@robocoder commented on March 4th 2012 Contributor

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

@robocoder commented on March 4th 2012 Contributor

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

@robocoder commented on March 5th 2012 Contributor

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

@robocoder commented on March 5th 2012 Contributor

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

@robocoder commented on March 5th 2012 Contributor

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

@mattab commented on March 5th 2012 Member

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

@mattab commented on March 5th 2012 Member

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

@mattab commented on March 5th 2012 Member

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

@mattab commented on March 5th 2012 Member

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

@robocoder commented on March 5th 2012 Contributor

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

@mattab commented on March 5th 2012 Member

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

@mattab commented on March 5th 2012 Member
  • 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.)
@mattab commented on March 5th 2012 Member
  • 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 :)

@mattab commented on March 5th 2012 Member
  • Install is broken too..: No entry is registered for key 'config'
@robocoder commented on March 6th 2012 Contributor

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

@robocoder commented on March 6th 2012 Contributor

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

@robocoder commented on March 6th 2012 Contributor

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

@robocoder commented on March 6th 2012 Contributor

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?)
@robocoder commented on March 7th 2012 Contributor

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

@robocoder commented on March 7th 2012 Contributor

(In [5987]) refs #1713

@mattab commented on March 8th 2012 Member

(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
@mattab commented on March 8th 2012 Member

(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)
@robocoder commented on March 9th 2012 Contributor

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

@robocoder commented on March 9th 2012 Contributor

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

@robocoder commented on March 9th 2012 Contributor

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

@robocoder commented on March 9th 2012 Contributor

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
@robocoder commented on March 9th 2012 Contributor

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

@robocoder commented on March 9th 2012 Contributor

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

@mattab commented on March 9th 2012 Member

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"

@robocoder commented on March 10th 2012 Contributor

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

@robocoder commented on March 10th 2012 Contributor

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

@robocoder commented on March 10th 2012 Contributor

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

@mattab commented on March 14th 2012 Member

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

@mattab commented on March 14th 2012 Member

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
@robocoder commented on March 14th 2012 Contributor

It's intentional and is a result of array_unmerge.

@mattab commented on March 15th 2012 Member

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?

@robocoder commented on March 15th 2012 Contributor

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

@mattab commented on March 20th 2012 Member

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?

@mattab commented on March 20th 2012 Member

(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

@robocoder commented on March 24th 2012 Contributor

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

@robocoder commented on March 24th 2012 Contributor

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

@mattab commented on March 24th 2012 Member

Thanks for the better fix!!

@mattab commented on March 28th 2012 Member

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

@mattab commented on March 30th 2012 Member
  • Maybe it would be possible to remove Zend/Config files from libs/Zend ?
@robocoder commented on March 31st 2012 Contributor

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.

@mattab commented on April 2nd 2012 Member

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?

@robocoder commented on April 3rd 2012 Contributor

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.

@mattab commented on May 25th 2012 Member

Looks OK, I think some users will complain that the config file automatically removes the config settings which are similar to the global.ini.php but we can wait and see how many actually mention it, since fixing it is not trivial :) Thanks for these great refactoring ad code improvements!

@mattab commented on May 25th 2012 Member

(In [6311]) Perf optimization refs #1713

This Issue was closed on May 29th 2012
Powered by GitHub Issue Mirror