This site has been archived and you can no longer log in or post new messages. For up-to-date community resources please visit ezplatform.com

eZ Community » Forums » Developer » zeta components db handler with ini...
expandshrink

zeta components db handler with ini settings

zeta components db handler with ini settings

Wednesday 30 March 2011 4:58:56 pm - 5 replies

Hi,

I'm willing to use to use the db schema zeta component which seems far more powerful than the ezpublish one but ezpublish db interface is not compatible.

I'm wondering if eZPublish API makes it possible to instantiate a ezcDBHandler using DatabaseSettings defined in site.ini. Has anyone tried that before ?

Wednesday 30 March 2011 7:40:21 pm

Hi Benjamin,

The ezcDBHandler interface and eZDBInterface's are different. Even if you manage to get an ezcDBHandler session instantiated, the methods called will differ, causing Fatal errors. Achieveing this would require more in-depth changes, imho.

In your custom extensions though, to access external tables, you can use Zeta Components for this. I do this very often, and i love it happy.gif Emoticon

Cheers !

Thursday 31 March 2011 9:24:00 am

Hi Nicolas, thanks for your reply.

The thing is I'm developing an upgrade script which is totally unrelated to eZ's execution so I wouldn't mind using a totally different API. My need is more of a ezcDbFactory wrapper loading site.ini's DatabaseSettings block and calling the component's factory but I gather nothing exists at the time.

I guess I'll have to make one. Any pit traps I should beware when it comes to db instantiation ?

Thursday 31 March 2011 10:14:54 am

If you do that, please share the results of your work - I guess many ppl will appreciate it.

About using ezc dbschema: it os not 100% compatible when using oracle (eg. the names of sequences used for autoincrement cols is different, as well as the way it handles quoting of identifiers). Any improvement in that area is of course welcome, too

Thursday 31 March 2011 11:32:33 am

Hi Benjamin, Gaetano,

Here is an initialization stub, easily embeddable in a dedicated method :

public static function initializeEzcPersistentSession()
    {
        if ( !self::$initialized )
        {
            // @FIXME : make this code DBMS-agnostic
            $dbURI = "mysql://";
            $dbURI .= eZINI::instance()->variable( 'DatabaseSettings', 'User' );
            $dbURI .= ':' . eZINI::instance()->variable( 'DatabaseSettings', 'Password' );
            $dbURI .= '@' . eZINI::instance()->variable( 'DatabaseSettings', 'Server' );
            $dbURI .= '/' . eZINI::instance()->variable( 'DatabaseSettings', 'Database' );
 
            ezcDbInstance::set( ezcDbFactory::create( $dbURI ) );
            $session = new ezcPersistentSession( ezcDbInstance::get(),
                                                 new ezcPersistentCacheManager( new ezcPersistentCodeManager( "extension/ezforumtools/classes/po/" ) ) );
            ezcPersistentSessionInstance::set( $session ); // set default session
            self::$initialized = true;
        }
        return ezcPersistentSessionInstance::get();
    }

and here is a usage stub :

$session = eZForumTools::initializeEzcPersistentSession();
$q = $session->createFindQuery( 'eZForumModeratedEntry' );
$q->where( $q->expr->eq( 'contentObjectId', $q->bindValue( $objectId ) ) );
return $session->find( $q, 'eZForumModeratedEntry' );

These are stubs, to be wrapped in lazy initialization ideally,
Hope it helps,
Cheers,

Wednesday 18 May 2011 6:56:34 pm

For those interested I finally made a helper method which works fine for a classic mySQL install.

Gist is available at https://gist.github.com/978982

Feel free to improve it happy.gif Emoticon

expandshrink

You must be logged in to post messages in this topic!

36 542 Users on board!

Forums menu

Proudly Developed with from