Hi Everyone,
I am using OJS 3.1.2 and have inherited code from a previous developer for a custom plugin that was made for OJS 3.1.1.4. I have been having a hard time figuring out how to trigger the function (handleRequest) from hook (LoadHandler) in the following code.
I’ve done some logging and from the logs it looks like the handleRequest function is never called and just skipped over. I don’t know what’s wrong. When I disable and enable the plugin I get the following in my log file. You’ll notice that nothing inside handleRequest is logged. Everything in the register function is logged just not inside the subroutines.
2019-09-09 10:18:18 function register :: start
2019-09-09 10:18:18 function register :: register plugin enabled
2019-09-09 10:18:18 function register :: completed handleRequest function call
2019-09-09 10:18:18 function register :: completed handleSubscriptionRequired function call
2019-09-09 10:18:18 function register :: completed handleTemplateDisplay function call
I know this one might be a bit sticky to debug because it’s custom, but if you have any suggestions of what I can try or approach, it would be much appreciated. I think I’ve reached a blocker in terms of development for this.
Thank you,
Rachel
import('lib.pkp.classes.plugins.GenericPlugin');
class IterOJSAccessPlugin extends GenericPlugin {
private $iter_environment = 'www-dev';
private $journalCodesInterested = array(
'renref' => 8,
'emw' => 20,
'qua' => 10,
'confrat' => 15,
'eth' => 6,
'reed' => 7,
'aestimatio' => 9,
'interpretatioa' => 122,
'iterbetatest' => 10000
);
function register($category, $path) {
$success = parent::register($category, $path);
// date timestamp for error log
$date = date_create();
$date = date_format($date, 'Y-m-d H:i:s');
error_log(print_r($date, true)." function register :: start \r\n", 3, '/var/www/html/toronto/plugins/themes/test_log');
if ($success && $this->getEnabled()) {
error_log(print_r($date, true)." function register :: register plugin enabled \r\n", 3, '/var/www/html/toronto/plugins/themes/test_log');
HookRegistry::register ('LoadHandler', array(&$this, 'handleRequest'));
error_log(print_r($date, true)." function register :: completed handleRequest function call \r\n", 3, '/var/www/html/toronto/plugins/themes/test_log');
HookRegistry::register ('IssueAction::subscriptionRequired', array(&$this, 'handleSubscriptionRequired'));
error_log(print_r($date, true)." function register :: completed handleSubscriptionRequired function call \r\n", 3, '/var/www/html/toronto/plugins/themes/test_log');
HookRegistry::register ('TemplateManager::display', array(&$this, 'handleTemplateDisplay'));
error_log(print_r($date, true)." function register :: completed handleTemplateDisplay function call \r\n", 3, '/var/www/html/toronto/plugins/themes/test_log');
}
return $success;
}
function getName() {
return 'IterOJSAccess';
}
function getDisplayName() {
return 'Iter OJS Access';
}
function getDescription() {
return 'Iter OJS Access plugin controls journal access according to Iter user database';
}
function isSitePlugin() {
return FALSE;
}
//Nothing inside handleRequest gets logged at all
function handleRequest($hookName, $args) {
//header('Location: http://library.utoronto.ca');
$date = date_create();
$date = date_format($date, 'Y-m-d H:i:s');
error_log(print_r($date, true)." function handleRequest :: start \r\n", 3, '/var/www/html/toronto/plugins/themes/test_log');
$page =& $args[0];
$op =& $args[1];
$sourceFile =& $args[2];
error_log(print_r($date, true)." function handleRequest :: Page parameter value ".print_r($page)." \r\n", 3, '/var/www/html/toronto/plugins/themes/test_log');
error_log(print_r($date, true)." function handleRequest :: Op parameter value ".print_r($op)." \r\n", 3, '/var/www/html/toronto/plugins/themes/test_log');
error_log(print_r($date, true)." function handleRequest :: Source File parameter value ".print_r($sourceFile )."\r\n", 3, '/var/www/html/toronto/plugins/themes/test_log');
if ($page == 'article') { // only interested in article views or downloads
error_log(print_r($date, true)." function handleRequest :: if page is an article \r\n", 3, '/var/www/html/toronto/plugins/themes/test_log');
if ($op == 'view' || $op == 'download') { // we do not care $op == 'viewFile' as it's called within view page to embed PDF
error_log(print_r($date, true)." function handleRequest :: If View or Download \r\n", 3, '/var/www/html/toronto/plugins/themes/test_log');
$matches = array();
error_log(print_r($date, true)." function handleRequest :: Matches Array Value ".print_r($matches)." \r\n", 3, '/var/www/html/toronto/plugins/themes/test_log');
if (preg_match('/\w*\/(view|download)\/[0-9]+\/[0-9]+/i', Request::getRequestPath(), $matches) === 1) {
$journal = Request::getJournal();
error_log(print_r($date, true)." function handleRequest :: Journal ".print_r($journal)." \r\n", 3, '/var/www/html/toronto/plugins/themes/test_log');
$journal_abbrev = $journal->_data['path'];
error_log(print_r($date, true)." function handleRequest :: Journal Abbrev ".print_r($journal_abbrev)." \r\n", 3, '/var/www/html/toronto/plugins/themes/test_log');
$user_ip = $_SERVER['REMOTE_ADDR'];
error_log(print_r($date, true)." function handleRequest :: User Ip ".print_r($user_ip)." \r\n", 3, '/var/www/html/toronto/plugins/themes/test_log');
$iterResourceId = isset($this->journalCodesInterested[$journal_abbrev]) ? $this->journalCodesInterested[$journal_abbrev]:0;
error_log(print_r($date, true)." function handleRequest :: ITER Resource ID ".print_r($iterResourceId)." \r\n", 3, '/var/www/html/toronto/plugins/themes/test_log');
$this->isIterSubscriber($user_ip, $iterResourceId, FALSE);
error_log(print_r($date, true)." function handleRequest :: Current Object ".print_r($this)." \r\n", 3, '/var/www/html/toronto/plugins/themes/test_log');
}
}
}
return FALSE;
}