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

API Request with idSite=all Throws Exception When There is Only One Site #5734

Closed
anonymous-matomo-user opened this issue Jul 23, 2008 · 3 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.

Comments

@anonymous-matomo-user
Copy link

While testing the API with idSite=all on my development instance I noticed that calling any API function with idSite=all results in an error when there is only one site.

Specifically, I get the following Error:

```
Recoverable Error: Argument 1 passed to Piwik_Date::isEarlier() must be an instance of Piwik_Date, null given, called in /Users/patrick/projects/sandwichboard/stats/modules/Archive/Single.php on line 143 and defined in /Users/patrick/projects/sandwichboard/stats/modules/Date.php on line 107

Backtrace —>

  1. Piwik_ErrorHandler(4096, Argument 1 passed to Piwik_Date::isEarlier() must be an instance of Piwik_Date, null given, called in /Users/patrick/projects/sandwichboard/stats/modules/Archive/Single.php on line 143 and defined, /Users/patrick/projects/sandwichboard/stats/modules/Date.php, 107, Array ()) called at [/Users/patrick/projects/sandwichboard/stats/modules/Date.php:107]
  2. Piwik_Date→isEarlier() called at [/Users/patrick/projects/sandwichboard/stats/modules/Archive/Single.php:143]
  3. Piwik_Archive_Single→prepareArchive() called at [/Users/patrick/projects/sandwichboard/stats/modules/Archive/Array/IndexedByDate.php:20]
  4. Piwik_Archive_Array_IndexedByDate→__construct(Piwik_Site Object ([] => all), day, last30) called at [/Users/patrick/projects/sandwichboard/stats/modules/Archive.php:106]
  5. Piwik_Archive::build(all, day, last30) called at [/Users/patrick/projects/sandwichboard/stats/plugins/VisitsSummary/API.php:49]
  6. Piwik_VisitsSummary_API→getNumeric(all, day, last30, nb_visits) called at [/Users/patrick/projects/sandwichboard/stats/plugins/VisitsSummary/API.php:56]
  7. Piwik_VisitsSummary_API→getVisits(all, day, last30)
  8. call_user_func_array(Array (0 => Piwik_VisitsSummary_API Object (),1 => getVisits), Array (0 => all,1 => day,2 => last30)) called at [/Users/patrick/projects/sandwichboard/stats/modules/API/Proxy.php:462]
  9. Piwik_API_Proxy→__call(getVisits, Array (0 => all,1 => day,2 => last30))
  10. Piwik_API_Proxy→getVisits(all, day, last30)
  11. call_user_func_array(Array (0 => Piwik_API_Proxy Object ([] => Array ([VisitsSummary] => 1),[] => Array ([Piwik_VisitsSummary_API] => Array ([get] => Array ([parameters] => Array ([idSite] => ,[period] => ,[date] => ),[numberOfRequiredParameters] => 3),[getVisits] => Array ([parameters] => Array ([idSite] => ,[period] => ,[date] => ),[numberOfRequiredParameters] => 3),[getUniqueVisitors] => Array ([parameters] => Array ([idSite] => ,[period] => ,[date] => ),[numberOfRequiredParameters] => 3),[getActions] => Array ([parameters] => Array ([idSite] => ,[period] => ,[date] => ),[numberOfRequiredParameters] => 3),[getMaxActions] => Array ([parameters] => Array ([idSite] => ,[period] => ,[date] => ),[numberOfRequiredParameters] => 3),[getSumVisitsLength] => Array ([parameters] => Array ([idSite] => ,[period] => ,[date] => ),[numberOfRequiredParameters] => 3),[getBounceCount] => Array ([parameters] => Array ([idSite] => ,[period] => ,[date] => ),[numberOfRequiredParameters] => 3)))),1 => getVisits), Array (0 => all,1 => day,2 => last30)) called at [/Users/patrick/projects/sandwichboard/stats/modules/API/Request.php:141]
  12. Piwik_API_Request→process() called at [/Users/patrick/projects/sandwichboard/stats/plugins/API/Controller.php:24]
  13. Piwik_API_Controller→index()
  14. call_user_func_array(Array (0 => Piwik_API_Controller Object ([] => API,[] => last30,[] => ),1 => index), Array ()) called at [/Users/patrick/projects/sandwichboard/stats/modules/FrontController.php:143]
  15. Piwik_FrontController→dispatch() called at [/Users/patrick/projects/sandwichboard/stats/index.php:55]

Fatal error: Call to a member function getTimestamp() on a non-object in /Users/patrick/projects/sandwichboard/stats/modules/Date.php on line 109
```

Adding another site makes the issue go away. Removing the site makes the error come back.

I was testing with the following API call, but it occurs for others as well

``

`
http://localhost/index.php?module=API&method=VisitsSummary.getVisits&idSite=all&period=day&date=last30&format=xml

``````

@anonymous-matomo-user
Copy link
Author

Attachment:
[make_id_site_all_work_with_only_one_site.diff](http://issues.piwik.org/attachments/5734/make_id_site_all_work_with_only_one_site.diff)

@anonymous-matomo-user
Copy link
Author

I found the problem and added a patch to fix the issue. Piwik_Archive→build assumed that if there weren’t multiple sites in he $sites array then $idSite was a numeric id of a site.

However, $idSite could also have been “all” and there could only have been one site.

I fixed the issue by replacing references to $idSite with references to the first element of the $sites array.

@anonymous-matomo-user
Copy link
Author

This was fixed with [and 585(584]). That is a better fix than the patch I submitted, because it returns an IndexedBySite Archive Array with one element, which is the behavior you would expect.

This issue was closed.
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

1 participant