Skip to content

Commit

Permalink
remove populateIds; name flush results sections
Browse files Browse the repository at this point in the history
  • Loading branch information
Vaidas Bagdonas committed Jul 12, 2017
1 parent 94dbe2e commit 8955f0e
Showing 1 changed file with 7 additions and 24 deletions.
31 changes: 7 additions & 24 deletions src/Phpforce/SoapClient/BulkSaver.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,47 +95,30 @@ public function flush()
$results = array();

if (count($this->bulkDeleteRecords) > 0) {
$results[] = $this->flushDeletes();
$results['deleted'] = $this->flushDeletes();
}

foreach ($this->bulkCreateRecords as $type => $objects) {
if (count($objects) > 0) {
$createResults = $this->flushCreates($type);

$this->populateIds($createResults, $objects);

$results[] = $createResults;
$results['created'] = $this->flushCreates($type);
}
}

foreach ($this->bulkUpdateRecords as $type => $objects) {
if (count($objects) > 0) {
$results[] = $this->flushUpdates($type);
$results['updated'] = $this->flushUpdates($type);
}
}

foreach ($this->bulkUpsertRecords as $type => $objects) {
if (count($objects) > 0) {
$results[] = $this->flushUpserts($type);
$results['upserted'] = $this->flushUpserts($type);
}
}

return $results;
}

/**
* @param SaveResult[] $results
* @param $objects
*/
public function populateIds($results, $objects)
{
foreach ($results as $key => $result) {
if($result instanceof SaveResult && method_exists($objects[$key], 'setId')) {
$objects[$key]->setId($result->getId());
}
}
}

/**
* Get bulk save limit
*
Expand Down Expand Up @@ -211,7 +194,7 @@ private function addBulkDeleteRecord($record)
$this->bulkDeleteRecords[] = $record;
}

/**
/**
* Add a record to the update queue
*
* @param sObject $sObject
Expand Down Expand Up @@ -245,7 +228,7 @@ private function addBulkUpsertRecord($sObject, $objectType, $matchField)
$this->bulkUpsertRecords[$objectType][] = $sObject;
}

/**
/**
* Flush creates
*
* @param string $objectType
Expand Down Expand Up @@ -281,7 +264,7 @@ private function flushDeletes()
* Flush updates
*
* @param string $objectType
* @return SaveResult
* @return SaveResult[]
*/
private function flushUpdates($objectType)
{
Expand Down

0 comments on commit 8955f0e

Please sign in to comment.