mirror of
https://github.com/owncloudarchive/contacts.git
synced 2025-01-30 19:52:17 +01:00
Remember to return the response on error.
This commit is contained in:
parent
54c4c79204
commit
ce4088f7ff
@ -112,6 +112,7 @@ class AddressBookController extends BaseController {
|
||||
$addressBook = $app->getAddressBook($params['backend'], $params['addressbookid']);
|
||||
if(!$addressBook->update($this->request['properties'])) {
|
||||
$response->bailOut(App::$l10n->t('Error updating address book'));
|
||||
return $response;
|
||||
}
|
||||
$response->setParams($addressBook->getMetaData());
|
||||
return $response;
|
||||
@ -135,6 +136,7 @@ class AddressBookController extends BaseController {
|
||||
}
|
||||
if(!$backend->deleteAddressBook($params['addressbookid'])) {
|
||||
$response->bailOut(App::$l10n->t('Error deleting address book'));
|
||||
return $response;
|
||||
}
|
||||
return $response;
|
||||
}
|
||||
@ -154,6 +156,7 @@ class AddressBookController extends BaseController {
|
||||
$id = $addressBook->addChild();
|
||||
if($id === false) {
|
||||
$response->bailOut(App::$l10n->t('Error creating contact.'));
|
||||
return $response;
|
||||
}
|
||||
$contact = $addressBook->getChild($id);
|
||||
$response->setStatus('201');
|
||||
@ -210,11 +213,13 @@ class AddressBookController extends BaseController {
|
||||
$contact = $fromAddressBook->getChild($params['contactid']);
|
||||
if(!$contact) {
|
||||
$response->bailOut(App::$l10n->t('Error retrieving contact.'));
|
||||
return $response;
|
||||
}
|
||||
$contactid = $targetAddressBook->addChild($contact);
|
||||
$contact = $targetAddressBook->getChild($contactid);
|
||||
if(!$contact) {
|
||||
$response->bailOut(App::$l10n->t('Error saving contact.'));
|
||||
return $response;
|
||||
}
|
||||
if(!$fromAddressBook->deleteChild($params['contactid'])) {
|
||||
// Don't bail out because we have to return the contact
|
||||
|
@ -43,6 +43,7 @@ class ContactController extends BaseController {
|
||||
|
||||
if(!$contact) {
|
||||
$response->bailOut(App::$l10n->t('Couldn\'t find contact.'));
|
||||
return $response;
|
||||
}
|
||||
|
||||
$data = JSONSerializer::serializeContact($contact);
|
||||
@ -71,13 +72,16 @@ class ContactController extends BaseController {
|
||||
|
||||
if(!$contact) {
|
||||
$response->bailOut(App::$l10n->t('Couldn\'t find contact.'));
|
||||
return $response;
|
||||
}
|
||||
|
||||
if(!$contact->mergeFromArray($request->params)) {
|
||||
$response->bailOut(App::$l10n->t('Error merging into contact.'));
|
||||
return $response;
|
||||
}
|
||||
if(!$contact->save()) {
|
||||
$response->bailOut(App::$l10n->t('Error saving contact to backend.'));
|
||||
return $response;
|
||||
}
|
||||
$data = JSONSerializer::serializeContact($contact);
|
||||
|
||||
@ -154,24 +158,29 @@ class ContactController extends BaseController {
|
||||
|
||||
if(!$contact) {
|
||||
$response->bailOut(App::$l10n->t('Couldn\'t find contact.'));
|
||||
return $response;
|
||||
}
|
||||
if(!$name) {
|
||||
$response->bailOut(App::$l10n->t('Property name is not set.'));
|
||||
return $response;
|
||||
}
|
||||
if(!$checksum && in_array($name, Properties::$multi_properties)) {
|
||||
$response->bailOut(App::$l10n->t('Property checksum is not set.'));
|
||||
return $response;
|
||||
}
|
||||
if(!is_null($checksum)) {
|
||||
try {
|
||||
$contact->unsetPropertyByChecksum($checksum);
|
||||
} catch(Exception $e) {
|
||||
$response->bailOut(App::$l10n->t('Information about vCard is incorrect. Please reload the page.'));
|
||||
return $response;
|
||||
}
|
||||
} else {
|
||||
unset($contact->{$name});
|
||||
}
|
||||
if(!$contact->save()) {
|
||||
$response->bailOut(App::$l10n->t('Error saving contact to backend.'));
|
||||
return $response;
|
||||
}
|
||||
|
||||
$response->setParams(array(
|
||||
@ -212,12 +221,15 @@ class ContactController extends BaseController {
|
||||
|
||||
if(!$contact) {
|
||||
$response->bailOut(App::$l10n->t('Couldn\'t find contact.'));
|
||||
return $response;
|
||||
}
|
||||
if(!$name) {
|
||||
$response->bailOut(App::$l10n->t('Property name is not set.'));
|
||||
return $response;
|
||||
}
|
||||
if(!$checksum && in_array($name, Properties::$multi_properties)) {
|
||||
$response->bailOut(App::$l10n->t('Property checksum is not set.'));
|
||||
return $response;
|
||||
}
|
||||
if(is_array($value)) {
|
||||
// NOTE: Important, otherwise the compound value will be
|
||||
@ -227,12 +239,14 @@ class ContactController extends BaseController {
|
||||
$result = array('contactid' => $params['contactid']);
|
||||
if(!$checksum && in_array($name, Properties::$multi_properties)) {
|
||||
$response->bailOut(App::$l10n->t('Property checksum is not set.'));
|
||||
return $response;
|
||||
} elseif($checksum && in_array($name, Properties::$multi_properties)) {
|
||||
try {
|
||||
$checksum = $contact->setPropertyByChecksum($checksum, $name, $value, $parameters);
|
||||
$result['checksum'] = $checksum;
|
||||
} catch(Exception $e) {
|
||||
$response->bailOut(App::$l10n->t('Information about vCard is incorrect. Please reload the page.'));
|
||||
return $response;
|
||||
}
|
||||
} elseif(!in_array($name, Properties::$multi_properties)) {
|
||||
if(!$contact->setPropertyByName($name, $value, $parameters)) {
|
||||
@ -241,6 +255,7 @@ class ContactController extends BaseController {
|
||||
}
|
||||
if(!$contact->save()) {
|
||||
$response->bailOut(App::$l10n->t('Error saving property to backend'));
|
||||
return $response;
|
||||
}
|
||||
$result['lastmodified'] = $contact->lastModified();
|
||||
|
||||
|
@ -149,14 +149,17 @@ class GroupController extends BaseController {
|
||||
|
||||
if(is_null($categoryid) || $categoryid === '') {
|
||||
$response->bailOut(App::$l10n->t('Group ID missing from request.'));
|
||||
return $response;
|
||||
}
|
||||
|
||||
if(is_null($categoryid) || $categoryid === '') {
|
||||
$response->bailOut(App::$l10n->t('Group name missing from request.'));
|
||||
return $response;
|
||||
}
|
||||
|
||||
if(is_null($ids)) {
|
||||
$response->bailOut(App::$l10n->t('Contact ID missing from request.'));
|
||||
return $response;
|
||||
}
|
||||
|
||||
$app = new App($this->api->getUserId());
|
||||
@ -197,10 +200,12 @@ class GroupController extends BaseController {
|
||||
|
||||
if(is_null($categoryid) || $categoryid === '') {
|
||||
$response->bailOut(App::$l10n->t('Group ID missing from request.'));
|
||||
return $response;
|
||||
}
|
||||
|
||||
if(is_null($ids)) {
|
||||
$response->bailOut(App::$l10n->t('Contact ID missing from request.'));
|
||||
return $response;
|
||||
}
|
||||
|
||||
$app = new App($this->api->getUserId());
|
||||
|
Loading…
x
Reference in New Issue
Block a user