Forums / Developer / Override kernel classes

Override kernel classes

Author Message

Frank Reiersen

Friday 11 December 2009 12:29:49 am

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

Nicolas Pastorino

Friday 11 December 2009 1: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

--
Nicolas Pastorino
Director Community - eZ
Member of the Community Project Board

eZ Publish Community on twitter: http://twitter.com/ezcommunity

t : http://twitter.com/jeanvoye
G+ : http://plus.tl/jeanvoye

Steven E. Bailey

Friday 11 December 2009 2: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".

Certified eZPublish developer
http://ez.no/certification/verify/396111

Available for ezpublish troubleshooting, hosting and custom extension development: http://www.leidentech.com

Frank Reiersen

Friday 11 December 2009 2: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 :-(

- - - - - -

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

Frank Reiersen

Friday 11 December 2009 3:09:19 am

Hi Steven

Thank you for your reply as well.

- I have already defined EZP_AUTOLOAD_ALLOW_KERNEL_OVERRIDE in config.php :)

Gaetano Giunta

Saturday 12 December 2009 3:32:31 am

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...

Principal Consultant International Business
Member of the Community Project Board

Nicolas Pastorino

Monday 14 December 2009 4:20:44 am

"

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,

--
Nicolas Pastorino
Director Community - eZ
Member of the Community Project Board

eZ Publish Community on twitter: http://twitter.com/ezcommunity

t : http://twitter.com/jeanvoye
G+ : http://plus.tl/jeanvoye

Jérôme Vieilledent

Monday 21 December 2009 3:17:00 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...

Nicolas Pastorino

Tuesday 22 December 2009 1: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 ;)

Cheers Jérôme!

--
Nicolas Pastorino
Director Community - eZ
Member of the Community Project Board

eZ Publish Community on twitter: http://twitter.com/ezcommunity

t : http://twitter.com/jeanvoye
G+ : http://plus.tl/jeanvoye

Jérôme Vieilledent

Tuesday 22 December 2009 2:36:31 am

Done !

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

Nicolas Pastorino

Tuesday 22 December 2009 3:23:05 am

"

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 :D

Brilliant otherwise !

--
Nicolas Pastorino
Director Community - eZ
Member of the Community Project Board

eZ Publish Community on twitter: http://twitter.com/ezcommunity

t : http://twitter.com/jeanvoye
G+ : http://plus.tl/jeanvoye

Nicolas Pastorino

Tuesday 22 December 2009 9:48:35 am

"

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

"

And ... fixed!
Thanks Jerome for reporting, and Bertrand for fixing :)

--
Nicolas Pastorino
Director Community - eZ
Member of the Community Project Board

eZ Publish Community on twitter: http://twitter.com/ezcommunity

t : http://twitter.com/jeanvoye
G+ : http://plus.tl/jeanvoye

Walter Rafelsberger

Friday 30 April 2010 2: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

Jérôme Vieilledent

Friday 30 April 2010 3:02:39 am

Hi Walter

Unfortunately overriding modules is not currently possible :(

Gaetano Giunta

Friday 30 April 2010 3:41:52 am

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

Principal Consultant International Business
Member of the Community Project Board

Abdelkader RHOUATI

Friday 30 April 2010 4:07:09 am

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 someone;)

Abdelkader RHOUATI

Blog (french) : http://arhouati.com
----
Extension arh_jdebug : EzDebug using jquery

Jérôme Vieilledent

Friday 30 April 2010 6:13:22 am

"

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

"

Mmm... Good catch ! It would be VERY nice :)

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

Abdelkader RHOUATI

Friday 30 April 2010 10:41:24 am

@Jérôme, yes, every day we discovered new things about EZ :)

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

Abdelkader RHOUATI

Blog (french) : http://arhouati.com
----
Extension arh_jdebug : EzDebug using jquery

Vincent Tabary

Thursday 09 September 2010 1:47:18 am

Hi all,

Thanks so much for this thread ! And to Abdelkader for his solution :)

Vinz
http://vincent.tabary.me

Jani Tarvainen

Tuesday 25 January 2011 2: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

--
http://ezpublish.fi/