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