@tsteur opened this Issue on October 26th 2022 Member

This was actually supposed to be fixed in https://github.com/matomo-org/matomo/issues/18794 but seems to be still a problem. It is the same URL as in #18794 . Or is it a regression?

Error: {"message":"strpos(): Argument #1 ($haystack) must be of type string, array given","file":"\/core\/Period\/Range.php","line":535,"request_id":"f2aab","backtrace":" on \/core\/Period\/Range.php(535)\n#0 \/core\/Period\/Range.php(535): strpos(Array, '-')\n#1 \/plugins\/ImageGraph\/ImageGraph.php(91): Piwik\Period\Range::getRelativeToEndDate('day', 'last30', Array, Object(Piwik\Site))\n#2 [internal function]: Piwik\Plugins\ImageGraph\ImageGraph->getReportMetadata(Array, Array)\n#3 \/core\/EventDispatcher.php(147): call_user_func_array(Array, Array)\n#4 \/core\/Piwik.php(871): Piwik\EventDispatcher->postEvent('API.getReportMe...', Array, false, Array)\n#5 \/plugins\/API\/ProcessedReport.php(220): Piwik\Piwik::postEvent('API.getReportMe...', Array)\n#6 \/plugins\/API\/API.php(272): Piwik\Plugins\API\ProcessedReport->getReportMetadata('1', 'day', Array, false, false)\n#7 \/core\/Plugin\/Controller.php(430): Piwik\Plugins\API\API->getReportMetadata('1', 'day', Array)\n#8 \/plugins\/VisitsSummary\/Controller.php(119): Piwik\Plugin\Controller->getLastUnitGraphAcrossPlugins('VisitsSummary', 'getEvolutionGra...', false, Array, 'This is an over...')\n#9 [internal function]: Piwik\Plugins\VisitsSummary\Controller->getEvolutionGraph()\n#10 \/core\/FrontController.php(631): call_user_func_array(Array, Array)\n#11 \/core\/FrontController.php(169): Piwik\FrontController->doDispatch('VisitsSummary', 'getEvolutionGra...', Array)\n#12 \/core\/dispatch.php(32): Piwik\FrontController->dispatch()\n#13 \/index.php(25): require_once('\/c...')\n#14 {main}","safemode_backtrace":"#0 [internal function]: Piwik\Plugins\Cloud\Controller->safemode(Array)\n#1 \/core\/FrontController.php(631): call_user_func_array(Array, Array)\n#2 \/core\/FrontController.php(169): Piwik\FrontController->doDispatch('Cloud', 'safemode', Array)\n#3 \/core\/FrontController.php(100): Piwik\FrontController->dispatch('CorePluginsAdmi...', 'safemode', Array)\n#4 \/core\/FrontController.php(140): Piwik\FrontController::(Array)\n#5 \/core\/FrontController.php(190): Piwik\FrontController::(Object(TypeError))\n#6 \/core\/dispatch.php(32): Piwik\FrontController->dispatch()\n#7 \/index.php(25): require_once('\/c...')\n#8 {main}"}

URL: https://demo.matomo.cloud/index.php?action=getEvolutionGraph&date%5B0%5D=exp&date%5B1%5D=%3D1%E9%8E%88%27%22%5C%28&disableLink=0&forceView=1&idSite=1&module=VisitsSummary&period=day&viewDataTable=graphEvolution&widget=1

GET: {"action":"getEvolutionGraph","date":["exp","=1\u9388'\"\("],"disableLink":"0","forceView":"1","idSite":"1","module":"VisitsSummary","period":"day","viewDataTable":"graphEvolution","widget":"1"}

@bx80 commented on October 26th 2022 Contributor

Looks like a potential regression, I'll assigned it to the current release.

@peterhashair commented on October 27th 2022 Contributor

I guess this could be coupe options here. https://github.com/matomo-org/matomo/blob/037cb426563244889c0f27aad168c0356377d387/core/Period/Range.php#L530

I can think of is add a check here.

 public static function getRelativeToEndDate(string $period, string $lastN, string $endDate, $site)
     if (!is_string($endDate) || !is_string($period) || !is_int($lastN)) {
            throw new \Exception("Invalid Input");
        }
@sgiehl commented on October 28th 2022 Member

