mirror of
https://github.com/owncloudarchive/contacts.git
synced 2025-01-30 19:52:17 +01:00
PATCH test WiP
This commit is contained in:
parent
5e38bf07cb
commit
8b6f877fea
@ -290,8 +290,8 @@ $this->create('contacts_contact_delete_property', 'addressbook/{backend}/{addres
|
||||
->requirements(array('backend', 'addressbook', 'contactid'));
|
||||
|
||||
// Save a single property.
|
||||
$this->create('contacts_contact_save_property', 'addressbook/{backend}/{addressbookid}/contact/{contactid}/property/save')
|
||||
->post()
|
||||
$this->create('contacts_contact_save_property', 'addressbook/{backend}/{addressbookid}/contact/{contactid}')
|
||||
->method('PATCH')
|
||||
->action(
|
||||
function($params) {
|
||||
session_write_close();
|
||||
|
@ -381,9 +381,10 @@ OC.Contacts = OC.Contacts || {
|
||||
|
||||
// Keep error messaging at one place to be able to replace it.
|
||||
$(document).bind('status.contacts.error', function(e, data) {
|
||||
console.warn(data.message);
|
||||
var message = data.message || data;
|
||||
console.warn(message);
|
||||
//console.trace();
|
||||
OC.notify({message:data.message});
|
||||
OC.notify({message:message});
|
||||
});
|
||||
|
||||
$(document).bind('status.contact.enabled', function(e, enabled) {
|
||||
|
@ -16,9 +16,18 @@ OC.Contacts = OC.Contacts || {};
|
||||
this.message = jqXHR.statusText;
|
||||
}
|
||||
} else {
|
||||
if(response.status === 'error') {
|
||||
// We need to allow for both the 'old' success/error status property
|
||||
// with the body in the data property, and the newer where we rely
|
||||
// on the status code, and the entire body is used.
|
||||
if(response.status === 'error'|| this.statusCode >= 400) {
|
||||
this.error = true;
|
||||
this.message = response.data.message;
|
||||
if(this.statusCode < 500) {
|
||||
this.message = (response.data && response.data.message)
|
||||
? response.data.message
|
||||
: response;
|
||||
} else {
|
||||
this.message = t('contacts', 'Server error! Please inform system administator');
|
||||
}
|
||||
} else {
|
||||
this.error = false;
|
||||
this.data = response.data || response;
|
||||
@ -42,6 +51,13 @@ OC.Contacts = OC.Contacts || {};
|
||||
this.user = user ? user : OC.currentUser;
|
||||
};
|
||||
|
||||
/**
|
||||
* When the response isn't returned from requestRoute(), you can
|
||||
* wrap it in a JSONResponse so that it's parsable by other objects.
|
||||
*
|
||||
* @param object response The body of the response
|
||||
* @param XMLHTTPRequest http://api.jquery.com/jQuery.ajax/#jqXHR
|
||||
*/
|
||||
Storage.prototype.formatResponse = function(response, jqXHR) {
|
||||
return new JSONResponse(response, jqXHR);
|
||||
};
|
||||
@ -396,9 +412,9 @@ OC.Contacts = OC.Contacts || {};
|
||||
Storage.prototype.saveProperty = function(backend, addressbookid, contactid, params) {
|
||||
return this.requestRoute(
|
||||
'contacts_contact_save_property',
|
||||
'POST',
|
||||
'PATCH',
|
||||
{backend: backend, addressbookid: addressbookid, contactid: contactid},
|
||||
params
|
||||
JSON.stringify(params)
|
||||
);
|
||||
};
|
||||
|
||||
@ -532,7 +548,7 @@ OC.Contacts = OC.Contacts || {};
|
||||
'contacts_setpreference',
|
||||
'POST',
|
||||
{},
|
||||
{key: key, value:value}
|
||||
JSON.stringify({key: key, value:value})
|
||||
);
|
||||
};
|
||||
|
||||
|
@ -128,7 +128,7 @@ class App {
|
||||
if($addressBook->getBackend()->name === $backendName
|
||||
&& $addressBook->getId() === $addressbookid
|
||||
) {
|
||||
\OCP\Util::writeLog('contacts', __METHOD__ . ' returning: '. print_r($addressBook, true), \OCP\Util::DEBUG);
|
||||
//\OCP\Util::writeLog('contacts', __METHOD__ . ' returning: '. print_r($addressBook, true), \OCP\Util::DEBUG);
|
||||
return $addressBook;
|
||||
}
|
||||
}
|
||||
|
@ -14,7 +14,8 @@ use OCA\Contacts\App,
|
||||
OCA\Contacts\ImageResponse,
|
||||
OCA\Contacts\Utils\JSONSerializer,
|
||||
OCA\Contacts\Utils\Properties,
|
||||
OCA\Contacts\Controller;
|
||||
OCA\Contacts\Controller,
|
||||
OCP\AppFramework\Http\Http;
|
||||
|
||||
/**
|
||||
* Controller class For Contacts
|
||||
@ -136,35 +137,33 @@ class ContactController extends Controller {
|
||||
*/
|
||||
public function saveProperty() {
|
||||
$params = $this->request->urlParams;
|
||||
$request = json_decode(file_get_contents('php://input'), true);
|
||||
|
||||
$request = $this->request;
|
||||
//$request = $requestData;
|
||||
$response = new JSONResponse();
|
||||
$response->debug(__METHOD__ .', upload_max_filesize: ' . ini_get('upload_max_filesize'));
|
||||
|
||||
$name = $request->post['name'];
|
||||
$value = $request->post['value'];
|
||||
$checksum = isset($request->post['checksum']) ? $request->post['checksum'] : null;
|
||||
$parameters = isset($request->post['parameters']) ? $request->post['parameters'] : null;
|
||||
|
||||
$name = $request['name'];
|
||||
$value = $request['value'];
|
||||
$checksum = isset($request['checksum']) ? $request['checksum'] : null;
|
||||
$parameters = isset($request['parameters']) ? $request['parameters'] : null;
|
||||
$response->debug(__METHOD__ . ', name: ' . print_r($name, true));
|
||||
$response->debug(__METHOD__ . ', value: ' . print_r($value, true));
|
||||
$response->debug(__METHOD__ . ', checksum: ' . print_r($checksum, true));
|
||||
$response->debug(__METHOD__ . ', parameters: ' . print_r($parameters, true));
|
||||
|
||||
$addressBook = $this->app->getAddressBook($params['backend'], $params['addressbookid']);
|
||||
$response->debug(__METHOD__ . ', addressBook: ' . print_r($addressBook, true));
|
||||
//$response->debug(__METHOD__ . ', addressBook: ' . print_r($addressBook, true));
|
||||
$contact = $addressBook->getChild($params['contactid']);
|
||||
|
||||
if(!$contact) {
|
||||
$response->bailOut(App::$l10n->t('Couldn\'t find contact.'));
|
||||
return $response;
|
||||
return $response->bailOut(App::$l10n->t('Couldn\'t find contact.'));
|
||||
}
|
||||
if(!$name) {
|
||||
$response->bailOut(App::$l10n->t('Property name is not set.'));
|
||||
return $response;
|
||||
return $response->bailOut(App::$l10n->t('Property name is not set.'));
|
||||
}
|
||||
if(!$checksum && in_array($name, Properties::$multi_properties)) {
|
||||
$response->bailOut(App::$l10n->t('Property checksum is not set.'));
|
||||
return $response;
|
||||
return $response->bailOut(App::$l10n->t('Property checksum is not set.'));
|
||||
}
|
||||
if(is_array($value)) {
|
||||
// NOTE: Important, otherwise the compound value will be
|
||||
@ -173,30 +172,26 @@ class ContactController extends Controller {
|
||||
}
|
||||
$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;
|
||||
return $response->bailOut(App::$l10n->t('Property checksum is not set.'));
|
||||
} 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;
|
||||
return $response->bailOut(App::$l10n->t('Information about vCard is incorrect. Please reload the page.'));
|
||||
}
|
||||
} elseif(!in_array($name, Properties::$multi_properties)) {
|
||||
if(!$contact->setPropertyByName($name, $value, $parameters)) {
|
||||
$response->bailOut(App::$l10n->t('Error setting property'));
|
||||
return $response->bailOut(App::$l10n->t('Error setting property'));
|
||||
}
|
||||
}
|
||||
if(!$contact->save()) {
|
||||
$response->bailOut(App::$l10n->t('Error saving property to backend'));
|
||||
return $response;
|
||||
return $response->bailOut(App::$l10n->t('Error saving property to backend'));
|
||||
}
|
||||
$result['lastmodified'] = $contact->lastModified();
|
||||
|
||||
$response->setParams($result);
|
||||
return $response->setData($result);
|
||||
|
||||
return $response;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -116,7 +116,8 @@ class ImportController extends Controller {
|
||||
|
||||
$proxyStatus = \OC_FileProxy::$enabled;
|
||||
\OC_FileProxy::$enabled = false;
|
||||
$content = \OC_Filesystem::file_get_contents($path . '/' . $filename);
|
||||
//$content = \OC_Filesystem::file_get_contents($path . '/' . $filename);
|
||||
$content = file_get_contents('oc://' . $path . '/' . $filename);
|
||||
if($view->file_put_contents('/imports/' . $filename, $content)) {
|
||||
\OC_FileProxy::$enabled = $proxyStatus;
|
||||
$count = substr_count($content, 'BEGIN:');
|
||||
|
@ -27,11 +27,22 @@ class JSONResponse extends OriginalResponse {
|
||||
* @param array|object $params an array or object which will be transformed
|
||||
* to JSON
|
||||
*/
|
||||
public function setParams(array $params){
|
||||
public function setParams(array $params) {
|
||||
$this->setData($params);
|
||||
return $this;
|
||||
$this->data['data'] = $params;
|
||||
$this->data['status'] = 'success';
|
||||
}
|
||||
|
||||
public function setData($data){
|
||||
$this->data = $data;
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setStatus($status) {
|
||||
parent::setStatus($status);
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* in case we want to render an error message, also logs into the owncloud log
|
||||
@ -39,8 +50,9 @@ class JSONResponse extends OriginalResponse {
|
||||
*/
|
||||
public function setErrorMessage($message){
|
||||
$this->error = true;
|
||||
$this->data['data']['message'] = $message;
|
||||
$this->data['status'] = 'error';
|
||||
$this->data = $message;
|
||||
return $this;
|
||||
//$this->data['status'] = 'error';
|
||||
}
|
||||
|
||||
function bailOut($msg, $tracelevel = 1, $debuglevel = \OCP\Util::ERROR) {
|
||||
@ -50,11 +62,12 @@ class JSONResponse extends OriginalResponse {
|
||||
}
|
||||
$this->setErrorMessage($msg);
|
||||
$this->debug($msg, $tracelevel, $debuglevel);
|
||||
return $this;
|
||||
}
|
||||
|
||||
function debug($msg, $tracelevel = 0, $debuglevel = \OCP\Util::DEBUG) {
|
||||
if(!is_numeric($tracelevel)) {
|
||||
return;
|
||||
return $this;
|
||||
}
|
||||
|
||||
if(PHP_VERSION >= "5.4") {
|
||||
@ -69,6 +82,7 @@ class JSONResponse extends OriginalResponse {
|
||||
$call['file'].'. Line: '.$call['line'].': '.$msg,
|
||||
$debuglevel);
|
||||
}
|
||||
return $this;
|
||||
}
|
||||
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user