ImportResult
Immutable summary returned by {@see Collection::import()}.
Mirrors the JSON object the server emits on POST /_api/import:
the four counters that decompose the input batch
(created + errors + empty + updated + ignored add up to
the number of source rows), plus an optional details list of
per-row error messages populated when the request was issued with
the details: true option.
Partial failures do NOT raise — the server processes the batch row-by-row and reports the outcome in the counters. Callers can detect failures with hasErrors() and inspect the verbatim messages in $details when relevant.
Example:
$result = $users->import
(
[
[ '_key' => 'alice' , 'name' => 'Alice' ] ,
[ '_key' => 'bob' , 'name' => 'Bob' ] ,
] ,
[ 'waitForSync' => true , 'details' => true ] ,
) ;
echo $result->created ; // 2
if ( $result->hasErrors() )
{
foreach ( $result->details as $message )
{
error_log( $message ) ;
}
}
Tags
Table of Contents
Properties
- $created : int
- $details : array<string|int, mixed>
- $empty : int
- $errors : int
- $ignored : int
- $updated : int
Methods
- __construct() : mixed
- fromBody() : self
- Builds an {@see ImportResult} from a server response body.
- hasErrors() : bool
- Returns true when the server reported at least one failed row.
- toArray() : array<string, int|array<int, string>>
- Returns the result as a plain associative array — useful for logging, JSON serialisation or interop with array-based code paths.
Properties
$created
public
int
$created
= 0
$details
public
array<string|int, mixed>
$details
= []
$empty
public
int
$empty
= 0
$errors
public
int
$errors
= 0
$ignored
public
int
$ignored
= 0
$updated
public
int
$updated
= 0
Methods
__construct()
public
__construct([int $created = 0 ][, int $errors = 0 ][, int $empty = 0 ][, int $updated = 0 ][, int $ignored = 0 ][, array<int, string> $details = [] ]) : mixed
Parameters
- $created : int = 0
-
Number of documents successfully created.
- $errors : int = 0
-
Number of documents that failed to be imported.
- $empty : int = 0
-
Number of empty (or otherwise skipped) source rows.
- $updated : int = 0
-
Number of existing documents updated (only meaningful with
onDuplicate: update|replace). - $ignored : int = 0
-
Number of duplicate documents silently ignored (only meaningful with
onDuplicate: ignore). - $details : array<int, string> = []
-
Per-row error messages, populated when the request used
details: true. Empty list otherwise.
fromBody()
Builds an {@see ImportResult} from a server response body.
public
static fromBody(array<string, mixed> $body) : self
Missing or non-integer counters fall back to 0; a missing or
malformed details field falls back to an empty list. Unknown
extra fields are ignored.
Parameters
- $body : array<string, mixed>
-
Raw decoded JSON object returned by
POST /_api/import.
Return values
selfhasErrors()
Returns true when the server reported at least one failed row.
public
hasErrors() : bool
Return values
booltoArray()
Returns the result as a plain associative array — useful for logging, JSON serialisation or interop with array-based code paths.
public
toArray() : array<string, int|array<int, string>>