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

UpgradePHP json_decode doesn't work for assoc = TRUE #4191

Closed
halfdan opened this issue Oct 3, 2013 · 2 comments
Closed

UpgradePHP json_decode doesn't work for assoc = TRUE #4191

halfdan opened this issue Oct 3, 2013 · 2 comments
Assignees
Labels
Bug For errors / faults / flaws / inconsistencies etc.
Milestone

Comments

@halfdan
Copy link
Member

halfdan commented Oct 3, 2013

The json_decode provided by the upgradephp script doesn't return an associative array for assoc = TRUE and breaks the bulk import.

Two edge cases:

  • php5-json is not installed -> upgradephp will create a json_decode function which will call _json_decode
  • Common::useJsonLibrary() returns TRUE

A fix should be backported to the 1.X branch.

Steps to reproduce the error:

Manually add a "return TRUE;" in the first line of Common::useJsonLibrary().

Use the Python log importer.

Error is:
Cannot use object of type as array in /var/www/domain.org/core/Common.php on line 594

@halfdan
Copy link
Member Author

halfdan commented Oct 3, 2013

Okay - found an easier way to reproduce the problem. It's the specific bulk-tracking format:

data.json:

{"requests":[{"test":"1"},{"best":"2"}], "token_auth": "anonymous"}

test.php:

<?php
require_once 'libs/upgradephp/upgrade.php';

$json = file_get_contents("data.json");
$result = _json_decode($json, TRUE);

var_dump($result);

result

$ php test.php 
array(2) {
  'requests' =>
  array(2) {
    [0] =>
    class stdClass#1 (1) {
      public $test =>
      string(1) "1"
    }
    [1] =>
    class stdClass#2 (1) {
      public $best =>
      string(1) "2"
    }
  }
  'token_auth' =>
  string(9) "anonymous"
}

expected

array(2) {
  'requests' =>
  array(2) {
    [0] =>
    array(1) {
      'test' =>
      string(1) "1"
    }
    [1] =>
    array(1) {
      'best' =>
      string(1) "2"
    }
  }
  'token_auth' =>
  string(9) "anonymous"
}

@anonymous-matomo-user
Copy link

In 40f0a20: Fixes upgradephp json_decode behaviour.

fixes #4191

@halfdan halfdan added this to the 2.0 - Piwik 2.0 milestone Jul 8, 2014
@halfdan halfdan self-assigned this Jul 8, 2014
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.
Projects
None yet
Development

No branches or pull requests

2 participants