OJS 3 Does not Register Custom Plugin

I am new developing for OJS3 and I have been developing a Plugin to generate a download link for a PDF file.

In general, the plugin obtains the data from the DB of OJS3 to generate a letter of acceptance of an article for its publication (title, name of the authors, date of upload, date of modification of status, and status of the article). The plugin uses this information to generate a url encoded in json and encrypted in base 64 to pass the data as a parameter to another php program.
I had no problems getting the data, but I can not get OJS3 to register the plugin.

Here is the part of my code that register my plugin

function register($category, $path){
$success = parent::register($category, $path);
if(!Config::getVar(‘general’, ‘installed’) || defined(‘RUNNING_UPGRADE’)) return $success;
if($success && $this->getEnabled()){
HookRegistry::register(‘Templates::Article::Footer::PageFooter’, array($this, ‘callbackTemplateArticlePageFooter’));
}
return $success;
}

Here is a link to the plugin

GitHub - htorres09/cartaPlugin: Plugin de Carta AceptaciĂłn para OJS3

Hi @htorres09,

The plugin probably isn’t registered with the system. This happens when you do any of the following


  • Install the plugin through the plugin gallery or by uploading the .tar.gz package
  • Run the upgrade script with the plugin in place
  • Manually register the plugin with lib/pkp/tools/installPluginVersion.php

When writing a fresh plugin from scratch, the last way is the best option. You can double-check that it worked by looking in the versions table for an entry for the plugin.

Also ensure that your version.xml has an <application> element that matches the directory the plugin has been installed into. For plugins/generic/tinymce, you’ll see <application>tinymce</application>, for example. If the names don’t match, you’ll have trouble with the registration function as you describe.

Regards,
Alec Smecher
Public Knowledge Project Team

1 Like

Yes, I try to uploading it in .tar.gz package. But I never saw the folder with the plugin appear in ~ojs3/plugins/generic

Then I copy of the plugin folder, change the ownerships of the files and granted permissions, and try to update via script

php tools/upgrade.php upgrade

When I tried to see it in the Dashboard, I got an error in the browser console

~/index.php/test/$$$call$$$/grid/settings/plugins/settings-plugin-grid/ fetch-grid? _ = 1516314756216
Failed to load resource: the server responded with a status of 500 (Internal Server Error)

My error log:

PHP Fatal error: Call to a member function getCurrent() on null in /www/htdocs/ss/hector/ojs3/lib/pkp/classes/site/VersionDAO.inc.php on line 135, referer : ~index.php/test/management/settings/website

I will try to register manually as you suggest. Thanks for the help.

My Version.xml

<application>carta</application>
<type>plugins.generic</type>
<release>1.0.0.0</release>
<date>2018-01-16</date>
<lazy-load>1</lazy-load>
<sitewide>1</sitewide>
<class>CartaPlugin</class>

How can I register the plugin manually?
I read the source code of installPluginVersion.php
But how do I use it? Can you refer me to document to se how to register it manually?

Hi @htorres09,

To get its usage information, just run it:

 $ php lib/pkp/tools/installPluginVersion.php 
Install plugin version tool
Usage: lib/pkp/tools/installPluginVersion.php path/to/version.xml

Regards,
Alec Smecher
Public Knowledge Project Team

Thanks!
I will try it and see the result.

Didn’t work.
It sends me an error, try to se definition of the function in OpenJournalSystems 3.0.0, but definition of getData() can’t be seen.

PHP Fatal error: Call to a member function getProductType() on null in ~/ojs3/lib/pkp/tools/installPluginVersion.php on line 57

Hi @htorres09,

Are you actually using OJS 3.0.0? If so, I’d strongly suggest upgrading.

Regards,
Alec Smecher
Public Knowledge Project Team

I had OJS 3.1.0-1, clean installation. Still got the error when I try to register via installPluginVersion.php

PHP Fatal error: Call to a member function getProductType() on null in ~/ojs3/lib/pkp/tools/installPluginVersion.php on line 57

Hi @htorres09,

What directory is the plugin in? (I.e. what is the full path to version.xml?)

Regards,
Alec Smecher
Public Knowledge Project Team

Full path is

/www/htdocs/ss/user/ojs3/plugins/generic/carta/version.xml

Hi @htorres09,

Hmm, that looks fine – what is the entry for the plugin in the versions table?

Regards,
Alec Smecher
Public Knowledge Project Team

That’s part of the problem, I search in versions table and don’t find an entry; also didn’t find an entry in plugin_settings.

Hi @htorres09,

Do you have an entry in versions where product = ojs2?

Regards,
Alec Smecher
Public Knowledge Project Team

Just the core.

image

Hi @htorres09,

Check your XML using an XML validator; I think you’re encountering a parsing problem.

Regards,
Alec Smecher
Public Knowledge Project Team

Thanks. I find the parsing problem with XML and now it is registered.
But as I try to enable the plugin in the dashboard found a weird behaivor, it added another instance of the plugin in the plugin list.

function register($category, $path){
$success = parent::register($category, $path);
if(!Config::getVar(‘general’, ‘installed’) || defined(‘RUNNING_UPGRADE’)) return $success;
if($success && $this->getEnabled()){
HookRegistry::register(‘Templates::Article::Footer::PageFooter’, array($this, ‘callbackTemplateArticlePageFooter’)); }
return $success; }

My template path function

function getTemplatePath($inCore = false){ return parent::getTemplatePath($inCore) . ‘templates/’; }

Callback snippet

function callbackTemplateArticlePageFooter($hookName, $params){
$smarty =& $params[1];
$output =& $params[2];


// Visualize
$url = “<a href=” . $query . “’ target=‘_blank’ class='‘pkp_button_primary’> Ver Carta de Aceptación ”;
$smarty->assign(‘query’, $url);
$output .= $smarty->fetch($this->getTemplatePath() . ‘articleFooter.tpl’);
return false;
}

Before enabling the plugin [TEST] Carta de AceptaciĂłn

After enabling the plugin

The articleFooter.tpl

<div id=“cartaPanel”>
<h3>{translate key=“plugins.generic.carta.header”}</h3>
<ul>
{if !$query->wasEmpty()}
<li>{$query}</li>
{/if}
</ul>
</div>

But it doesn’t display it.

Hi @htorres09,

Off the top of my head, the kind of template override you’re coding won’t be supported until OJS 3.1.1 is released. I’d suggest using a hook, e.g. TemplateManager::display, to override templates. There are examples of this in the plugins distributed with OJS.

Regards,
Alec Smecher
Public Knowledge Project Team

Thanks, I take the recommendedByAuthorPlugin as base.
I will look at the examples, thanks again.