Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

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

Closed
halfdan opened this Issue · 2 comments

2 participants

@halfdan
Collaborator

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
Collaborator

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-piwik-user

In 40f0a20: Fixes upgradephp json_decode behaviour.

fixes #4191

@halfdan halfdan added this to the 2.0 - Piwik 2.0 milestone
@halfdan halfdan self-assigned this
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.