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

Config class refactoring #1713

Closed
robocoder opened this issue Sep 20, 2010 · 64 comments
Closed

Config class refactoring #1713

robocoder opened this issue Sep 20, 2010 · 64 comments
Assignees
Labels
Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc. Major Indicates the severity or impact or benefit of an issue is much higher than normal but not critical.
Milestone

Comments

@robocoder
Copy link
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
Copy link
Contributor Author

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
Copy link
Member

mattab commented Sep 21, 2010

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
Copy link
Contributor Author

(In [5484]) refs #1713

@robocoder
Copy link
Contributor Author

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
Copy link
Contributor Author

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

@mattab
Copy link
Member

mattab commented Dec 12, 2011

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
Copy link
Contributor Author

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
Copy link
Contributor Author

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

@mattab
Copy link
Member

mattab commented Dec 22, 2011

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
Copy link
Contributor Author

  • 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
Copy link
Contributor Author

in [5608], added backward compatibility layer

@mattab
Copy link
Member

mattab commented Dec 24, 2011

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
Copy link
Contributor Author

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

@robocoder
Copy link
Contributor Author

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

@mattab
Copy link
Member

mattab commented Feb 25, 2012

See also the double quotes bug in #2968

@robocoder
Copy link
Contributor Author

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

@robocoder
Copy link
Contributor Author

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

@robocoder
Copy link
Contributor Author

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

@robocoder
Copy link
Contributor Author

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

@robocoder
Copy link
Contributor Author

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

@mattab
Copy link
Member

mattab commented Mar 5, 2012

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

@mattab
Copy link
Member

mattab commented Mar 5, 2012

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
Copy link
Member

mattab commented Mar 5, 2012

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

@mattab
Copy link
Member

mattab commented Mar 5, 2012

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

@robocoder
Copy link
Contributor Author

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

@mattab
Copy link
Member

mattab commented Mar 5, 2012

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

@mattab
Copy link
Member

mattab commented Mar 5, 2012

  • 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
Copy link
Member

mattab commented Mar 5, 2012

  • 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
Copy link
Member

mattab commented Mar 5, 2012

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

@robocoder
Copy link
Contributor Author

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

@mattab
Copy link
Member

mattab commented Mar 9, 2012

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
Copy link
Contributor Author

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

@robocoder
Copy link
Contributor Author

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

@robocoder
Copy link
Contributor Author

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

@mattab
Copy link
Member

mattab commented Mar 14, 2012

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
Copy link
Member

mattab commented Mar 14, 2012

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
Copy link
Contributor Author

It's intentional and is a result of array_unmerge.

@mattab
Copy link
Member

mattab commented Mar 15, 2012

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
Copy link
Contributor Author

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

@mattab
Copy link
Member

mattab commented Mar 20, 2012

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
Copy link
Member

mattab commented Mar 20, 2012

(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
Copy link
Contributor Author

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

@robocoder
Copy link
Contributor Author

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

@mattab
Copy link
Member

mattab commented Mar 24, 2012

Thanks for the better fix!!

@mattab
Copy link
Member

mattab commented Mar 28, 2012

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
Copy link
Member

mattab commented Mar 30, 2012

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

@robocoder
Copy link
Contributor Author

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
Copy link
Member

mattab commented Apr 2, 2012

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
Copy link
Contributor Author

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
Copy link
Member

mattab commented May 25, 2012

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
Copy link
Member

mattab commented May 25, 2012

(In [6311]) Perf optimization refs #1713

This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement For new feature suggestions that enhance Matomo's capabilities or add a new report, new API etc. Major Indicates the severity or impact or benefit of an issue is much higher than normal but not critical.
Projects
None yet
Development

No branches or pull requests

2 participants