PDF.JS not working on 3.1.1-4

Hi @Oberdan,

Can you describe the current (logging) modifications to the PDF.js plugin?

Regards,
Alec Smecher
Public Knowledge Project Team

Sure. My PdfJsViewerPlugin.inc.php have the following changes:

        function register($category, $path, $mainContextId = null) {
                if (parent::register($category, $path, $mainContextId)) {
                        if ($this->getEnabled($mainContextId)) {
                                error_log('TEST - PDF.JS is enabled');
                                HookRegistry::register('ArticleHandler::view::galley', array($this, 'articleCallback'));
                                error_log('TEST - PDF.JS articleCallback set');
                                HookRegistry::register('IssueHandler::view::galley', array($this, 'issueCallback'));
                                AppLocale::requireComponents(LOCALE_COMPONENT_APP_COMMON);
                                $this->_registerTemplateResource();
                        }
                        return true;
                }
                return false;
        }

and

        function articleCallback($hookName, $args) {
                $request =& $args[0];
                $issue =& $args[1];
                $galley =& $args[2];
                $article =& $args[3];

                error_log('TEST - PDF.JS articleCallback was called');

                $templateMgr = TemplateManager::getManager($request);

Regards,

Oberdan

Hi @Oberdan,

Hmm, very strange. So my read is that the PDF.js plugin is enabled and successfully registers for the necessary hooks, and that the hooks are called, but somehow the hook registry isn’t invoking the PDF.js plugin’s callback function.

I think the next thing to investigate is going to be the HookRegistry (lib/pkp/classes/plugins/HookRegistry.inc.php). I’d suggest adding some error_log calls to the call function there, inside a conditional on $hookName to decrease the amount of noise from other hooks, that will dump out the hook registrants as they’re called. (You can dump objects to the error log by calling e.g.:

error_log(print_r($myObject,true));

Regards,
Alec Smecher
Public Knowledge Project Team

Sorry, I’m not very good with PHP… Tried this and it shows nothing inside error_log.

        static function call($hookName, $args = null) {
                // Called only by Unit Test
                // The implementation is a bit quirky as this has to work when
                // executed statically.
                if (self::rememberCalledHooks(true)) {
                        // Remember the called hooks for testing.
                        $calledHooks =& HookRegistry::getCalledHooks();
                        $calledHooks[] = array(
                                $hookName, $args
                        );
                }

                $hooks =& HookRegistry::getHooks();

                if( $hookName == 'articleCallback' ){
                    error_log(print_r($hooks,true));
                };

                if (!isset($hooks[$hookName])) {
                        return false;
                }

                if (isset($hooks[$hookName])) {
                        ksort($hooks[$hookName], SORT_NUMERIC);
                        foreach ($hooks[$hookName] as $priority => $hookList) {
                                foreach ($hookList as $hook) {
                                        if( $hookName == 'articleCallback' ){
                                           error_log(print_r($hook,true));
                                        };
                                        if ($result = call_user_func($hook, $hookName, $args)) return true;
                                }
                        }
                }

                return false;
        }

Regards,

Oberdan

Hi @Oberdan,

Try ArticleHandler::view::galley instead of articleCallback in…

if( $hookName == 'articleCallback' ){
    error_log(print_r($hooks,true));
};

Regards,
Alec Smecher
Public Knowledge Project Team

Hi @asmecher,

Here is the result:

[Wed Oct 31 16:07:31.623739 2018] [:error] [pid 7795] [client 200.145.92.39:62386] Array
(
    [Installer::postInstall] => Array
        (
            [256] => Array
                (
                    [0] => Array
                        (
                            [0] => UsageStatsPlugin Object
                                (
                                    [_currentUsageEvent] => 
                                    [_dataPrivacyOn] => 
                                    [_optedOut] => 
                                    [_saltpath] => 
                                    [pluginPath] => plugins/generic/usageStats
                                    [pluginCategory] => generic
                                    [request] => 
                                )

                            [1] => updateSchema
                        )

                    [1] => Array
                        (
                            [0] => UsageStatsPlugin Object
                                (
                                    [_currentUsageEvent] => 
                                    [_dataPrivacyOn] => 
                                    [_optedOut] => 
                                    [_saltpath] => 
                                    [pluginPath] => plugins/generic/usageStats
                                    [pluginCategory] => generic
                                    [request] => 
                                )

                            [1] => installSiteSettings
                        )

                    [2] => Array
                        (
                            [0] => UsageStatsPlugin Object
                                (
                                    [_currentUsageEvent] => 
                                    [_dataPrivacyOn] => 
                                    [_optedOut] => 
                                    [_saltpath] => 
                                    [pluginPath] => plugins/generic/usageStats
                                    [pluginCategory] => generic
                                    [request] => 
                                )

                            [1] => installFilters
                        )

                    [3] => Array
                        (
                            [0] => UsageStatsReportPlugin Object
                                (
                                    [pluginPath] => plugins/generic/usageStats
                                    [pluginCategory] => reports
                                    [request] => 
                                )

                            [1] => installFilters
                        )

                    [4] => Array
                        (
                            [0] => DefaultThemePlugin Object
                                (
                                    [styles] => Array
                                        (
                                            [stylesheet] => Array
                                                (
                                                    [style] => /ojs_temp/rc-3.1.1/plugins/themes/default/styles/index.less
                                                )

                                            [fontNotoSans] => Array
                                                (
                                                    [baseUrl] => 
                                                    [style] => //fonts.googleapis.com/css?family=Noto+Sans:400,400italic,700,700italic
                                                )

                                            [fontAwesome] => Array
                                                (
                                                    [baseUrl] => 
                                                    [style] => https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.css
                                                )

                                        )

                                    [scripts] => Array
                                        (
                                            [jQuery] => Array
                                                (
                                                    [baseUrl] => 
                                                    [script] => //ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.js
                                                )

                                            [jQueryUI] => Array
                                                (
                                                    [baseUrl] => 
                                                    [script] => //ajax.googleapis.com/ajax/libs/jqueryui/1.11.0/jquery-ui.js
                                                )

                                            [jQueryTagIt] => Array
                                                (
                                                    [baseUrl] => 
                                                    [script] => http://ojs-teste.biblioteca.unesp.br/lib/pkp/js/lib/jquery/plugins/jquery.tag-it.js
                                                )

                                            [popper] => Array
                                                (
                                                    [script] => http://ojs-teste.biblioteca.unesp.br/plugins/themes/default/js/lib/popper/popper.js
                                                )

                                            [bsUtil] => Array
                                                (
                                                    [script] => http://ojs-teste.biblioteca.unesp.br/plugins/themes/default/js/lib/bootstrap/util.js
                                                )

                                            [bsDropdown] => Array
                                                (
                                                    [script] => http://ojs-teste.biblioteca.unesp.br/plugins/themes/default/js/lib/bootstrap/dropdown.js
                                                )

                                            [default] => Array
                                                (
                                                    [script] => http://ojs-teste.biblioteca.unesp.br/plugins/themes/default/js/main.js
                                                )

                                        )

                                    [options] => Array
                                        (
                                            [typography] => Array
                                                (
                                                    [type] => radio
                                                    [label] => plugins.themes.default.option.typography.label
                                                    [description] => plugins.themes.default.option.typography.description
                                                    [options] => Array
                                                        (
                                                            [notoSans] => plugins.themes.default.option.typography.notoSans
                                                            [notoSerif] => plugins.themes.default.option.typography.notoSerif
                                                            [notoSerif_notoSans] => plugins.themes.default.option.typography.notoSerif_notoSans
                                                            [notoSans_notoSerif] => plugins.themes.default.option.typography.notoSans_notoSerif
                                                            [lato] => plugins.themes.default.option.typography.lato
                                                            [lora] => plugins.themes.default.option.typography.lora
                                                            [lora_openSans] => plugins.themes.default.option.typography.lora_openSans

Regards,

Oberdan

Hi @Oberdan,

I think that got cut off…

Regards,
Alec Smecher
Public Knowledge Project Team

Hi @asmecher,

Yeah, seems cut off, but is not complete in my error_log either. You can look a the file here:

http://portal.biblioteca.unesp.br/ojs_teste_error.log

Is there any parameter I can set so this does not happen?

Regards,

Oberdan

Hi @Oberdan,

There’s probably a length limit, either in error_log or in the syslog (or equivalent) mechanism it relies on. I’d suggest doing something like

file_put_contents('/tmp/dump.txt', print_r($hooks, true));

…to write the variable’s contents to a flat file instead of using the error log.

Regards,
Alec Smecher
Public Knowledge Project Team

Hi @asmecher,

Now it seems complete, but the file is quite large (38 MB). You can see it here:

https://portal.biblioteca.unesp.br/dump.txt

Regards,

Oberdan

Hi @Oberdan,

Hmm, I don’t see any registrants at all for ArticleHandler::view::galley in the list.

Regards,
Alec Smecher
Public Knowledge Project Team