@anonymous-piwik-user opened this Issue on April 21st 2009

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-piwik-user commented on April 21st 2009

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

@robocoder commented on April 25th 2009 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-piwik-user commented on April 27th 2009

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:
<a href='/0'>#0</a> [PATH]/typo3conf/ext/piwikintegration/class.tx_piwikintegration.php(147): Zend_Config-&gt;__set('login', 'b7e240793ed3f6c...')
<a href='/1'>#1</a> [PATH]/typo3conf/ext/piwikintegration/mod1/index.php(163): tx_piwikintegration::correctPiwikConfiguration()
<a href='/2'>#2</a> [PATH]/typo3conf/ext/piwikintegration/mod1/index.php(123): tx_piwikintegration_module1-&gt;moduleContent()
<a href='/3'>#3</a> [PATH]/typo3conf/ext/piwikintegration/mod1/index.php(285): tx_piwikintegration_module1-&gt;main()
<a href='/4'>#4</a> [PATH]/typo3/mod.php(49): require('/is/htdocs/wp10...')
<a href='/5'>#5</a> {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 commented on April 27th 2009 Contributor

Can you use a temporary variable?

$superuserInfo = Zend_Registry::get('config')->superuser;
$superuserInfo['login'] = md5(microtime());
Zend_Registry::get('config')->superuser = $superuserInfo;
@anonymous-piwik-user commented on April 27th 2009

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 commented on April 27th 2009 Contributor

Thanks Kay.

@robocoder commented on June 10th 2009 Contributor

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

This Issue was closed on July 29th 2009
Powered by GitHub Issue Mirror