PHP Arrays not Serialized by Default · Issue #6137 · matomo-org/matomo · GitHub
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP Arrays not Serialized by Default #6137

Closed
claytondaley opened this issue Sep 6, 2014 · 8 comments
Closed

PHP Arrays not Serialized by Default #6137

claytondaley opened this issue Sep 6, 2014 · 8 comments
Labels
Bug For errors / faults / flaws / inconsistencies etc. Major Indicates the severity or impact or benefit of an issue is much higher than normal but not critical.
Milestone

Comments

@claytondaley
Copy link
Contributor

Calls to SitesManager.getSitesIdFromSiteUrl&format=PHP&... are returning data structured like

array (
  0 => 
  array (
    'idsite' => '4',
  ),
)

instead of serialized data (e.g. SitesManager.getJavascriptTag&format=PHP&...):

s:825:"<!-- Piwik -->
<script type="text/javascript">
  var _paq = _paq || [];
  _paq.push(['trackPageView']);
  _paq.push(['enableLinkTracking']);
  (function() {
    var u=(("https:" == document.location.protocol) ? "https" : "http") + "://piwik.daleycrm.com/";
    _paq.push(['setTrackerUrl', u+'piwik.php']);
    _paq.push(['setSiteId', 4]);
    var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0]; g.type='text/javascript';
    g.defer=true; g.async=true; g.src=u+'piwik.js'; s.parentNode.insertBefore(g,s);
  })();
</script>
<noscript><p><img src="http://piwik.daleycrm.com/piwik.php?idsite=4" style="border:0;" alt="" /></p></noscript>
<!-- End Piwik Code -->
";

This was discovered while "debugging" an issue in WP-Piwik but I confirmed the root cause was Piwik by pasting API calls directly into the browser. I assume this is an unintended change since the new response cannot be unserialized by PHP code.

@claytondaley claytondaley changed the title PHP Formatted Responses PHP Formatted Responses in SitesManager not Serialized Sep 6, 2014
@claytondaley claytondaley changed the title PHP Formatted Responses in SitesManager not Serialized PHP Formatted Responses not Serialized Sep 6, 2014
@claytondaley
Copy link
Contributor Author

I'm getting the same format from SitesManager.getSitesWithAtLeastViewAccess:

array (
  0 => 
  array (
    'idsite' => '4',
    'name' => 'DaleyKlippings',
    'main_url' => 'http://claytondaley.com',
    'ts_created' => '2013-04-05 22:05:58',
    'ecommerce' => '0',
    'sitesearch' => '1',
    'sitesearch_keyword_parameters' => '',
    'sitesearch_category_parameters' => '',
    'timezone' => 'America/New_York',
    'currency' => 'USD',
    'excluded_ips' => '',
    'excluded_parameters' => '',
    'excluded_user_agents' => '',
    'group' => '',
    'type' => 'website',
    'keep_url_fragment' => '0',
  ),
)

@claytondaley
Copy link
Contributor Author

... the root cause is that the new Php Renderer module does not serialize Arrays by default:

https://github.com/piwik/piwik/blob/master/plugins/API/Renderer/Php.php#L50

@claytondaley claytondaley changed the title PHP Formatted Responses not Serialized PHP Arrays not Serialized by Default Sep 7, 2014
claytondaley added a commit to claytondaley/piwik that referenced this issue Sep 7, 2014
@mattab mattab added the Bug For errors / faults / flaws / inconsistencies etc. label Sep 8, 2014
@mattab mattab added this to the Piwik 2.8.0 milestone Sep 8, 2014
@mattab
Copy link
Member

mattab commented Sep 8, 2014

@claytondaley thanks for the report! Do you think it's a regression and that it used to return serialized data in an older Piwik version?

@claytondaley
Copy link
Contributor Author

I honestly can't say. For sure the previous version returned serialized data by default and the contributor who refactored this code made the same change in another part of the new file. @tsteur did the refactor and might know off hand.

@ham1
Copy link
Contributor

ham1 commented Sep 10, 2014

This seems to fix the issue with WP-Piwik however it causes errors on my Visitor Map section inside Piwik (see below). Could this be a problem with the visitor map?

e.g. Warning: Illegal string offset 'metrics' in /var/www/xxx/plugins/UserCountryMap/Controller.php on line 226 

Backtrace -->

