Forums / Extensions / Problem creating extension fetch functions

Problem creating extension fetch functions

Author Message

Arno Lehmann

Sunday 09 March 2008 3:23:57 am

Hi,

I'm running eZ Publish 4.0.0 and need to write an extension for our site.

What I've got so far is taken mostly from the manual, the online articles, and lots of code reading and debugging (to better understabnd what happens behind the scenes).

I can create design, templates, translations and template operators ok. Where I'm stuck is setting up a new fetch function (which is right now the core of my current work).

Ok, what did I do:

Created an extension, with module directory, a directory for my module, and thus I've got this now in extension/xxldapusers/modules/xxpartners:

[arno@xx xxpartners]$ ls
function_definition.php ldap.php

<?php
# the following include fixes a possible bug:
# the named include_file is apparently never included
# A.L.

include('extension/xxldapusers/modules/xxpartners/ldap.php');

$FunctionList=array();
$FunctionList['partners'] = array( 'name' => 'partners',
                                   'operation_types' => array( 'read' ),
                                   'call_method' => array( 'include_file' => 'extension/xxldapusers/modules/xxpartners/ldap.php'
,
                                                           'class' => 'xxldapfetch',
                                                           'method' => 'FetchPartners' ),
                                   'parameter_type' => 'standard',
                                   'parameters' => array( array( 'name' => 'country',
                                                                 'type' => 'string',
                                                                 'required' => false ) )
                                 );

?>

This file, as shown above, works <b>once</b> after clearing the cache.

The next run, I get a fatal error with this information in the apache's error log:

[Sun Mar 09 09:48:48 2008] [error] [client 91.96.some.ip] PHP Fatal error:  Class xxldapfetch' not found in /var/www/ez/var/ezwebin_site/cache/template/compiled/xx_partnerlist-9840f7bd50f98f56b322336088b46bd9.php on line 404, referer: http://ez.xx.com/eng/Partners/Find-a-xx-Partner/Partners-list

I understand that, for some reason, the file with the actual function definition is not really included in the cached version.

If I leave out the include from the function_definition.php, I get an error stating that the class for the defined function call could not be found.

The latter is not really astonishing after I looked into the source of lib/ezutils/classes/ezmodulefunctioninfo.php as there, only the function_definition.php file is included, but the referenced include_file is never read.

What I conclude:
- function_definition.php is not working as expected; the named include_file is not included at all. I found the instructions at http://ez.no/de/layout/set/printarticle/developer/articles/an_introduction_to_developing_ez_publish_extensions (German), by the way. The same construct is found in kernel/layout/function_definition.php so I expect it to be supported, by the way.
- including other php files is not easily done as caching seems not to handle file inclusions.

How do I others handle these problems?

Thanks,

Arno

Heath

Sunday 09 March 2008 11:07:28 am

Hello,

Are you certain that you have correctly reloaded your extension autoload cache.

While not auditing your code or message in exacting detail. The error message and description you have shared is strikingly familiar to us. I've seen it before when a template operator was not enabled properly for an individual siteaccess of a site.

This is different than standard cache and is often most accurately accomplished from the commandline.

I recently used this command to re-generate extension autoload cache.

Which I have found to be more effective than the admin gui for this feature as the admin tool is restricted per siteaccess and all available autoload information is not process the same as with the following shell command (It's ... complicated)

<b>Commands</b>

<i>bin/php/ezpgenerateautoloads.php -v -e
bin/php/ezcache.php --clear-all</i>

Cheers,
Heath

Brookins Consulting | http://brookinsconsulting.com/
Certified | http://auth.ez.no/certification/verify/380350
Solutions | http://projects.ez.no/users/community/brookins_consulting
eZpedia community documentation project | http://ezpedia.org

Arno Lehmann

Sunday 09 March 2008 2:41:45 pm

Hi,

as it is, I'm certain I haven't done anything useful to the autoloader cache. I found no instructions to do so :-)

Unfortunately, running sudo -u root bin/php/ezpgenerateautoloads.php -v -e doesn't help here as it only results in

PHP Warning:  require(Base/src/base.php): failed to open stream: No such file or directory in /var/www/ez/bin/php/ezpgenerateautoloads.php on line 35
PHP Fatal error:  require(): Failed opening required 'Base/src/base.php' (include_path='.:/usr/share/pear') in /var/www/ez/bin/php/ezpgenerateautoloads.php on line 35

the ezPublish installation has exactly no path containing Base, so either this installation is severely broken or the ezpgenerateautoloads.php script needs some help.

