Integrating Algolia Search - PHP Errors on Plugin Installation

Overview

We are working on integrating Algolia search into OJS. Ideally, we’d like to do this through a plugin so that it could be shared with others. In a forum post (OJS 3 - advance search - #8 by asmecher) we found a plugin that looks like it will get us most of the way there (GitHub - fostermadeco/ojs-algolia: Plugin integrating OJS and Algolia).

Upon installing it however, we ran into some PHP errors that I’m not sure how to parse. My hope is that:

  • Someone that has experience with plugins may be able to figure out the specific issue.
  • We may eventually get to a place where an official Algolia plugin is possible.

Steps to Reproduce

  1. Download/clone repo: GitHub - fostermadeco/ojs-algolia: Plugin integrating OJS and Algolia
  2. Pack into .tar.gz
  3. Upload through the plugins manager /management/settings/website
  4. UI will become unresponsive, with spinners non-stop. Try accessing Installed Plugins, and you’ll just get spinners. The Plugin Gallery will still work fine. Similar to [OJS 3] Plugins Tab doesn't load but with a more specific cause.
    image
  5. Deleting the plugin folder instantly fixes the issue.

Logs

error.log

[Fri Feb 19 20:17:10.402218 2021] [php7:error] [pid 2378] [client 70.66.230.254:64502] PHP Fatal error:  Uncaught Error: Call to undefined method AlgoliaPlugin::getTemplateResourceName() in /var/www/html/plugins/generic/algolia/AlgoliaPlugin.inc.php:340\nStack trace:\n#0 /var/www/html/lib/pkp/classes/plugins/Plugin.inc.php(367): AlgoliaPlugin->getTemplatePath()\n#1 /var/www/html/lib/pkp/classes/plugins/Plugin.inc.php(118): Plugin->_registerTemplateResource()\n#2 /var/www/html/lib/pkp/classes/plugins/LazyLoadPlugin.inc.php(28): Plugin->register()\n#3 /var/www/html/plugins/generic/algolia/AlgoliaPlugin.inc.php(41): LazyLoadPlugin->register()\n#4 /var/www/html/lib/pkp/classes/plugins/PluginRegistry.inc.php(69): AlgoliaPlugin->register()\n#5 /var/www/html/lib/pkp/classes/plugins/PluginRegistry.inc.php(144): PluginRegistry::register()\n#6 /var/www/html/lib/pkp/classes/plugins/PluginRegistry.inc.php(214): PluginRegistry::loadCategory()\n#7 /var/www/html/plugins/generic/customLocale/controllers/grid/CustomLocaleAction.inc.php(22): PluginRegistry::loadAllPlugins()\n#8 /var/www/html/plugins/generic/customLocale/controllers/grid/Cu in /var/www/html/plugins/generic/algolia/AlgoliaPlugin.inc.php on line 340, referer: https://journal.bahaistudies.ca/online/management/settings/website
[Fri Feb 19 20:17:10.508306 2021] [php7:error] [pid 793] [client 70.66.230.254:64499] PHP Fatal error:  Uncaught Error: Call to undefined method AlgoliaPlugin::getTemplateResourceName() in /var/www/html/plugins/generic/algolia/AlgoliaPlugin.inc.php:340\nStack trace:\n#0 /var/www/html/lib/pkp/classes/plugins/Plugin.inc.php(367): AlgoliaPlugin->getTemplatePath()\n#1 /var/www/html/lib/pkp/classes/plugins/Plugin.inc.php(118): Plugin->_registerTemplateResource()\n#2 /var/www/html/lib/pkp/classes/plugins/LazyLoadPlugin.inc.php(28): Plugin->register()\n#3 /var/www/html/plugins/generic/algolia/AlgoliaPlugin.inc.php(41): LazyLoadPlugin->register()\n#4 /var/www/html/lib/pkp/classes/plugins/PluginRegistry.inc.php(69): AlgoliaPlugin->register()\n#5 /var/www/html/lib/pkp/classes/plugins/PluginRegistry.inc.php(144): PluginRegistry::register()\n#6 /var/www/html/lib/pkp/classes/controllers/grid/plugins/PluginGridHandler.inc.php(155): PluginRegistry::loadCategory()\n#7 /var/www/html/controllers/grid/settings/plugins/SettingsPluginGridHandler.inc.php(36): PluginGridHandler->loadCategoryData()\n#8 /var/www/html/lib/pkp/classes/controllers/ in /var/www/html/plugins/generic/algolia/AlgoliaPlugin.inc.php on line 340, referer: https://journal.bahaistudies.ca/online/management/settings/website
[Fri Feb 19 20:17:10.689344 2021] [php7:notice] [pid 794] [client 70.66.230.254:64500] ojs2: 404 Not Found

access.log

70.66.230.254 - - [19/Feb/2021:20:17:10 +0000] "GET /online/$$$call$$$/grid/settings/plugins/settings-plugin-grid/fetch-grid?_=1613765829408 HTTP/1.1" 500 4118 "https://journal.bahaistudies.ca/online/management/settings/website" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36"
70.66.230.254 - - [19/Feb/2021:20:17:10 +0000] "GET /lib/pkp/lib/vendor/tinymce/tinymce/skins/lightgray/skin.min.css.map HTTP/1.1" 404 447 "-" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36"

Possible Issues

So it seems like the most relevant issue here is:

PHP Fatal error:  Uncaught Error: Call to undefined method AlgoliaPlugin::getTemplateResourceName() in /var/www/html/plugins/generic/algolia/AlgoliaPlugin.inc.php

You can find the line here:

return $this->getTemplateResourceName() . ':templates/';

There are also some other errors it seems. I don’t have the adequate experience with the plugin system needed to figure out why this would through an error.

Environment

OJS Version history

Version Major Minor Revision Build Date installed
3.2.1.2 3 2 1 2 2021-01-19

Server Information

Setting Name Setting Value
OS platform Linux
PHP version 7.4.3
Apache version Apache/2.4.41 (Ubuntu)
Database driver mysqli
Database server version 8.0.23-0ubuntu0.20.04.1

Hi @benaltair,

This is a change in the way Smarty templates were managed between OJS 3.1.1 and 3.1.2. Remove the getTemplatePath function from your plugin class, and make sure any templates are in the templates subdirectory of your plugin. For more recent releases, we’ve been publishing a release notebook to guide through changes like this – see e.g. OJS/OMP v3.2 Release Notebook - OJS/OMP

Regards,
Alec Smecher
Public Knowledge Project Team

1 Like

Thanks @asmecher that gets me one step closer. I can now install the plugin, but when I try to open the settings page, I get an error.

GET https://journal.bahaistudies.ca/online/$$$call$$$/grid/settings/plugins/settings-plugin-grid/manage?plugin=algoliaplugin&category=generic&verb=settings&_=1613779634889 500 (Internal Server Error)

image

access.log

70.66.230.254 - - [20/Feb/2021:00:14:51 +0000] "GET /online/$$$call$$$/grid/settings/plugins/settings-plugin-grid/manage?plugin=algoliaplugin&category=generic&verb=settings&_=1613779634890 HTTP/1.1" 500 4118 "https://journal.bahaistudies.ca/online/management/settings/website" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36"

error.log

[Sat Feb 20 00:14:51.689587 2021] [php7:warn] [pid 10706] [client 70.66.230.254:56992] PHP Warning:  Declaration of AlgoliaSettingsForm::execute() should be compatible with Form::execute(...$functionArgs) in /var/www/html/plugins/generic/algolia/classes/form/AlgoliaSettingsForm.inc.php on line 81, referer: https://journal.bahaistudies.ca/online/management/settings/website
[Sat Feb 20 00:14:51.691020 2021] [php7:warn] [pid 10706] [client 70.66.230.254:56992] PHP Warning:  filemtime(): stat failed for lib/pkp/templates/plugins/generic/algolia/templatessettingsForm.tpl in /var/www/html/lib/pkp/classes/template/PKPTemplateResource.inc.php on line 51, referer: https://journal.bahaistudies.ca/online/management/settings/website
[Sat Feb 20 00:14:51.691117 2021] [php7:error] [pid 10706] [client 70.66.230.254:56992] PHP Fatal error:  Uncaught  --> Smarty: Unable to load template 'app:plugins/generic/algolia/templatessettingsForm.tpl' <-- \n  thrown in /var/www/html/lib/pkp/lib/vendor/smarty/smarty/libs/sysplugins/smarty_internal_template.php on line 195, referer: https://journal.bahaistudies.ca/online/management/settings/website

Any ideas what to look for here?

Hi @benaltair,

Is your fork of the plugin available on github somewhere? It would be easy to figure out what’s happening if I could refer to the code.

Regards,
Alec Smecher
Public Knowledge Project Team

Sure thing @asmecher GitHub - bahaistudies/ojs-algolia: Plugin integrating OJS and Algolia

Hi @benaltair,

This is another related change that came with 3.1.2, if I recall. The conventions for referring to a template in a plugin changed. See for example this change: Changes for OJS master branch compatibility · pkp/pln@c4afa7d · GitHub

Regards,
Alec Smecher
Public Knowledge Project Team

Great, the substitution from getTemplatePath() . DIRECTORY_SEPARATOR . '[file.tpl]') to getTemplateResource('[file.tpl]') got the settings page open. Thanks for the pointer @asmecher

