Omeka S 3.1.0 "asHtml()" error

Hello. After updating Omeka S to the latest version 3.1.0 I have found a new error in my personalized theme that did not occur in the previous 3.0.2 version . Specifically in this strings of the browse.phtml (item-set) file:

  $descripcion = $body; ?>
                <?php if ($descripcion) {
                        if (mb_strlen($descripcion) > 110) {
                            echo '<div class="description">' . $descripcion . ' [...]' . '</div>';
                        } else {
                            echo '<div class="description">' . $descripcion->asHtml() . '</div>';
                        }
                    };
  ?>

That “->asHtml()” produces the following error:


Laminas\Db\Adapter\Exception\InvalidQueryException
Statement could not be executed (42000 - 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"log" ("created","severity","message","owner_id","context") VALUES ('2021-09-14 ' at line 1)

Detalles:

PDOException: SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"log" ("created","severity","message","owner_id","context") VALUES ('2021-09-14 ' at line 1 in /home/site/www/vendor/laminas/laminas-db/src/Adapter/Driver/Pdo/Statement.php:238
Stack trace:
#0 /home/site/www/vendor/laminas/laminas-db/src/Adapter/Driver/Pdo/Statement.php(238): PDOStatement->execute()
#1 /home/site/www/vendor/laminas/laminas-log/src/Writer/Db.php(128): Laminas\Db\Adapter\Driver\Pdo\Statement->execute(Array)
#2 /home/site/www/vendor/laminas/laminas-log/src/Writer/AbstractWriter.php(282): Laminas\Log\Writer\Db->doWrite(Array)
#3 /home/site/www/vendor/laminas/laminas-log/src/Logger.php(459): Laminas\Log\Writer\AbstractWriter->write(Array)
#4 /home/site/www/vendor/laminas/laminas-log/src/Logger.php(502): Laminas\Log\Logger->log(3, 'Error: Call to ...', Array)
#5 /home/site/www/application/src/Mvc/ExceptionListener.php(54): Laminas\Log\Logger->err('Error: Call to ...')
#6 /home/site/www/vendor/laminas/laminas-eventmanager/src/EventManager.php(321): Omeka\Mvc\ExceptionListener->handleException(Object(Laminas\Mvc\MvcEvent))
#7 /home/site/www/vendor/laminas/laminas-eventmanager/src/EventManager.php(170): Laminas\EventManager\EventManager->triggerListeners(Object(Laminas\Mvc\MvcEvent))
#8 /home/site/www/vendor/laminas/laminas-mvc/src/View/Http/DefaultRenderingStrategy.php(122): Laminas\EventManager\EventManager->triggerEvent(Object(Laminas\Mvc\MvcEvent))
#9 /home/site/www/vendor/laminas/laminas-eventmanager/src/EventManager.php(321): Laminas\Mvc\View\Http\DefaultRenderingStrategy->render(Object(Laminas\Mvc\MvcEvent))
#10 /home/site/www/vendor/laminas/laminas-eventmanager/src/EventManager.php(170): Laminas\EventManager\EventManager->triggerListeners(Object(Laminas\Mvc\MvcEvent))
#11 /home/site/www/vendor/laminas/laminas-mvc/src/Application.php(366): Laminas\EventManager\EventManager->triggerEvent(Object(Laminas\Mvc\MvcEvent))
#12 /home/site/www/vendor/laminas/laminas-mvc/src/Application.php(347): Laminas\Mvc\Application->completeRequest(Object(Laminas\Mvc\MvcEvent))
#13 /home/site/www/index.php(21): Laminas\Mvc\Application->run()
#14 {main}

Next Laminas\Db\Adapter\Exception\InvalidQueryException: Statement could not be executed (42000 - 1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '"log" ("created","severity","message","owner_id","context") VALUES ('2021-09-14 ' at line 1) in /home/site/www/vendor/laminas/laminas-db/src/Adapter/Driver/Pdo/Statement.php:243
Stack trace:
#0 /home/site/www/vendor/laminas/laminas-log/src/Writer/Db.php(128): Laminas\Db\Adapter\Driver\Pdo\Statement->execute(Array)
#1 /home/site/www/vendor/laminas/laminas-log/src/Writer/AbstractWriter.php(282): Laminas\Log\Writer\Db->doWrite(Array)
#2 /home/site/www/vendor/laminas/laminas-log/src/Logger.php(459): Laminas\Log\Writer\AbstractWriter->write(Array)
#3 /home/site/www/vendor/laminas/laminas-log/src/Logger.php(502): Laminas\Log\Logger->log(3, 'Error: Call to ...', Array)
#4 /home/site/www/application/src/Mvc/ExceptionListener.php(54): Laminas\Log\Logger->err('Error: Call to ...')
#5 /home/site/www/vendor/laminas/laminas-eventmanager/src/EventManager.php(321): Omeka\Mvc\ExceptionListener->handleException(Object(Laminas\Mvc\MvcEvent))
#6 /home/site/www/vendor/laminas/laminas-eventmanager/src/EventManager.php(170): Laminas\EventManager\EventManager->triggerListeners(Object(Laminas\Mvc\MvcEvent))
#7 /home/site/www/vendor/laminas/laminas-mvc/src/View/Http/DefaultRenderingStrategy.php(122): Laminas\EventManager\EventManager->triggerEvent(Object(Laminas\Mvc\MvcEvent))
#8 /home/site/www/vendor/laminas/laminas-eventmanager/src/EventManager.php(321): Laminas\Mvc\View\Http\DefaultRenderingStrategy->render(Object(Laminas\Mvc\MvcEvent))
#9 /home/site/www/vendor/laminas/laminas-eventmanager/src/EventManager.php(170): Laminas\EventManager\EventManager->triggerListeners(Object(Laminas\Mvc\MvcEvent))
#10 /home/site/www/vendor/laminas/laminas-mvc/src/Application.php(366): Laminas\EventManager\EventManager->triggerEvent(Object(Laminas\Mvc\MvcEvent))
#11 /home/site/www/vendor/laminas/laminas-mvc/src/Application.php(347): Laminas\Mvc\Application->completeRequest(Object(Laminas\Mvc\MvcEvent))
#12 /home/site/www/index.php(21): Laminas\Mvc\Application->run()
#13 {main}

First of all, congratulations on the new version, it includes very interesting features and I am really happy to see Omeka S evolve. Greetings.

The error message you have here looks like it’s actually related to an error in saving the log message itself. Do you have a module installed that affects logging? You might need to disable it to see whatever the actual error is here.

Thanks, John, for your answer. After uninstall Log module, the error change:

 Error
Call to a member function asHtml() on string

Detalles:

Error: Call to a member function asHtml() on string in /home/site/www/themes/patrimoniouja/view/omeka/site/item-set/browse.phtml:73
Stack trace:
#0 /home/site/www/vendor/laminas/laminas-view/src/Renderer/PhpRenderer.php(505): include()
#1 /home/site/www/vendor/laminas/laminas-view/src/View.php(206): Laminas\View\Renderer\PhpRenderer->render(NULL)
#2 /home/site/www/vendor/laminas/laminas-view/src/View.php(235): Laminas\View\View->render(Object(Laminas\View\Model\ViewModel))
#3 /home/site/www/vendor/laminas/laminas-view/src/View.php(199): Laminas\View\View->renderChildren(Object(Laminas\View\Model\ViewModel))
#4 /home/site/www/vendor/laminas/laminas-mvc/src/View/Http/DefaultRenderingStrategy.php(104): Laminas\View\View->render(Object(Laminas\View\Model\ViewModel))
#5 /home/site/www/vendor/laminas/laminas-eventmanager/src/EventManager.php(321): Laminas\Mvc\View\Http\DefaultRenderingStrategy->render(Object(Laminas\Mvc\MvcEvent))
#6 /home/site/www/vendor/laminas/laminas-eventmanager/src/EventManager.php(170): Laminas\EventManager\EventManager->triggerListeners(Object(Laminas\Mvc\MvcEvent))
#7 /home/site/www/vendor/laminas/laminas-mvc/src/Application.php(366): Laminas\EventManager\EventManager->triggerEvent(Object(Laminas\Mvc\MvcEvent))
#8 /home/site/www/vendor/laminas/laminas-mvc/src/Application.php(347): Laminas\Mvc\Application->completeRequest(Object(Laminas\Mvc\MvcEvent))
#9 /home/site/www/index.php(21): Laminas\Mvc\Application->run()
#10 {main}

Any idea why? Thanks again. Greetings.

It would appear that $descripcion is a string, so you can’t call any methods on it. What you’ve posted doesn’t reveal where that comes from (the $body variable), but it’s probably a pretty simple case of either changing your code so you have the actual value object and not a string here, or just printing the string as-is and removing the “asHtml” call.

I will investigate it, although I am not sure why it worked with the previous version. I’ll put the solution here if I find it. Thanks and regards.

I still can’t find a solution, I don’t know why version 3.1.0 works differently. I paste the complete code for that section in case I was doing something wrong and someone could help me. Sorry for the insistence. All the best.

    <?php $this->trigger('view.browse.before'); ?>
    <ul class="resource-list-item-set <?php echo $currentLayout; ?>">
        <?php
        $headingTerm = $this->siteSetting('browse_heading_property_term');
        $bodyTerm = $this->siteSetting('browse_body_property_term');
        foreach ($itemSets as $itemSet) :
            $heading = $headingTerm ? $itemSet->value($headingTerm, ['default' => $translate('[Untitled]')]) : $itemSet->displayTitle();
            $body = $bodyTerm ? $itemSet->value($bodyTerm) : $itemSet->displayDescription();
        ?>
            <li class="item resource">
                <?php if ($thumbnail = $this->thumbnail($itemSet, 'large')) : ?>
                    <?php echo $itemSet->linkRaw($thumbnail, null, ['class' => 'thumbnail']); ?>
                <?php endif; ?>
                <h4><?php echo $itemSet->link($heading); ?></h4>

                <?php
                        $descripcion = $body; ?>
                <?php if ($descripcion) {
                    if (mb_strlen($descripcion) > 110) {
                        echo '<div class="description">' . $descripcion . ' [...]' . '</div>';
                    } else {
                        echo '<div class="description">' . $descripcion->asHtml() . '</div>';
                    }
                };
                ?>

            </li>
        <?php endforeach; ?>
    </ul>

What exactly are you trying to do here?

The code looks like it checks the length of the description: if it’s longer than 110 characters, then it adds an ellipsis to the end, if not then it prints the description.

What’s this adding that just echo $body; doesn’t do?

The issue for module Log is fixed in last version.

Yes, there is a check for lenght, but what it does is print the description. The problem is that the descriptions of some item-sets are authors and then the “->asHtml()” is necessary so that it does not return the URL of the item-set. In the old version of Omeka S this code worked fine, but not in the new one, I don’t know why . My knowledge of PHP as you can see is very limited, sorry. And really thanks, John and Daniel, for your answers.

displayDescription() returns a string, but value($bodyTerm) returns an object. So update your line as :

echo '<div class="description">' . (is_string($descripcion) ? $descripcion : $descripcion->asHtml()) . '</div>';
1 Like

Really thanks, Daniel!!

This topic was automatically closed 250 days after the last reply. New replies are no longer allowed.