mirror of
https://github.com/owncloudarchive/contacts.git
synced 2024-12-01 13:24:10 +01:00
Fix group/category deletion.
This commit is contained in:
parent
57e9e42fb3
commit
73b3c7346d
@ -36,7 +36,7 @@ if(\OCP\App::isEnabled('appframework')) {
|
||||
$api->connectHook('OC_User', 'post_deleteUser', '\OCA\Contacts\Hooks', 'userDeleted');
|
||||
$api->connectHook('OCA\Contacts', 'pre_deleteAddressBook', '\OCA\Contacts\Hooks', 'addressBookDeletion');
|
||||
$api->connectHook('OCA\Contacts', 'pre_deleteContact', '\OCA\Contacts\Hooks', 'contactDeletion');
|
||||
$api->connectHook('OCA\Contacts', 'post_createContact', 'OCA\Contacts\Hooks', 'contactUpdated');
|
||||
$api->connectHook('OCA\Contacts', 'post_createContact', 'OCA\Contacts\Hooks', 'contactAdded');
|
||||
$api->connectHook('OCA\Contacts', 'post_updateContact', '\OCA\Contacts\Hooks', 'contactUpdated');
|
||||
$api->connectHook('OCA\Contacts', 'scanCategories', '\OCA\Contacts\Hooks', 'scanCategories');
|
||||
$api->connectHook('OCA\Contacts', 'indexProperties', '\OCA\Contacts\Hooks', 'indexProperties');
|
||||
|
@ -1703,13 +1703,15 @@ OC.Contacts = OC.Contacts || {};
|
||||
* @param String name The group name
|
||||
*/
|
||||
Contact.prototype.removeFromGroup = function(name) {
|
||||
console.log('removeFromGroup', name);
|
||||
name = name.trim();
|
||||
if(!this.data.CATEGORIES) {
|
||||
console.warn('removeFromGroup. No groups found');
|
||||
return;
|
||||
} else {
|
||||
var found = false;
|
||||
var categories = [];
|
||||
$.each(this.data.CATEGORIES[0].value, function(idx, category) {
|
||||
category = category.trim();
|
||||
if(name.toLowerCase() === category.toLowerCase()) {
|
||||
found = true;
|
||||
} else {
|
||||
@ -1717,10 +1719,10 @@ OC.Contacts = OC.Contacts || {};
|
||||
}
|
||||
});
|
||||
if(!found) {
|
||||
console.log('not found');
|
||||
return;
|
||||
}
|
||||
this.data.CATEGORIES[0].value = categories;
|
||||
//this.data.CATEGORIES[0].value.splice(this.data.CATEGORIES[0].value.indexOf(name), 1);
|
||||
if(this.$listelem) {
|
||||
this.$listelem.find('td.categories')
|
||||
.text(categories.join(' / '));
|
||||
|
@ -28,6 +28,8 @@ OC.Contacts = OC.Contacts || {};
|
||||
}
|
||||
console.log('group click', $(this));
|
||||
if($(event.target).is('.action.delete')) {
|
||||
$('.tipsy').remove();
|
||||
$(this).addClass('loading');
|
||||
event.stopPropagation();
|
||||
event.preventDefault();
|
||||
var id = $(event.target).parents('li').first().data('id');
|
||||
|
@ -86,6 +86,28 @@ class GroupController extends BaseController {
|
||||
}
|
||||
|
||||
$catman = new \OC_VCategories('contact', $this->api->getUserId());
|
||||
$ids = $catman->idsForCategory($name);
|
||||
if($ids !== false) {
|
||||
$app = new App($this->api->getUserId());
|
||||
$backend = $app->getBackend('local');
|
||||
foreach($ids as $id) {
|
||||
$contact = $backend->getContact(null, $id, $noCollection = true);
|
||||
$obj = \Sabre\VObject\Reader::read(
|
||||
$contact['carddata'],
|
||||
\Sabre\VObject\Reader::OPTION_IGNORE_INVALID_LINES
|
||||
);
|
||||
if($obj) {
|
||||
if(!isset($obj->CATEGORIES)) {
|
||||
continue;
|
||||
}
|
||||
if($obj->CATEGORIES->removeGroup($name)) {
|
||||
$backend->updateContact(null, $id, $obj, true);
|
||||
}
|
||||
} else {
|
||||
\OCP\Util::writeLog('contacts', __METHOD__.', could not parse card ' . $id, \OCP\Util::DEBUG);
|
||||
}
|
||||
}
|
||||
}
|
||||
$catman->delete($name);
|
||||
return $response;
|
||||
}
|
||||
@ -115,20 +137,24 @@ class GroupController extends BaseController {
|
||||
return $response;
|
||||
}
|
||||
$ids = $catman->idsForCategory($to);
|
||||
$app = new App($this->api->getUserId());
|
||||
$backend = $app->getBackend('local');
|
||||
foreach($ids as $id) {
|
||||
$contact = $backend->getContact(null, $id, true);
|
||||
$obj = \Sabre\VObject\Reader::read(
|
||||
$contact['carddata'],
|
||||
\Sabre\VObject\Reader::OPTION_IGNORE_INVALID_LINES
|
||||
);
|
||||
if($obj) {
|
||||
if(!isset($obj->CATEGORIES)) {
|
||||
continue;
|
||||
if($ids !== false) {
|
||||
$app = new App($this->api->getUserId());
|
||||
$backend = $app->getBackend('local');
|
||||
foreach($ids as $id) {
|
||||
$contact = $backend->getContact(null, $id, true);
|
||||
$obj = \Sabre\VObject\Reader::read(
|
||||
$contact['carddata'],
|
||||
\Sabre\VObject\Reader::OPTION_IGNORE_INVALID_LINES
|
||||
);
|
||||
if($obj) {
|
||||
if(!isset($obj->CATEGORIES)) {
|
||||
continue;
|
||||
}
|
||||
$obj->CATEGORIES->renameGroup($from, $to);
|
||||
$backend->updateContact(null, $id, $obj, true);
|
||||
} else {
|
||||
\OCP\Util::writeLog('contacts', __METHOD__.', could not parse card ' . $id, \OCP\Util::DEBUG);
|
||||
}
|
||||
$obj->CATEGORIES->renameGroup($from, $to);
|
||||
$backend->updateContact(null, $id, $obj, true);
|
||||
}
|
||||
}
|
||||
return $response;
|
||||
|
@ -100,7 +100,7 @@ class Hooks{
|
||||
//\OCP\Share::unshareAll('contact', $id);
|
||||
}
|
||||
|
||||
public static function contactUpdated($parameters) {
|
||||
public static function contactAdded($parameters) {
|
||||
//\OCP\Util::writeLog('contacts', __METHOD__.' parameters: '.print_r($parameters, true), \OCP\Util::DEBUG);
|
||||
$contact = $parameters['contact'];
|
||||
if(isset($contact->CATEGORIES)) {
|
||||
@ -111,9 +111,15 @@ class Hooks{
|
||||
$catctrl->addToCategory($parameters['id'], $group);
|
||||
}
|
||||
}
|
||||
Utils\Properties::updateIndex($parameters['id'], $parameters['contact']);
|
||||
Utils\Properties::updateIndex($parameters['id'], $contact);
|
||||
}
|
||||
|
||||
public static function contactUpdated($parameters) {
|
||||
//\OCP\Util::writeLog('contacts', __METHOD__.' parameters: '.print_r($parameters, true), \OCP\Util::DEBUG);
|
||||
$contact = $parameters['contact'];
|
||||
Utils\Properties::updateIndex($parameters['id'], $contact);
|
||||
// If updated via CardDAV we don't know if PHOTO has changed
|
||||
if(isset($parameters['carddav']) && $parameters['cardav']
|
||||
if(isset($parameters['carddav']) && $parameters['carddav']
|
||||
&& (isset($contact->PHOTO) || isset($contact->LOGO))) {
|
||||
$contact->cacheThumbnail(null, false, true);
|
||||
}
|
||||
|
@ -39,6 +39,7 @@ class GroupProperty extends CompoundProperty {
|
||||
* @param string $name
|
||||
*/
|
||||
public function addGroup($name) {
|
||||
$name = trim($name);
|
||||
if($this->hasGroup($name)) {
|
||||
return;
|
||||
}
|
||||
@ -51,14 +52,18 @@ class GroupProperty extends CompoundProperty {
|
||||
* Remove an existing group.
|
||||
*
|
||||
* @param string $name
|
||||
* @return bool
|
||||
*/
|
||||
public function removeGroup($name) {
|
||||
$name = trim($name);
|
||||
if(!$this->hasGroup($name)) {
|
||||
return;
|
||||
return false;
|
||||
}
|
||||
$groups = $this->getParts();
|
||||
$groups = array_map('trim', $groups);
|
||||
array_splice($groups, $this->array_searchi($name, $groups), 1);
|
||||
$this->setParts($groups);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -68,7 +73,10 @@ class GroupProperty extends CompoundProperty {
|
||||
* @return bool
|
||||
*/
|
||||
public function hasGroup($name) {
|
||||
return $this->in_arrayi($name, $this->getParts());
|
||||
$name = trim($name);
|
||||
$groups = $this->getParts();
|
||||
$groups = array_map('trim', $groups);
|
||||
return $this->in_arrayi($name, $groups);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -78,10 +86,13 @@ class GroupProperty extends CompoundProperty {
|
||||
* @param string $to
|
||||
*/
|
||||
public function renameGroup($from, $to) {
|
||||
$from = trim($from);
|
||||
$to = trim($to);
|
||||
if(!$this->hasGroup($from)) {
|
||||
return;
|
||||
}
|
||||
$groups = $this->getParts();
|
||||
$groups = array_map('trim', $groups);
|
||||
$groups[$this->array_searchi($from, $groups)] = $to;
|
||||
$this->setParts($groups);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user