Skip to content

Commit

Permalink
fixed handling of results from API v2, bug was introduced with versio…
Browse files Browse the repository at this point in the history
…n 2.0.32
  • Loading branch information
malle-pietje committed Nov 24, 2024
1 parent cc074e4 commit 170aa92
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
23 changes: 13 additions & 10 deletions ajax/fetch_collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,22 +154,25 @@
* https://stackoverflow.com/questions/1005857/how-to-call-a-function-from-a-string-stored-in-a-variable
*/
if (count($params) === 0) {
$data_array = $unifi_connection->{$method}();
$request_results = $unifi_connection->{$method}();
} else {
$data_array = $unifi_connection->{$method}(...$params);
$request_results = $unifi_connection->{$method}(...$params);
}

if (!empty($data_array)) {
if (!empty($request_results)) {
/**
* Count the array items and inject $data_array into $results.
*/
$results['count'] = count($data_array);
if (is_array($request_results)) {
$results['count'] = count($request_results);
}

/**
* For results returned from API v2, we need to check for the 'data' key and count items in that array.
* For results returned from API v2, the $request_results are an object, and we need to check for the
* 'data' property and count items in that array.
*/
if(key_exists('data', $data_array)) {
$results['count'] = count($data_array['data']);
if(is_object($request_results) && property_exists($request_results, 'data', )) {
$results['count'] = count($request_results->data);
}

if ($debug) {
Expand All @@ -184,7 +187,7 @@
*/
Kint::$display_called_from = false;
RichRenderer::$folder = false;
$results['data'] = @d($data_array);
$results['data'] = @d($request_results);
} else {
if ($output_method === 'kint_plain') {
/**
Expand All @@ -193,9 +196,9 @@
Kint::$display_called_from = false;
RichRenderer::$folder = false;
TextRenderer::$decorations = false;
$results['data'] = @s($data_array);
$results['data'] = @s($request_results);
} else {
$results['data'] = $data_array;
$results['data'] = $request_results;
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion common.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

use UniFi_API\Client as ApiClient;

const TOOL_VERSION = '2.0.32';
const TOOL_VERSION = '2.0.33';

/**
* Gather some basic information for the About modal.
Expand Down

0 comments on commit 170aa92

Please sign in to comment.