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

Using plugin postLoad hook to override configuration #672

Closed
anonymous-matomo-user opened this issue Apr 21, 2009 · 7 comments
Closed

Using plugin postLoad hook to override configuration #672

anonymous-matomo-user opened this issue Apr 21, 2009 · 7 comments
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. wontfix If you can reproduce this issue, please reopen the issue or create a new one describing it.
Milestone

Comments

@anonymous-matomo-user
Copy link

Hello piwik developers,

im proud to announce the TYPO3 extension piwikintegration, which will be released soon in the TYPO3 extension repository.
http://piwik.org/blog/2008/06/new-plugin-typo3-integration/
Its partly based on the extension discussed in the upper blog article.

Its completely integrated in TYPO3 (Backendmodule, Userauthentification, etc.).

'''But I do need a change in the main source code of Piwik.
I need an additional hook in:
https://github.com/piwik/piwik/blob/master/core/FrontController.php?rev=head#L240
which is called directly after successful creation of the configuration object.
215 try {
216 Piwik::createConfigObject();
217 } catch(Exception $e) {
218 Piwik_PostEvent('FrontController.NoConfigurationFile', $e);
219 $exceptionToThrow = $e;
220 }
Piwik_PostEvent('FrontController.ConfigurationLoaded'); //or similar

'''I would like to use this hook to dynamically override the database settings with the valid ones stored in the TYPO3 settings.
This would ensure, that the database settings are always up to date.

Thanks for your great work on PIWIK.

Regards Kay

@anonymous-matomo-user
Copy link
Author

Attachment: This is a draft of the manual for the TYPO3 Extension
manual.pdf

@robocoder
Copy link
Contributor

Um... at the point where you propose to add a post-config-load hook, plugins haven't been loaded yet, right? Might a better place be to override the config be in the typo3 plugin's postload?

@anonymous-matomo-user
Copy link
Author

hello again,

ok, i haven't seen that, i thought on the postload version before.
So i started walking to the code again to find out, how to init the config object.

static function correctPiwikConfiguration() {
        global $typo_db_host,
            $typo_db_username,
            $typo_db_password,
            $typo_db;
        //load files from piwik
        if(!defined('PIWIK_INCLUDE_PATH')) {
            define('PIWIK_INCLUDE_PATH', dirname(__FILE__).'/piwik/');
        }
        set_include_path(PIWIK_INCLUDE_PATH 
                    . PATH_SEPARATOR . PIWIK_INCLUDE_PATH . '/libs/'
                    . PATH_SEPARATOR . PIWIK_INCLUDE_PATH . '/plugins/'
                    . PATH_SEPARATOR . PIWIK_INCLUDE_PATH . '/core/'
                    . PATH_SEPARATOR . get_include_path());
        error_reporting(E_ALL);
        ini_set('display_errors', 1);
        require_once('core/Piwik.php');
        require_once('core/Config.php');
        Piwik::createConfigObject();
        #print_r(Zend_Registry::getInstance());


        Zend_Registry::get('config')->superuser->login        = md5(microtime());
}

Reading of properties works fine with that code, but i need a way to write them.
I tried this with the last line, but this line throws the following exception:

<b>Fatal error</b>:  Uncaught exception 'Zend_Config_Exception' with message 'Zend_Config is read only' in [PATH]/typo3conf/ext/piwikintegration/piwik/libs/Zend/Config.php:156
Stack trace:
#0 [PATH]/typo3conf/ext/piwikintegration/class.tx_piwikintegration.php(147): Zend_Config-&gt;__set('login', 'b7e240793ed3f6c...')
#1 [PATH]/typo3conf/ext/piwikintegration/mod1/index.php(163): tx_piwikintegration::correctPiwikConfiguration()
#2 [PATH]/typo3conf/ext/piwikintegration/mod1/index.php(123): tx_piwikintegration_module1-&gt;moduleContent()
#3 [PATH]/typo3conf/ext/piwikintegration/mod1/index.php(285): tx_piwikintegration_module1-&gt;main()
#4 [PATH]/typo3/mod.php(49): require('/is/htdocs/wp10...')
#5 {main}
  thrown in <b>[PATH]/typo3conf/ext/piwikintegration/piwik/libs/Zend/Config.php</b> on line <b>156</b>

So my new Question is, how to make this class storing changes. As i understand the documentation of Zend_Config and Line 110 in Piwik_Config::init() it should be writeable.

Regards -> Thanks for your help

Kay

@robocoder
Copy link
Contributor

Can you use a temporary variable?

$superuserInfo = Zend_Registry::get('config')->superuser;
$superuserInfo['login'] = md5(microtime());
Zend_Registry::get('config')->superuser = $superuserInfo;

@anonymous-matomo-user
Copy link
Author

worked for me, with some modifications, erhaps usefull for other integrations.

//load files from piwik
        if(!defined('PIWIK_INCLUDE_PATH')) {
            define('PIWIK_INCLUDE_PATH', dirname(__FILE__).'/piwik/');
        }
        set_include_path(PIWIK_INCLUDE_PATH 
                    . PATH_SEPARATOR . PIWIK_INCLUDE_PATH . '/libs/'
                    . PATH_SEPARATOR . PIWIK_INCLUDE_PATH . '/plugins/'
                    . PATH_SEPARATOR . PIWIK_INCLUDE_PATH . '/core/'
                    . PATH_SEPARATOR . get_include_path());
        #error_reporting(E_ALL);
        #ini_set('display_errors', 1);
        require_once('core/Piwik.php');
        require_once('core/Config.php');
        Piwik::createConfigObject();
        #print_r(Zend_Registry::getInstance());


        $superuser = Zend_Registry::get('config')->superuser->toArray();
        $superuser['login']    = md5(microtime());
        $superuser['password'] = md5(microtime());
        Zend_Registry::get('config')->superuser = new Zend_Config($superuser);

@robocoder
Copy link
Contributor

Thanks Kay.

@robocoder
Copy link
Contributor

Shouldn't you have: Zend_Config($superuser, true) ?

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. wontfix If you can reproduce this issue, please reopen the issue or create a new one describing it.
Projects
None yet
Development

No branches or pull requests

2 participants