OJS OCS OMP OHS

You are viewing the PKP Support Forum | PKP Home Wiki



How can a plugin get instantiated as a handler?

Are you responsible for making OJS work -- installing, upgrading, migrating or troubleshooting? Do you think you've found a bug? Post in this forum.

Moderators: jmacgreg, btbell, michael, bdgregg, barbarah, asmecher

Forum rules
What to do if you have a technical problem with OJS:

1. Search the forum. You can do this from the Advanced Search Page or from our Google Custom Search, which will search the entire PKP site. If you are encountering an error, we especially recommend searching the forum for said error.

2. Check the FAQ to see if your question or error has already been resolved.

3. Post a question, but please, only after trying the above two solutions. If it's a workflow or usability question you should probably post to the OJS Editorial Support and Discussion subforum; if you have a development question, try the OJS Development subforum.

How can a plugin get instantiated as a handler?

Postby springday » Sun Oct 21, 2012 8:52 am

Dear PKP team,

in my error log I found this message:

[18-Oct-2012 11:12:22] PHP Fatal error: Call to undefined method PayPalPlugin::getAuthorizedContextObject() in /html/ojs/lib/pkp/classes/handler/PKPHandler.inc.php on line 430


This line 430 looks like this:
Code: Select all
$templateMgr->assign('userRoles', $this->getAuthorizedContextObject(ASSOC_TYPE_USER_ROLES));


So somewhere a PayPalPlugin has been instantiated as a PKPHandler, while the inheritance line of the PayPalPlugin looks like this:
PayPalPlugin -> PayMethodPlugin -> Plugin -> PKPPlugin

Therefore I don't understand this error. Is a plugin supposed to extend the PKPHandler class and therefore be able to access its methods? Or is it wrong in the first place to treat a PayPalPlugin as a subclass of the PKPHandler? But then where did this slip happen?

Best regards,
Kai Weber
springday
 
Posts: 111
Joined: Wed Jul 25, 2012 2:56 pm
Location: Munich, Germany

Re: How can a plugin get instantiated as a handler?

Postby springday » Mon Jan 20, 2014 1:28 am

Today I found the same error again and had totally forgotten that I had already posted this here more than a year ago. Does anybody have a solution by now?

Best regards,
Kai Weber
springday
 
Posts: 111
Joined: Wed Jul 25, 2012 2:56 pm
Location: Munich, Germany

Re: How can a plugin get instantiated as a handler?

Postby asmecher » Mon Jan 20, 2014 6:15 am

Hi Kai,

Do you have any more of the stack trace than you've posted? I worry it'll be something fairly obscure like a reference error. Do you have any information on e.g. what URL is causing the error? Correlating your access log against your PHP error log might help. In any case, treating the plugin like a handler is wrong and shouldn't be happening.

Regards,
Alec Smecher
Public Knowledge Project Team
asmecher
 
Posts: 9201
Joined: Wed Aug 10, 2005 12:56 pm

Re: How can a plugin get instantiated as a handler?

Postby springday » Tue Feb 11, 2014 5:56 am

Hi Alec,

I've been led off to different things, so I couldn't follow up this problem for a while. I've tried to get some more error output, but have not succeeded yet. I don't have xdebug on the production server and a few var_dump() or error_log() commands inserted in the source code haven't been helpful either. I'll try to simulate the error on the development server and try to trace it with xdebug. I'll keep this forum updated - either with new questions or with a solution.

Best,

Kai
springday
 
Posts: 111
Joined: Wed Jul 25, 2012 2:56 pm
Location: Munich, Germany

Re: How can a plugin get instantiated as a handler?

Postby springday » Tue Feb 11, 2014 8:58 am

