diff options
-rw-r--r-- | core/API/ResponseBuilder.php | 2 | ||||
-rw-r--r-- | core/Piwik.php | 8 | ||||
-rwxr-xr-x | misc/log-analytics/import_logs.py | 10 | ||||
-rw-r--r-- | plugins/API/Renderer/Json.php | 4 | ||||
-rw-r--r-- | plugins/API/tests/JsonRendererTest.php | 6 |
5 files changed, 11 insertions, 19 deletions
diff --git a/core/API/ResponseBuilder.php b/core/API/ResponseBuilder.php index 8fcf3e8f35..f5af551917 100644 --- a/core/API/ResponseBuilder.php +++ b/core/API/ResponseBuilder.php @@ -221,7 +221,7 @@ class ResponseBuilder $firstKey = key($array); } - $isAssoc = !empty($firstArray) && is_numeric($firstKey) && is_array($firstArray) && !Piwik::isMultiDimensionalArray($array) && count(array_filter(array_keys($firstArray), 'is_string')); + $isAssoc = !empty($firstArray) && is_numeric($firstKey) && is_array($firstArray) && count(array_filter(array_keys($firstArray), 'is_string')); if ($isAssoc) { $hideColumns = Common::getRequestVar('hideColumns', '', 'string', $this->request); diff --git a/core/Piwik.php b/core/Piwik.php index befe249923..fcb49ee82f 100644 --- a/core/Piwik.php +++ b/core/Piwik.php @@ -747,12 +747,8 @@ class Piwik $first = reset($array); foreach ($array as $first) { if (is_array($first)) { - foreach ($first as $value) { - // Yes, this is a multi dim array - if (is_array($value)) { - return true; - } - } + // Yes, this is a multi dim array + return true; } } diff --git a/misc/log-analytics/import_logs.py b/misc/log-analytics/import_logs.py index a52b581c8c..0e11685e6d 100755 --- a/misc/log-analytics/import_logs.py +++ b/misc/log-analytics/import_logs.py @@ -970,17 +970,9 @@ class StaticResolver(object): def __init__(self, site_id): self.site_id = site_id # Go get the main URL - sites = piwik.call_api( + site = piwik.call_api( 'SitesManager.getSiteFromId', idSite=self.site_id ) - try: - site = sites[0] - except (IndexError, KeyError): - logging.debug('response for SitesManager.getSiteFromId: %s', str(sites)) - - fatal_error( - "cannot get the main URL of this site: invalid site ID: %s" % site_id - ) if site.get('result') == 'error': fatal_error( "cannot get the main URL of this site: %s" % site.get('message') diff --git a/plugins/API/Renderer/Json.php b/plugins/API/Renderer/Json.php index 401a4e1a5a..9604859757 100644 --- a/plugins/API/Renderer/Json.php +++ b/plugins/API/Renderer/Json.php @@ -52,7 +52,9 @@ class Json extends ApiRenderer $result = $this->renderDataTable($array); // if $array is a simple associative array, remove the JSON root array that is added by renderDataTable - if (Piwik::isAssociativeArray($array)) { + if (!empty($array) + && Piwik::isAssociativeArray($array) + ) { $result = substr($result, 1, strlen($result) - 2); } diff --git a/plugins/API/tests/JsonRendererTest.php b/plugins/API/tests/JsonRendererTest.php index 366c22efe2..a840305c70 100644 --- a/plugins/API/tests/JsonRendererTest.php +++ b/plugins/API/tests/JsonRendererTest.php @@ -249,8 +249,9 @@ class JsonRendererTest extends \PHPUnit_Framework_TestCase $input = array('nb_visits' => 6, 'nb_random' => 8); $response = $this->jsonBuilder->renderArray($input); + $expected = json_encode($input); - $this->assertEquals('[{"nb_visits":6,"nb_random":8}]', $response); + $this->assertEquals($expected, $response); $this->assertNoJsonError($response); } @@ -262,8 +263,9 @@ class JsonRendererTest extends \PHPUnit_Framework_TestCase ); $response = $this->jsonBuilder->renderArray($input); + $expected = json_encode($input); - $this->assertEquals('[{"nb_visits":6,"nb_random":8},{"nb_visits":3,"nb_random":4}]', $response); + $this->assertEquals($expected, $response); $this->assertNoJsonError($response); } |