#0 Piwik\Error::errorHandler(...) called at [/var/www/xxx/plugins/UserCountryMap/Controller.php:226]
#1 Piwik\Plugins\UserCountryMap\Controller->getMetrics(...) called at [/var/www/xxx/plugins/UserCountryMap/Controller.php:89]
#2 Piwik\Plugins\UserCountryMap\Controller->visitorMap(...) called at [:]
#3 call_user_func_array(...) called at [/var/www/xxx/core/FrontController.php:577]
#4 Piwik\FrontController->doDispatch(...) called at [/var/www/xxx/core/FrontController.php:86]
#5 Piwik\FrontController->dispatch(...) called at [/var/www/xxx/core/dispatch.php:34]
#6 require_once(...) called at [/var/www/xxx/index.php:46]


There is an error. Please report the message (Piwik 2.6.1) and full backtrace in the Piwik forums (please do a Search first as it might have been reported already!).

Warning: Invalid argument supplied for foreach() in /var/www/xxx/plugins/UserCountryMap/Controller.php on line 226 

Backtrace -->

#0 Piwik\Error::errorHandler(...) called at [/var/www/xxx/plugins/UserCountryMap/Controller.php:226]
#1 Piwik\Plugins\UserCountryMap\Controller->getMetrics(...) called at [/var/www/xxx/plugins/UserCountryMap/Controller.php:89]
#2 Piwik\Plugins\UserCountryMap\Controller->visitorMap(...) called at [:]
#3 call_user_func_array(...) called at [/var/www/xxx/core/FrontController.php:577]
#4 Piwik\FrontController->doDispatch(...) called at [/var/www/xxx/core/FrontController.php:86]
#5 Piwik\FrontController->dispatch(...) called at [/var/www/xxx/core/dispatch.php:34]
#6 require_once(...) called at [/var/www/xxx/index.php:46]


There is an error. Please report the message (Piwik 2.6.1) and full backtrace in the Piwik forums (please do a Search first as it might have been reported already!).

Warning: Illegal string offset 'processedMetrics' in /var/www/xxx/plugins/UserCountryMap/Controller.php on line 231 

Backtrace -->

#0 Piwik\Error::errorHandler(...) called at [/var/www/xxx/plugins/UserCountryMap/Controller.php:231]
#1 Piwik\Plugins\UserCountryMap\Controller->getMetrics(...) called at [/var/www/xxx/plugins/UserCountryMap/Controller.php:89]
#2 Piwik\Plugins\UserCountryMap\Controller->visitorMap(...) called at [:]
#3 call_user_func_array(...) called at [/var/www/xxx/core/FrontController.php:577]
#4 Piwik\FrontController->doDispatch(...) called at [/var/www/xxx/core/FrontController.php:86]
#5 Piwik\FrontController->dispatch(...) called at [/var/www/xxx/core/dispatch.php:34]
#6 require_once(...) called at [/var/www/xxx/index.php:46]


There is an error. Please report the message (Piwik 2.6.1) and full backtrace in the Piwik forums (please do a Search first as it might have been reported already!).

Warning: Invalid argument supplied for foreach() in /var/www/xxx/plugins/UserCountryMap/Controller.php on line 231 

Backtrace -->

#0 Piwik\Error::errorHandler(...) called at [/var/www/xxx/plugins/UserCountryMap/Controller.php:231]
#1 Piwik\Plugins\UserCountryMap\Controller->getMetrics(...) called at [/var/www/xxx/plugins/UserCountryMap/Controller.php:89]
#2 Piwik\Plugins\UserCountryMap\Controller->visitorMap(...) called at [:]
#3 call_user_func_array(...) called at [/var/www/xxx/core/FrontController.php:577]
#4 Piwik\FrontController->doDispatch(...) called at [/var/www/xxx/core/FrontController.php:86]
#5 Piwik\FrontController->dispatch(...) called at [/var/www/xxx/core/dispatch.php:34]
#6 require_once(...) called at [/var/www/xxx/index.php:46]
```.

@claytondaley
Copy link
Contributor Author

As noted in the patch, I have fixed UserCountryMap. I also cited the section of the documentation that leads me to believe that the patch (and not the current state) produces the expected behavior.

@ghelleks
Copy link

This is definitely a regression, and has the nasty side-effect of compelling WP-Piwik to create spurious new site records.

@mattab mattab added the Major Indicates the severity or impact or benefit of an issue is much higher than normal but not critical. label Sep 15, 2014
mattab added a commit that referenced this issue Sep 16, 2014
@mattab
Copy link
Member

mattab commented Sep 16, 2014

Thanks for the report. I've added some test for this particular case so it should not regress again. feel free to report any other issue, we can fix them until 2.7.0 release due next week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For errors / faults / flaws / inconsistencies etc. Major Indicates the severity or impact or benefit of an issue is much higher than normal but not critical.
Projects
None yet
Development

No branches or pull requests

4 participants