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

Issue after Upgrading module #4

Closed
teseo opened this issue Jul 17, 2014 · 14 comments
Closed

Issue after Upgrading module #4

teseo opened this issue Jul 17, 2014 · 14 comments

Comments

@teseo
Copy link

teseo commented Jul 17, 2014

Hello David,

I believe you should just remove from vendor/davidhavl/dherrorlogging/config/module.config.php the whole array:

    'service_manager' => array(

        'aliases' => array(
            'dherrorlogging_zend_db_adapter' => 'Zend\Db\Adapter\Adapter',
        ),

        'factories' => array(
            'DhErrorLogging\Logger' => 'DhErrorLogging\Factory\Logger\LoggerFactory',
            'DhErrorLogging\ErrorReferenceGenerator' => 'DhErrorLogging\Factory\Generator\ErrorReferenceGeneratorFactory'
        ),


    ),

And only leaving it on dherrorlogging.global.php. Just after the upgrade I got the same error

Fatal error: Uncaught exception 'Zend\ServiceManager\Exception\InvalidServiceNameException' with message 'An alias by the name "dherrorloggingzenddbadapter" or "dherrorlogging_zend_db_adapter" already exists' 

My proposal is, same way you commented the log_writter part, whether leave it commented or just in the global.php config. I had to do this in the module.config.php :

    'service_manager' => array(
/*
        'aliases' => array(
            'dherrorlogging_zend_db_adapter' => 'Zend\Db\Adapter\Adapter',
        ),

        'factories' => array(
            'DhErrorLogging\Logger' => 'DhErrorLogging\Factory\Logger\LoggerFactory',
            'DhErrorLogging\ErrorReferenceGenerator' => 'DhErrorLogging\Factory\Generator\ErrorReferenceGeneratorFactory'
        ),*/

    ),

And this in my global.php config:

return array(
    'dherrorlogging' => $config,

    'service_manager' => array(
        'factories' => array(
            'dherrorlogging_zend_db_adapter' => function ($sm){
                    $config = $sm->get('Config');

                    $dbAdapter = new Adapter(array(
                        'driver' => 'Mysqli',
                        'database' => $dbname, // from config
                        'username' => $user, // from config
                        'password' => $password,// from config
                        'host'     => $host,// from config
                        'port'     => $port,// from config
                    ));
                    return $dbAdapter;
                },
            'DhErrorLogging\Logger' => 'DhErrorLogging\Factory\Logger\LoggerFactory',
            'DhErrorLogging\ErrorReferenceGenerator' => 'DhErrorLogging\Factory\Generator\ErrorReferenceGeneratorFactory'
        ),

    ),
);

By the way, in the global.php config you are calling the main config array $config and in the bottom you are doing a ternary to the $settings variable. Is that correct?

@DavidHavl
Copy link
Owner

Thanks about the config/settings bug. This is now fixed.

As for the alias... it works perfectly on my system.
When it comes to configs, they are merged together before they are processed, so the alias in module config will be overwritten by the one in global config.
Is it possible that your application is setting up the service manager twice?

@teseo
Copy link
Author

teseo commented Jul 17, 2014

I'm pretty new to Zend Framework and some deep basics I'm not clear yet. It might be possible. Do you know how can I trace if the service manager is setup twice?

Many thanks for your patience!

@DavidHavl
Copy link
Owner

No worries. Do you have the zend developer tools installed?

@teseo
Copy link
Author

teseo commented Jul 17, 2014

Yes I do.

@DavidHavl
Copy link
Owner

You can check the final config, although I just realized you can't cause it throws error.

@teseo
Copy link
Author

teseo commented Jul 17, 2014

Yes, Is only once. I really would like to trace this down as it might affect in the future if you say you have the right way to do it.

I'm a bit lost what other reason could be to have overwritten the global config with vendor's config?

@DavidHavl
Copy link
Owner

You can maybe hook into service manager and have it reporting to you how many times it gets setup?
It may also be something more obvious I/you are missing.

@teseo
Copy link
Author

teseo commented Jul 17, 2014

Ok, I will do it after what I'm debugging now. The module seems to not to log exceptions in console mode.

@teseo
Copy link
Author

teseo commented Jul 17, 2014

Ok, got it. In Module.php line 74. When you have this closure

        $sharedEventManager->attach('Zend\Mvc\Application', array(MvcEvent::EVENT_DISPATCH_ERROR, MvcEvent::EVENT_RENDER_ERROR), function($event) use ($logger, $generator) {}

On a web environment it gets the exception but not in console mode. I'm going to trace where we can fix this and propose a workaround / fix.

@teseo
Copy link
Author

teseo commented Jul 17, 2014

I've been working a little while and I figured out that when in console you throw an exception is not attaching to the event manager. Is not only it's not any of MvcEvent::EVENT_DISPATCH_ERROR, MvcEvent::EVENT_RENDER_ERROR even in if you set '*' is not getting attached.

Any idea? I'm walking in circles.

@DavidHavl
Copy link
Owner

Hey Javier, I will have a look all of the issues later tonight or tomorrow. Thanks for your input.

@teseo
Copy link
Author

teseo commented Jul 17, 2014

Brilliant David. No rush.

For the moment with a bit of deeper debugging, I'm good. It would be just nice having errors logged on console mode.

Cheers mate!

@teseo
Copy link
Author

teseo commented Jul 17, 2014

Fixed the configuration issue. It was a very silly problem. The configuration in module.config.php was fine. The problem was with my factory name. I had a collision with "dherrorlogging_zend_db_adapter" the repetition was not because it was coming from your config but from my factory name:

'aliases' => array(
            'dherrorlogging_zend_db_adapter' => 'Zend\Db\Adapter\Adapter',
        ),

        'factories' => array(
            'dherrorlogging_zend_db_adapter' => function ($sm){

This solves my problem.

'aliases' => array(
            'dherrorlogging_zend_db_adapter' => 'dherrorlogging_zend_db_adapter_factory',
        ),

        'factories' => array(
            'dherrorlogging_zend_db_adapter_factory' => function ($sm){

Hope this helps someone else.

@DavidHavl
Copy link
Owner

:), no worries, it happens to best of us.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants