Skip to content

Commit

Permalink
Updated direct save method to retrospecively populate GUIDs of child …
Browse files Browse the repository at this point in the history
…objects on save
  • Loading branch information
calcinai committed May 1, 2015
1 parent ef9dc11 commit 4648828
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/XeroPHP/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,14 +242,14 @@ private function savePropertiesDirectly(Object $object){
foreach($object::getProperties() as $property_name => $meta){
if($meta[Object::KEY_SAVE_DIRECTLY] && $object->isDirty($property_name)){
//Then actually save
$property = $object->$property_name;
$property_type = get_class(current($property));
$property_objects = $object->$property_name;
$property_type = get_class(current($property_objects));

$url = new URL($this, sprintf('%s/%s/%s', $object::getResourceURI(), $object->getGUID(), $property_type::getResourceURI()));
$request = new Request($this, $url, Request::METHOD_PUT);

$property_array = array();
foreach($property as $property_object){
foreach($property_objects as $property_object){
$property_array[] = $property_object->toStringArray();
}

Expand All @@ -258,6 +258,14 @@ private function savePropertiesDirectly(Object $object){

$request->send();

$response = $request->getResponse();
foreach($response->getElements() as $element_index => $element) {
if($response->getErrorsForElement($element_index) === null) {
$property_objects[$element_index]->fromStringArray($element);
$property_objects[$element_index]->setClean();
}
}

//Set it clean so the following save might have nothing to do.
$object->setClean($property_name);
}
Expand Down

0 comments on commit 4648828

Please sign in to comment.