Cannot use object type stdClass as array in classes/statistics/MetricsDAO.inc.php

Hi
I’m using OJS version 3.1.2-1
When generating a custom statistics report I get a warning then an error see error log below. The result is just a blank page with a 500 error.
If this is a permission error which directory would this be writing too? It already has write permissions to the cache directory so I’m a bit confused.

[Wed Jan 15 12:14:50.437308 2020] [php7:warn] PHP Warning: file_put_contents(cache/fc-pluginSettings-0-defaultthemeplugin.php): failed to open stream: Permission denied in lib/pkp/classes/cache/FileCache.inc.php on line 90

PHP Fatal error: Uncaught Error: Cannot use object of type stdClass as array in classes/statistics/MetricsDAO.inc.php:34
Stack trace:
#0 plugins/generic/usageStats/PKPUsageStatsReportPlugin.inc.php(84): MetricsDAO->getMetrics(‘ojs::counter’, Array, Object(stdClass), Array, NULL)
#1 plugins/generic/usageStats/OJSUsageStatsReportPlugin.inc.php(32): PKPUsageStatsReportPlugin->getMetrics(‘ojs::counter’, Array, Object(stdClass), Array, NULL)
#2 /lib/pkp/pages/management/PKPToolsHandler.inc.php(208): OJSUsageStatsReportPlugin->getMetrics(‘ojs::counter’, Array, Object(stdClass), Array)
#3 /lib/pkp/pages/management/PKPToolsHandler.inc.php(64): PKPToolsHandler->generateReport(Array, Object(Request))
#4 /lib/pkp/classes/core/PKPRouter.inc.php(390): PKPToolsHandler->tools(Array, Object(Request))
#5 /lib/pkp in /classes/statistics/MetricsDAO.inc.php on line 34, referer: /management/tools/reportGenerator

Just flagging this! Our custom reports are failing for all of our journals - we’re not sure if this started with our upgrade to 3.1.2-1, but it’s consistent across all of our journals. Other stats reports are still working, but custom reports just generate a 500 error. jhennig (above) captured some error messages from the log, but we need help decoding them and trying to id the problem.

Thanks for any help anyone can provide!

Hi all,

I suspect you need to apply pkp/pkp-lib#5302 Cast stdClass to array to avoid warnings · pkp/pkp-lib@8486017 · GitHub to resolve this. (Please check to see if the patch will apply cleanly e.g. using the --dry-run option to the patch tool before you actually apply it.)

Note that this is already included in OJS since version 3.1.2-3, so upgrading is also an option.

Regards,
Alec Smecher
Public Knowledge Project Team

Thanks @asmecher - we’ll give that a try and see if it resolves the issue!

1 Like

You may also need this one as well:

https://github.com/pkp/pkp-lib/commit/103eeed2fc9cfb71aa7d02bcc683e542f6a2a1c4

If you run custom reports with date ranges.

Cheers,
Jason

1 Like