I'm running OJS 2.4.2 on a server with PHP 5.3.10. I've checked to make sure that the paypal-cancellation code on my server is identical with the current stable OJS 2.4-code on Github (https://github.com/pkp/ojs/blob/ojs-sta ... in.inc.php, lines 314-327).

I can prevent the described error, if I uncomment line 315, i.e. leave away the call to setupTemplate().

The error log is full with "Non-static method PKPHandler::setupTemplate() should not be called statically, assuming $this from incompatible context" (see below for an excerpt). Could this implicit assumption of $this be the cause of the problem? I was also getting confused by the fact, that the PayPalPlugin operates on a variable $templateMgr as well as the PKPHandler class in its setupTemplate() method. Is the intention behind this that the PayPalPlugin and the PKPHandler "communicate" via this variable? I'm not too familiar with object-oriented encapsulation in PHP, but that seems somehow "fishy" to me...

Here's the beginning of the trace:
Code: Select all
    0.1477   20641744                   -> PKPApplication->errorHandler(2048, 'Non-static method PKPHandler::setupTemplate() should not be called statically, assuming $this from incompatible context', '/var/www/ojs/plugins/paymethod/paypal/PayPalPlugin.inc.php', 363, array ('args' => array (), [...], 'paymentStatus' => NULL)) /var/www/ojs/pages/payment/PaymentHandler.inc.php:363
    0.1484   20641824                     -> error_reporting() /var/www/ojs/lib/pkp/classes/core/PKPApplication.inc.php:387
    0.1484   20639600                   -> PKPHandler->setupTemplate() /var/www/ojs/plugins/paymethod/paypal/PayPalPlugin.inc.php:363
    0.1485   20640680                     -> PKPApplication->errorHandler(2048, 'Non-static method PKPLocale::requireComponents() should not be called statically, assuming $this from incompatible context', '/var/www/ojs/lib/pkp/classes/handler/PKPHandler.inc.php', 421, array ()) /var/www/ojs/plugins/paymethod/paypal/PayPalPlugin.inc.php:421
    0.1485   20640760                       -> error_reporting() /var/www/ojs/lib/pkp/classes/core/PKPApplication.inc.php:387
    0.1485   20639760                     -> PKPLocale->requireComponents(1, 7) /var/www/ojs/lib/pkp/classes/handler/PKPHandler.inc.php:424
    0.1486   20639840                       -> func_get_args() /var/www/ojs/lib/pkp/classes/i18n/PKPLocale.inc.php:157
    0.1486   20640552                       -> count(array (0 => 1, 1 => 7)) /var/www/ojs/lib/pkp/classes/i18n/PKPLocale.inc.php:158
    0.1486   20640632                       -> is_string(7) /var/www/ojs/lib/pkp/classes/i18n/PKPLocale.inc.php:163
    0.1487   20642432                       -> PKPApplication->errorHandler(2048, 'Non-static method AppLocale::getLocale() should not be called statically, assuming $this from incompatible context', '/var/www/ojs/lib/pkp/classes/i18n/PKPLocale.inc.php', 167, array ('params' => array (0 => 1, 1 => 7), 'paramCount' => 2, 'lastParam' => 7)) /var/www/ojs/lib/pkp/classes/handler/PKPHandler.inc.php:167
    0.1487   20642512                         -> error_reporting() /var/www/ojs/lib/pkp/classes/core/PKPApplication.inc.php:387


Best regards,
Kai
springday
 
Posts: 111
Joined: Wed Jul 25, 2012 2:56 pm
Location: Munich, Germany

Re: How can a plugin get instantiated as a handler?

Postby asmecher » Tue Feb 11, 2014 10:03 am

Hi Kai,

I see it now.

First off, we haven't used some of the PHP OO keywords (e.g. "static") because we've had to maintain PHP4 compatibility; PHP4 dies screaming when it encounters some of these.

Recently we moved from static invocation of handler functions to calling functions on instantiations of handler classes. It looks like the PayPal cancel code still tries to use static instantiation, which leads to $this being used in a case where it doesn't exist.

The correct solution will be to remove the static call to Handler::setupTemplate() from PayPalPlugin. OTOH this call is probably used to load locale files; would you mind running a quick test with that line removed and reporting back whether you see e.g. untranslated locale keys?

Regards,
Alec Smecher
Public Knowledge Project Team
asmecher
 
Posts: 9201
Joined: Wed Aug 10, 2005 12:56 pm

Re: How can a plugin get instantiated as a handler?

Postby springday » Tue Feb 11, 2014 1:06 pm

Yes, Alex, your assumption is right: I did see an untranslated locale key on the Paypal-cancel-response page after I commented Handler::setupTemplate() out.

Kai
springday
 
Posts: 111
Joined: Wed Jul 25, 2012 2:56 pm
Location: Munich, Germany

Re: How can a plugin get instantiated as a handler?

Postby asmecher » Tue Feb 11, 2014 1:23 pm

Hi Kai,

OK, now try putting this line in place of Handler::setupTemplate():
Code: Select all
AppLocale::requireComponents(LOCALE_COMPONENT_PKP_COMMON, LOCALE_COMPONENT_PKP_USER);
This should cause the locale keys to be translated.

Regards,
Alec Smecher
Public Knowledge Project Team
asmecher
 
Posts: 9201
Joined: Wed Aug 10, 2005 12:56 pm

Re: How can a plugin get instantiated as a handler?

Postby springday » Wed Feb 12, 2014 12:09 am

Hi Alec,

that nearly solved it, thank you. But I also needed to add the lines

Code: Select all
if (defined('LOCALE_COMPONENT_APPLICATION_COMMON')) {
   AppLocale::requireComponents(LOCALE_COMPONENT_APPLICATION_COMMON);
}


to get all the keys translated.

Best regards,
Kai
springday
 
Posts: 111
Joined: Wed Jul 25, 2012 2:56 pm
Location: Munich, Germany

Re: How can a plugin get instantiated as a handler?

Postby asmecher » Wed Feb 12, 2014 8:59 am

Hi Kai,

Great, thanks! I've filed this and posted a patch (wrapping those lines into one) at http://pkp.sfu.ca/bugzilla/show_bug.cgi?id=8556.

Regards,
Alec Smecher
Public Knowledge Project Team
asmecher
 
Posts: 9201
Joined: Wed Aug 10, 2005 12:56 pm


Return to OJS Technical Support

Who is online

Users browsing this forum: Bing [Bot] and 1 guest