Interestingly, when I try to regenerate the autoloader cache from the web fron-end, I get a ez Publish error again, and in the apache's error log, I see

[Sun Mar 09 21:38:04 2008] [error] [client 89.166.some.ip] PHP Fatal error:  Class 'ezcFile' not found in /var/www/ez/lib/ezutils/classes/ezautoloadgenerator.php on line 283, referer: http://ez.xx.com/ezwebin_site_admin/setup/extensions

To me, this looks like part of eZ Components is missing. I wonder how this could happen?

Arno

Heath

Sunday 09 March 2008 2:56:54 pm

Yes. My advice is accurate, thank you for providing aditional confirmation details.

You must first install eZ Components which is required with eZ Publish 4.0

http://ezcomponents.org/docs/install

eZ Components is especially required when you begin trying to enable / activate / autoload extensions beyond the default base installation.

eZ is quite smart in allowing eZ Publish 4.0 to work out of the box, leaving this aspect to the more brave users who customize to ensure they have properly provided for all the softwares requirements.

Cheers,
Heath

Brookins Consulting | http://brookinsconsulting.com/
Certified | http://auth.ez.no/certification/verify/380350
Solutions | http://projects.ez.no/users/community/brookins_consulting
eZpedia community documentation project | http://ezpedia.org

Arno Lehmann

Sunday 09 March 2008 3:15:54 pm

Hm... thanks for the help so far.

Now I wonder - does anyone have experiences to share regarding installation of eZ Components besides an existing eZ Publish setup?

From looking into the tarball and comparing with the error message and code from bin/php/ezpgenerateautoloads.php, I should need eZ Components in the ezc directory below the eZ Publish base directory. Does that sound correct?

Arno

Heath

Sunday 09 March 2008 3:59:50 pm

You should consider switching your focus from eZ Publish for a solid moment and instead turning to reading the documentation link provided with detailed installation instructions.

Currently the installation of eZ Components is entirely separate from eZ Publish.

For a user such as yourself I would strongly recommend you use the 'pear' installation method. It is by far the simplest to use to complete the installation.

http://ezcomponents.org/docs/install#pear-installer

Once you install the eZ Components (pear packages) you will need to ensure that these are included within your php installation or apache virtual host's php include_path.

http://ezcomponents.org/docs/install#include-path

Often this is the default within a php installation meaning you only need to install the packages, clear eZ Publish Cache and Autoload Cache.

Cheers,
Heath

Brookins Consulting | http://brookinsconsulting.com/
Certified | http://auth.ez.no/certification/verify/380350
Solutions | http://projects.ez.no/users/community/brookins_consulting
eZpedia community documentation project | http://ezpedia.org

Arno Lehmann

Monday 10 March 2008 2:40:28 am

Hello,

thanks for your advice - actually, I know about the possible ways to install eZ Components, but I am a bit reluctant to install a server-wide php thingie as I'm not sure how this might interfere with other applications running on that machine.

So I really only was interested in learning about experience with having eZ Components installed in an eZ Publish environment, and not site-wide.

I guess I'll dig through the system for a while and find if any other php applications might stumble over the pear-installed eZ Components library...

Anyway, what I'm wondering is that, to use locally created extensions, I need eZ Components. While this seems logical, I hadn't found this in the manuals or in the tutorials I read. The jacextension tutorial, for example, does not mention that eZ Components are needed. Well, the fact that documentation is hardly ever complete is nothing new to me ;-)

Arno

Felix Laate

Monday 10 March 2008 6:58:20 am

Hi there,

obviously you'll only need the components for extensions that depend on them as such. Allmost all existing contributed extensions don't.

The reason is off course that the components are PHP5 and eZ Publish only recently became compatible with that.

That being said, the components are a great basis for creating great extensions.

Felix

Publlic Relations Manager
Greater Stavanger
www.greaterstavanger.com

Arno Lehmann

Monday 10 March 2008 1:23:40 pm

Hi,

ok, this is fixed.

I followed Heath's advice of installing eZ Components to be able to run the ezpgenerateautoloads.php which, after eZ Components was installed, ran ok and updated the autoload/ezp_extension.php file correctly.

Afterwards, my own module was running correctly, without the need to include its worker file(s).

I could have updated that file manually, as it's fairly simple structured.

What I wonder about is - still - why this step is not mentioned in the tutorials I read, but I know from experience that it's no easy task writing complete and yet readable documentation for complex stuff.

So let me state that my own extension does not need eZ Components (yet), but that having eZ Components installed makes maintaining an extended eZ Publish installation simpler.

Thanks for your help!