eZ Community » Forums » Developer » Override kernel classes
expandshrink

Override kernel classes

Override kernel classes

Friday 11 December 2009 9:29:49 am - 20 replies

Hi all -

I am trying to override the class eZContentOperationCollection.

I have added this line in ezp_override.php:

'eZContentOperationCollection' => 'extension/myext/kernel/content/ezcontentoperationcollection.php',

But It won't override the kernel file. When I try to generate the autoload-array I get an error message: already defined and not added to the autoload array..

What am I doing wrong? I hope someone can help me soon as this is kind of urgent =/

Frank

Friday 11 December 2009 10:04:18 am

Hi Frank,

usually the method is the following :

  1. Create your kernel-override class in your extension, the class name obviously matching one of the kernel's
  2. Run the following script from the eZ Publish root :
    php bin/php/ezpgenerateautoloads.php -o
  3. Then run the "normal" autoload generation (same line as above, without he "-o" option).

No direct edition of the autolad files.

Have you tried this already ?
Let us know,

Nicolas

Friday 11 December 2009 11:56:54 am

for versions 4.1 and 4.2 you also have to set this in the /config.php file:

/*
KERNEL OVERRIDES
----------------
This setting controls if eZ Publish's autoload system should allow, and
load classes, which override kernel classes from extensions.
*/
define( 'EZP_AUTOLOAD_ALLOW_KERNEL_OVERRIDE', true );

I think before that it was an undocumented "feature".

Friday 11 December 2009 11:58:11 am

Hi Nicolas and thank you for your quick reply!

I do not have shell access, but the server owner ran the commands for me - this is the output:

Still not working sad.gif Emoticon

- - - - - -

php bin/php/ezpgenerateautoloads.php -o

Scanning for PHP-files.

Scan complete. Found 176 PHP files.

Searching for classes (tokenizing).

Class eZUserShopAccountHandler in file extension/myext/kernel/classes/shopaccounthandlers/ezusershopaccounthandler.php will override:
kernel/classes/shopaccounthandlers/ezusershopaccounthandler.php (autoload/ezp_kernel.php)

Class eZContentOperationCollection in file extension/myext/kernel/content/ezcontentoperationcollection.php will override:
kernel/content/ezcontentoperationcollection.php (autoload/ezp_kernel.php)
Found 37 classes, added 2 of them to the autoload array.

php bin/php/ezpgenerateautoloads.php

Scanning for PHP-files.

Scan complete. Found 176 PHP files.

Searching for classes (tokenizing).

Warning:
Class eZUserShopAccountHandler in file extension/myext/kernel/classes/shopaccounthandlers/ezusershopaccounthandler.php is already defined in:
kernel/classes/shopaccounthandlers/ezusershopaccounthandler.php (autoload/ezp_kernel.php)

This class was not added to the autoload array.
Warning:
Class eZContentOperationCollection in file extension/myext/kernel/content/ezcontentoperationcollection.php is already defined in:
kernel/content/ezcontentoperationcollection.php (autoload/ezp_kernel.php)
This class was not added to the autoload array.

Found 37 classes, added 35 of them to the autoload array.

PHP Warning: chmod(): Operation not permitted in /home/sites/XXX.no/www/kernel/private/classes/ezautoloadgenerator.php on line 253

Modified on Friday 11 December 2009 12:00:23 pm by Frank Reiersen

Friday 11 December 2009 12:09:19 pm

Hi Steven

Thank you for your reply as well.

- I have already defined EZP_AUTOLOAD_ALLOW_KERNEL_OVERRIDE in config.php happy.gif Emoticon

Saturday 12 December 2009 12:32:31 pm

Just a note: there are still a few places in eZP (esp. ez-approved extensions) where include_once and require_once are present, hardcoded to the php classes in the standard directories. You should take care about that when overriding the provided php classes...

Monday 14 December 2009 1:20:44 pm

PHP Warning: chmod(): Operation not permitted in /home/sites/XXX.no/www/kernel/private/classes/ezautoloadgenerator.php on line 253

Hi Frank,

The quote above tells us the autoload file can not be written. You need to run the same command as a sufficiently privileged user. This can be something like this :

sudo php bin/php/ezpgenerateautoloads.php -o

Let us know how it goes,

Modified on Tuesday 22 December 2009 9:44:46 am by Nicolas Pastorino

Monday 21 December 2009 12:17:00 pm

Kernel override capability is great but there are 2 issues though :

  1. Does not work with datatypes (sometimes really annoying)
  2. When setting EZP_AUTOLOAD_ALLOW_KERNEL_OVERRIDE in config.php, it does a require_once() statement of var/autoload/ezp_override.php without testing if it exists. So you can have a PHP Fatal Error if you just plan to make a kernel override...

