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

Reporting API with format=php returning unknown objects __PHP_Incomplete_Class __PHP_Incomplete_Class_Name #11108

Closed
c-prompt opened this issue Dec 28, 2016 · 5 comments
Labels
answered For when a question was asked and we referred to forum or answered it. Bug For errors / faults / flaws / inconsistencies etc. duplicate For issues that already existed in our issue tracker and were reported previously.

Comments

@c-prompt
Copy link

According to Serializing objects - objects in sessions:

In order to be able to unserialize() an object, the class of that object needs to be defined. That is, if you have an object of class A and serialize this, you'll get a string that refers to class A and contains all values of variables contained in it. If you want to be able to unserialize this in another file, an object of class A, the definition of class A must be present in that file first.

It appears Piwik 3 Live.getVisitorProfile API command (i.e., index.php?module=API&method=Live.getVisitorProfile) is now returning serialized objects (in this case lastVisits). For example, here is a sample unserialized response:

array(24) {
  ["totalVisits"]=>
  int(1)
  ["totalVisitDuration"]=>
  int(4)
  ["totalActions"]=>
  int(2)
  ["totalEvents"]=>
  int(0)
  ["totalOutlinks"]=>
  int(0)
  ["totalDownloads"]=>
  int(0)
  ["totalSearches"]=>
  int(0)
  ["totalPageViews"]=>
  int(2)
  ["totalPageViewsWithTiming"]=>
  int(2)
  ["totalGoalConversions"]=>
  int(0)
  ["totalConversionsByGoal"]=>
  array(0) {
  }
  ["hasLatLong"]=>
  bool(true)
  ["searches"]=>
  array(0) {
  }
  ["continents"]=>
  array(1) {
    [0]=>
    array(3) {
      ["continent"]=>
      string(3) "amn"
      ["nb_visits"]=>
      int(1)
      ["prettyName"]=>
      string(13) "North America"
    }
  }
  ["countries"]=>
  array(1) {
    [0]=>
    array(5) {
      ["country"]=>
      string(2) "us"
      ["nb_visits"]=>
      int(1)
      ["flag"]=>
      string(39) "plugins/UserCountry/images/flags/us.png"
      ["prettyName"]=>
      string(13) "United States"
      ["cities"]=>
      array(1) {
        [0]=>
        string(7) "*******"
      }
    }
  }
  ["averagePageGenerationTime"]=>
  float(0.7)
  ["totalVisitDurationPretty"]=>
  string(2) "4s"
  ["firstVisit"]=>
  array(5) {
    ["date"]=>
    int(1482949717)
    ["prettyDate"]=>
    string(28) "Wednesday, December 28, 2016"
    ["daysAgo"]=>
    int(0)
    ["referrerType"]=>
    string(6) "direct"
    ["referralSummary"]=>
    string(12) "Direct Entry"
  }
  ["lastVisit"]=>
  array(5) {
    ["date"]=>
    int(1482949717)
    ["prettyDate"]=>
    string(28) "Wednesday, December 28, 2016"
    ["daysAgo"]=>
    int(0)
    ["referrerType"]=>
    string(6) "direct"
    ["referralSummary"]=>
    string(12) "Direct Entry"
  }
  ["visitsAggregated"]=>
  int(1)
  ["nextVisitorId"]=>
  string(16) "b62bae85fc4b8de5"
  ["previousVisitorId"]=>
  bool(false)
  ["lastVisits"]=>
  object(__PHP_Incomplete_Class)#41 (3) {
    ["__PHP_Incomplete_Class_Name"]=>
    string(15) "Piwik\DataTable"
    ["rows":protected]=>
    array(1) {
      [0]=>
      object(__PHP_Incomplete_Class)#414 (1) {
        ["__PHP_Incomplete_Class_Name"]=>
        string(19) "Piwik\DataTable\Row"
      }
    }
    ["summaryRow":protected]=>
    NULL
  }
  ["userId"]=>
  bool(false)
}

As you can see, the problem is a __PHP_Incomplete_Class is returned (with an associated warning in the error log that Class __PHP_Incomplete_Class has no unserializer) because the class isn't defined. Although I can define the class, I'd rather not as the lastVisits object isn't important to the information I was retrieving. Is there any chance the response of this API call will be put back to the way it was (or changed to remove or transmute the object) because, otherwise, anyone who has been using this API call will now have to modify their own code to define the object? Thanks.

@mattab
Copy link
Member

mattab commented Jan 2, 2017

Thanks for the report.

Note: this is not a regression as serialised php data export was already returning DataTable/Row in Piwik 2

@c-prompt
Copy link
Author

c-prompt commented Jan 2, 2017

I'm going to close this and just change my code to retrieve the API call results via JSON instead of PHP (i.e., index.php?module=API&method=Live.getVisitorProfile&format=JSON&token_auth=xxx), thus eliminating the need to unserialize and create the class. However, wanted to leave it out there in case anyone else is looking to understand why they're getting __PHP_Incomplete_Class errors.

@c-prompt c-prompt closed this as completed Jan 2, 2017
@mattab
Copy link
Member

mattab commented Jan 3, 2017

@c-prompt i'd leave it open as it seems to me a bug that we return incomplete classes. We likely won't fix it for now, but worth to keep this open as a bug

@mattab mattab reopened this Jan 3, 2017
@mattab mattab changed the title 3.0.0 API returning serialized objects Reporting API with format=php returning unknown objects __PHP_Incomplete_Class __PHP_Incomplete_Class_Name Jan 3, 2017
@mattab mattab added the Bug For errors / faults / flaws / inconsistencies etc. label Jan 3, 2017
@mattab mattab added this to the Backlog (Help wanted) milestone Jan 3, 2017
@mattab
Copy link
Member

mattab commented Jan 3, 2017

Alternatively we could maybe deprecate the format=php reporting api export...

@mattab
Copy link
Member

mattab commented Jun 19, 2017

This will be "fixed" once we deprecate the PHP format: #8100

@mattab mattab closed this as completed Jun 19, 2017
@mattab mattab added answered For when a question was asked and we referred to forum or answered it. duplicate For issues that already existed in our issue tracker and were reported previously. labels Jun 19, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
answered For when a question was asked and we referred to forum or answered it. Bug For errors / faults / flaws / inconsistencies etc. duplicate For issues that already existed in our issue tracker and were reported previously.
Projects
None yet
Development

No branches or pull requests

2 participants