1 Like

It’s still throwing a few errors around articleDAO when attempting to build the index.

[Mon Feb 22 23:43:51.342847 2021] [php7:warn] [pid 84869] [client 70.66.230.254:49658] PHP Warning:  Declaration of AlgoliaSettingsForm::execute() should be compatible with Form::execute(...$functionArgs) in /var/www/html/plugins/generic/algolia/classes/form/AlgoliaSettingsForm.inc.php on line 81, referer: https://journal.bahaistudies.ca/online/management/settings/website
[Mon Feb 22 23:43:51.349514 2021] [php7:notice] [pid 84869] [client 70.66.230.254:49658] ojs2: Unrecognized DAO ArticleDAO!, referer: https://journal.bahaistudies.ca/online/management/settings/website
[Mon Feb 22 23:43:56.223895 2021] [php7:notice] [pid 84869] [client 70.66.230.254:49658] ojs2: 404 Not Found

I remember maybe reading about $articleDao being deprecated, but I’m not sure. I don’t see it in the API reference, so maybe this needs to be changed. Are there any resources that might help with migrating a plugin in that way? I’ve looked through a number of issues and PRs but couldn’t find much applicable so far.

The error also mentions this function:

    function execute() {
        $plugin = $this->_plugin;
        $formFields = $this->_getFormFields();
        foreach($formFields as $formField) {
            $plugin->updateSetting(CONTEXT_SITE, $formField, $this->getData($formField), 'string');
        }
    }

Hi @benaltair,

Now you’re into better-documented territory; see OJS/OMP v3.2 Release Notebook - OJS/OMP.

Regards,
Alec Smecher
Public Knowledge Project Team

1 Like