pkp / jatsTemplate

Basic JATS document template generator plugin for OJS
GNU General Public License v3.0
9 stars 13 forks source link

PHP Fatal Error: Duplicate declaration static variable $purifier #55

Closed danielmoralesc closed 2 months ago

danielmoralesc commented 2 months ago

Hi.

Today I updated the JatsTemplate plugin from 1.0.6.1 to 1.0.6.2 in OJS 3.3.0.19. The OJS website gives me a 500 error.

The "tools/upgrade.php check" command returns the following result: "PHP Fatal error: Duplicate declaration of static variable $purifier in /var/www/haal.cl/html/plugins/generic/jatsTemplate/JatsTemplatePlugin.inc.php on line 299"

In the mentioned file there are two declarations of $purifier (one in 177 line and the second in line 299), if I disable one of them I fix it and the site works again.

I don't know how to solve this correctly. Regards

Here is my main information of server Nginx. OS Platform Linux PHP Version 8.3.11 ApacheVersion nginx/1.24.0 Database driver mysql Database server version 8.0.39-0ubuntu0.24.04.2

asmecher commented 2 months ago

@danielmoralesc, can you try the following patch?

diff --git a/JatsTemplatePlugin.inc.php b/JatsTemplatePlugin.inc.php
index 9426c62..8bcca29 100644
--- a/JatsTemplatePlugin.inc.php
+++ b/JatsTemplatePlugin.inc.php
@@ -83,6 +83,8 @@ class JatsTemplatePlugin extends GenericPlugin {
        if (!$datePublished) $datePublished = $issue->getDatePublished();
        if ($datePublished) $datePublished = strtotime($datePublished);

+       static $purifier;
+
        $response = "<article
            xmlns:xlink=\"http://www.w3.org/1999/xlink\"
            xmlns:mml=\"http://www.w3.org/1998/Math/MathML\"
@@ -174,7 +176,6 @@ class JatsTemplatePlugin extends GenericPlugin {
                "\t\t\t\t\t<email>" . htmlspecialchars($author->getEmail()) . "</email>\n" .
                (($s = $author->getUrl()) != ''?"\t\t\t\t\t<uri>" . htmlspecialchars($s) . "</uri>\n":'');

-           static $purifier;
            if (!$purifier) {
                $config = HTMLPurifier_Config::createDefault();
                $config->set('HTML.Allowed', 'p,em,strong');
@@ -298,7 +299,6 @@ class JatsTemplatePlugin extends GenericPlugin {
            $filepath = $fileService->get($galleyFile->getData('fileId'))->path;
            $mimeType = $fileService->fs->getMimetype($filepath);
            if (in_array($mimeType, ['text/html'])) {
-               static $purifier;
                if (!$purifier) {
                    $config = HTMLPurifier_Config::createDefault();
                    $config->set('HTML.Allowed', 'p');
danielmoralesc commented 2 months ago

I added the patch and it's working!.

Thanks!

asmecher commented 2 months ago

Merged to stable-3_3_0 and stable-3_4_0, thanks!