function updateUDatabase() { $fields = $this->getUFields(); // Can return false if there is an error in the total, subtotal, taxtotal calculations if ($fields) { $format = $this->stat('post_format'); if ($this->owner->GUID) { // uObject already created $uObject = $this->getUObjectByGUID(); if (!$uObject) { // uObject has been deleted return $this->notifyError('U_OBJECT_DELETED'); } } else { list($uField, $ssField) = $this->stat('unique_fields'); if ($uField) { if ($this->owner->{$ssField}) { $uObject = $this->getUObjectByUniqueField(); if ($uObject) { // A uObject with the same ss code already exists so we can not add a new uObject with the same code return $this->notifyError('U_OBJECT_DUPLICATE', $ssField); } } else { // uObject can not be added because the unique field value is missing return $this->notifyError('SS_FIELDS_MISSING', $ssField); } $fields[$uField] = $this->owner->{$ssField}; } $newGUID = $this->owner->GUID = $this->createGUID(); if ($format == 'xml') { $fields['Guid'] = $newGUID; } } $uObject = UnleashedAPI::post($this->stat('u_class'), $this->owner->GUID, $fields, $format); if (!$uObject) { // The POST query failed return $this->notifyError('POST'); } else { if (isset($newGUID)) { // DO NOT USE isChanged('GUID') function to avoid infinite write loop calls $function = is_a($this->owner, 'SiteTree') ? 'doPublish' : 'write'; $this->owner->{$function}(); } } return true; } }