Skip to content

Commit 4648828

Browse files
committed
Updated direct save method to retrospecively populate GUIDs of child objects on save
1 parent ef9dc11 commit 4648828

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/XeroPHP/Application.php

+11-3
Original file line numberDiff line numberDiff line change
@@ -242,14 +242,14 @@ private function savePropertiesDirectly(Object $object){
242242
foreach($object::getProperties() as $property_name => $meta){
243243
if($meta[Object::KEY_SAVE_DIRECTLY] && $object->isDirty($property_name)){
244244
//Then actually save
245-
$property = $object->$property_name;
246-
$property_type = get_class(current($property));
245+
$property_objects = $object->$property_name;
246+
$property_type = get_class(current($property_objects));
247247

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

251251
$property_array = array();
252-
foreach($property as $property_object){
252+
foreach($property_objects as $property_object){
253253
$property_array[] = $property_object->toStringArray();
254254
}
255255

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

259259
$request->send();
260260

261+
$response = $request->getResponse();
262+
foreach($response->getElements() as $element_index => $element) {
263+
if($response->getErrorsForElement($element_index) === null) {
264+
$property_objects[$element_index]->fromStringArray($element);
265+
$property_objects[$element_index]->setClean();
266+
}
267+
}
268+
261269
//Set it clean so the following save might have nothing to do.
262270
$object->setClean($property_name);
263271
}

0 commit comments

Comments
 (0)