@peterhashair For such cases it is always important to reproduce that locally. That way you may actually see the full set of errors/notices that occur.
Using PHP 7.2 the URL in the issue actually results in:

WARNING API[2022-10-28 07:48:43 UTC] [e1a71] /srv/matomo/plugins/API/ProcessedReport.php(818): Notice - Array to string conversion - Matomo 4.12.3 - Please report this message in the Matomo forums: https://forum.matomo.org (please do a search first as it might have been reported already) <a href='/0'>#0</a>/plugins/API/ProcessedReport.php(818),<a href='/1'>#1</a>/plugins/API/ProcessedReport.php(178),<a href='/2'>#2</a>/plugins/API/API.php(272),<a href='/3'>#3</a>/core/Plugin/Controller.php(430),<a href='/4'>#4</a>/plugins/VisitsSummary/Controller.php(120),[internal function]: Piwik\Plugins\VisitsSummary\Controller->getEvolutionGraph(),<a href='/6'>#6</a>/core/FrontController.php(631),<a href='/7'>#7</a>/core/FrontController.php(169),<a href='/8'>#8</a>/core/dispatch.php(32),<a href='/9'>#9</a>/index.php(25)
WARNING ImageGraph[2022-10-28 07:48:43 UTC] [e1a71] /srv/matomo/core/Period/Range.php(535): Warning - strpos() expects parameter 1 to be string, array given - Matomo 4.12.3 - Please report this message in the Matomo forums: https://forum.matomo.org (please do a search first as it might have been reported already) [internal function]: Piwik\ErrorHandler::errorHandler(),<a href='/1'>#1</a>/core/Period/Range.php(535),<a href='/2'>#2</a>/plugins/ImageGraph/ImageGraph.php(94),[internal function]: Piwik\Plugins\ImageGraph\ImageGraph->getReportMetadata(),<a href='/4'>#4</a>/core/EventDispatcher.php(147),<a href='/5'>#5</a>/core/Piwik.php(871),<a href='/6'>#6</a>/plugins/API/ProcessedReport.php(220),<a href='/7'>#7</a>/plugins/API/API.php(272),<a href='/8'>#8</a>/core/Plugin/Controller.php(430),<a href='/9'>#9</a>/plugins/VisitsSummary/Controller.php(120)
WARNING ImageGraph[2022-10-28 07:48:43 UTC] [e1a71] /srv/matomo/core/Date.php(138): Warning - urldecode() expects parameter 1 to be string, array given - Matomo 4.12.3 - Please report this message in the Matomo forums: https://forum.matomo.org (please do a search first as it might have been reported already) [internal function]: Piwik\ErrorHandler::errorHandler(),<a href='/1'>#1</a>/core/Date.php(138),<a href='/2'>#2</a>/core/Period/Range.php(539),<a href='/3'>#3</a>/plugins/ImageGraph/ImageGraph.php(94),[internal function]: Piwik\Plugins\ImageGraph\ImageGraph->getReportMetadata(),<a href='/5'>#5</a>/core/EventDispatcher.php(147),<a href='/6'>#6</a>/core/Piwik.php(871),<a href='/7'>#7</a>/plugins/API/ProcessedReport.php(220),<a href='/8'>#8</a>/plugins/API/API.php(272),<a href='/9'>#9</a>/core/Plugin/Controller.php(430)
WARNING ImageGraph[2022-10-28 07:48:43 UTC] [e1a71] /srv/matomo/core/Date.php(140): Warning - urldecode() expects parameter 1 to be string, array given - Matomo 4.12.3 - Please report this message in the Matomo forums: https://forum.matomo.org (please do a search first as it might have been reported already) [internal function]: Piwik\ErrorHandler::errorHandler(),<a href='/1'>#1</a>/core/Date.php(140),<a href='/2'>#2</a>/core/Period/Range.php(539),<a href='/3'>#3</a>/plugins/ImageGraph/ImageGraph.php(94),[internal function]: Piwik\Plugins\ImageGraph\ImageGraph->getReportMetadata(),<a href='/5'>#5</a>/core/EventDispatcher.php(147),<a href='/6'>#6</a>/core/Piwik.php(871),<a href='/7'>#7</a>/plugins/API/ProcessedReport.php(220),<a href='/8'>#8</a>/plugins/API/API.php(272),<a href='/9'>#9</a>/core/Plugin/Controller.php(430)
WARNING ImageGraph[2022-10-28 07:48:43 UTC] [e1a71] /srv/matomo/core/Date.php(142): Warning - urldecode() expects parameter 1 to be string, array given - Matomo 4.12.3 - Please report this message in the Matomo forums: https://forum.matomo.org (please do a search first as it might have been reported already) [internal function]: Piwik\ErrorHandler::errorHandler(),<a href='/1'>#1</a>/core/Date.php(142),<a href='/2'>#2</a>/core/Period/Range.php(539),<a href='/3'>#3</a>/plugins/ImageGraph/ImageGraph.php(94),[internal function]: Piwik\Plugins\ImageGraph\ImageGraph->getReportMetadata(),<a href='/5'>#5</a>/core/EventDispatcher.php(147),<a href='/6'>#6</a>/core/Piwik.php(871),<a href='/7'>#7</a>/plugins/API/ProcessedReport.php(220),<a href='/8'>#8</a>/plugins/API/API.php(272),<a href='/9'>#9</a>/core/Plugin/Controller.php(430)
WARNING ImageGraph[2022-10-28 07:48:43 UTC] [e1a71] /srv/matomo/core/Date.php(148): Warning - strpos() expects parameter 1 to be string, array given - Matomo 4.12.3 - Please report this message in the Matomo forums: https://forum.matomo.org (please do a search first as it might have been reported already) [internal function]: Piwik\ErrorHandler::errorHandler(),<a href='/1'>#1</a>/core/Date.php(148),<a href='/2'>#2</a>/core/Period/Range.php(539),<a href='/3'>#3</a>/plugins/ImageGraph/ImageGraph.php(94),[internal function]: Piwik\Plugins\ImageGraph\ImageGraph->getReportMetadata(),<a href='/5'>#5</a>/core/EventDispatcher.php(147),<a href='/6'>#6</a>/core/Piwik.php(871),<a href='/7'>#7</a>/plugins/API/ProcessedReport.php(220),<a href='/8'>#8</a>/plugins/API/API.php(272),<a href='/9'>#9</a>/core/Plugin/Controller.php(430)
WARNING ImageGraph[2022-10-28 07:48:43 UTC] [e1a71] /srv/matomo/core/Date.php(1144): Notice - Array to string conversion - Matomo 4.12.3 - Please report this message in the Matomo forums: https://forum.matomo.org (please do a search first as it might have been reported already) <a href='/0'>#0</a>/core/Date.php(1144),<a href='/1'>#1</a>/core/Date.php(153),<a href='/2'>#2</a>/core/Period/Range.php(539),<a href='/3'>#3</a>/plugins/ImageGraph/ImageGraph.php(94),[internal function]: Piwik\Plugins\ImageGraph\ImageGraph->getReportMetadata(),<a href='/5'>#5</a>/core/EventDispatcher.php(147),<a href='/6'>#6</a>/core/Piwik.php(871),<a href='/7'>#7</a>/plugins/API/ProcessedReport.php(220),<a href='/8'>#8</a>/plugins/API/API.php(272),<a href='/9'>#9</a>/core/Plugin/Controller.php(430)
ERROR Piwik\ExceptionHandler[2022-10-28 07:48:43 UTC] [e1a71] Uncaught exception: /srv/matomo/core/Date.php(1144): Das Datumsformat muss YYYY-MM-DD, or 'today' or 'yesterday' oder eine andere, von der Funktion strtotime unterstützte Zeichenkette sein. (Besuchen Sie http://php.net/strtotime für nähere Informationen): Array [Query: ?action=getEvolutionGraph&date%5B0%5D=exp&date%5B1%5D=%3D1%E9%8E%88%27%22%5C%28&disableLink=0&forceView=1&idSite=1&module=VisitsSummary&period=day&viewDataTable=graphEvolution&widget=1, CLI mode: 0]

So the fix for https://github.com/matomo-org/matomo/issues/18794 is actually doing what it should - it results in an invalid date exception that is shown to the user. But there are a couple of warnings/notices on they way, that shouldn't be triggered.
Looking through all the stacktraces actually shows, that adjusting getRelativeToEndDate will not fix all of them. The problem is in Controller::getLastUnitGraphAcrossPlugins, as it directly passes through the input date & period.

This Issue was closed on October 30th 2022
Powered by GitHub Issue Mirror