Skip to content

Commit

Permalink
Fix errors in bulk api calls
Browse files Browse the repository at this point in the history
  • Loading branch information
frankkessler committed Sep 14, 2016
1 parent 90dcacf commit 195d609
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
16 changes: 9 additions & 7 deletions src/Bulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function runBatch($operation, $objectType, $data, $options = [])
'externalIdFieldName' => null,
'batchSize' => 2000,
'batchTimeout' => 600,
'contentType' => 'json',
'contentType' => 'JSON',
'pollIntervalSeconds' => 5,
];

Expand All @@ -48,6 +48,8 @@ public function runBatch($operation, $objectType, $data, $options = [])
for ($i = 1; $i <= $totalNumberOfBatches; $i++) {
$batches[] = $this->addBatch($job->id, array_splice($data, ($i - 1) * $options['batchSize'], $options['batchSize']));
}
}else{
$this->log('error', 'Job Failed: '.json_encode($job->toArrayAll()));
}

$time = time();
Expand Down Expand Up @@ -115,7 +117,7 @@ public function createJob($operation, $objectType, $externalIdFieldName = null,
'json' => $json_array,
]);

if ($result && isset($result['id']) && $result['id']) {
if ($result && is_array($result)) {
return new BulkJobResponse($result);
}

Expand All @@ -128,7 +130,7 @@ public function jobDetails($jobId)

$result = $this->call_api('get', $url);

if ($result && isset($result['id']) && $result['id']) {
if ($result && is_array($result)) {
return new BulkJobResponse($result);
} else {
//throw exception
Expand All @@ -151,10 +153,10 @@ public function closeJob($jobId)
];

$result = $this->call_api('post', $url, [
'json' => json_encode($json_array),
'json' => $json_array,
]);

if ($result && isset($result['id']) && $result['id']) {
if ($result && is_array($result)) {
return new BulkJobResponse($result);
}

Expand Down Expand Up @@ -183,7 +185,7 @@ public function addBatch($jobId, $data)
],
]);

if ($result) {
if ($result && is_array($result)) {
return new BulkBatchResponse($result);
}

Expand All @@ -202,7 +204,7 @@ public function batchDetails($jobId, $batchId)

$result = $this->call_api('get', $url);

if ($result && isset($result['id']) && $result['id']) {
if ($result && is_array($result)) {
return new BulkBatchResponse($result);
} else {
//throw exception
Expand Down
12 changes: 12 additions & 0 deletions src/Responses/BaseResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,18 @@ public function toArray()
return $return;
}

/**
* Get the instance as an array.
*
* @return array
*/
public function toArrayAll()
{
$return = get_object_vars($this);

return $return;
}

/**
* __toString implementation for this class.
*
Expand Down
4 changes: 3 additions & 1 deletion src/Salesforce.php
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,9 @@ public function call_api($method, $url, $options = [], $debug_info = [])
}
} else {
$full_data = json_decode((string) $response->getBody(), true);
if (count($full_data) > 1) {
if(!is_array($full_data)){
$data = array_merge($data, ['message' => $full_data]);
} elseif (count($full_data) > 1) {
$data = array_merge($data, $full_data);
} else {
$data = array_merge($data, current($full_data));
Expand Down

0 comments on commit 195d609

Please sign in to comment.