Tuesday 22 December 2009 10:26:47 am

Kernel override capability is great but there are 2 issues though :

  1. Does not work with datatypes (sometimes really annoying)
  2. When setting EZP_AUTOLOAD_ALLOW_KERNEL_OVERRIDE in config.php, it does a require_once() statement of var/autoload/ezp_override.php without testing if it exists. So you can have a PHP Fatal Error if you just plan to make a kernel override...

I can only agree with this, and can not find any bug report for this. It seems like you'd need to author a few ones blunk.gif Emoticon

Cheers Jérôme!

Tuesday 22 December 2009 11:36:31 am

Done !

http://issues.ez.no/IssueView.php?Id=15982
http://issues.ez.no/IssueView.php?Id=15983 (with patch)

Modified on Tuesday 22 December 2009 11:37:17 am by Jérôme Vieilledent

Tuesday 22 December 2009 12:23:05 pm

http://issues.ez.no/IssueView.php?Id=15983 (with patch)

I can see a teasing comment on this one... (in the issue tracker directly), from a certain Bertrand Dunogier...you may want to have a look at it big-smile.gif Emoticon

Brilliant otherwise !

Tuesday 22 December 2009 6:48:35 pm

http://issues.ez.no/IssueView.php?Id=15983 (with patch)

And ... fixed!
Thanks Jerome for reporting, and Bertrand for fixing happy.gif Emoticon

Friday 30 April 2010 11:07:16 am

I'm trying to override kernel files which are not classes, like

kernel/collaboration/item.php

Any hints how to do that?

Kind regards,
Walter

Friday 30 April 2010 12:02:39 pm

Hi Walter

Unfortunately overriding modules is not currently possible sad.gif Emoticon

Friday 30 April 2010 12:41:52 pm

Maybe it is possible to override standard views using wildcard rewrites?

Friday 30 April 2010 1:07:09 pm

Hi,

A little trick to Override a module in ez, (this is not very clean but it can be useful when you can not do this otherwise)

In the file module.ini, define:

[ModuleSettings]
# Important to initialize the variable
ModuleRepositories []
ModuleRepositories [] =extension / [costum_extension] / modules
ModuleRepositories [] =kernel
ModuleRepositories []=kernel / private / modules

PS: But we must override all of the views's module.

I hope it will be useful for someoneblunk.gif Emoticon

Modified on Friday 30 April 2010 1:08:41 pm by Abdelkader RHOUATI

Friday 30 April 2010 3:13:22 pm

Maybe it is possible to override standard views using wildcard rewrites?

Mmm... Good catch ! It would be VERY nice happy.gif Emoticon

@Abdelkader : Interesting, but pretty impacting isn't it ?

Friday 30 April 2010 7:41:24 pm

@Jérôme, yes, every day we discovered new things about EZ happy.gif Emoticon

In fact we can do the same thing to override the datatype. On a project, I overloaded single relation object datatype in order to redirect the link browse to the destination defined in the class. and it work well.

to do it, edit file content.ini, and set the parameter :

[DataTypeSettings]
RepositoryDirectories []
RepositoryDirectories []=extension/[Costum Extension]/datatypes
RepositoryDirectories []=kernel/classes/datatypes

Regrads

Tks

Modified on Friday 30 April 2010 7:46:25 pm by Abdelkader RHOUATI

Thursday 09 September 2010 10:47:18 am

Hi all,

Thanks so much for this thread ! And to Abdelkader for his solution happy.gif Emoticon

Tuesday 25 January 2011 11:52:08 am

To override the default shop user handler (kernel/classes/shopaccounthandlers/ezusershopaccounthandler.php) you need to create settings/override/shopaccount.ini.append.php:

 <?php /* #?ini charset="utf-8"?

[HandlerSettings]
Repositories[]
Repositories[]=extension/your_extension/classes
Repositories[]=kernel/classes

*/ ?>

Then take a copy of kernel/classes/shopaccounthandlers/ezusershopaccounthandler.php to extension/your_extension/classes/shopaccounthandlers/ezusershopaccounthandler.php

Then run kernel override autorun. Easiest way to verify that it is working is just to echo something in the beginning of your custom ezusershopaccounthandler.php

Friday 03 June 2011 9:03:40 am

Does anyone know how to stop the "normal" autoload generation (without the "-o" option) from showing those warning messages?

expandshrink

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

36 542 Users on board!

Forums menu

Proudly Developed with from