1
0
mirror of https://github.com/owncloudarchive/contacts.git synced 2024-11-29 11:24:11 +01:00

Merge pull request #1001 from gvde/fix-update-index-owner

insert correct userid (aka id of owner) into index properties.
This commit is contained in:
LEDfan 2015-09-09 16:15:36 +02:00
commit 9f9cf6722d
2 changed files with 17 additions and 4 deletions

View File

@ -104,6 +104,10 @@ class Hooks{
public static function contactAdded($parameters) {
\OCP\Util::writeLog('contacts', __METHOD__.' id: '.$parameters['id'], \OCP\Util::DEBUG);
$app = new App();
$backend = $app->getBackend( (isset($parameters['backend'])) ? $parameters['backend'] :'local' );
$ab = $backend->getAddressBook( $parameters['addressBookId'] );
$contact = $parameters['contact'];
if(isset($contact->CATEGORIES)) {
\OCP\Util::writeLog('contacts', __METHOD__.' groups: '.print_r($contact->CATEGORIES->getParts(), true), \OCP\Util::DEBUG);
@ -113,13 +117,17 @@ class Hooks{
$tagMgr->tagAs($parameters['id'], $group);
}
}
Utils\Properties::updateIndex($parameters['id'], $contact);
Utils\Properties::updateIndex($parameters['id'], $contact, $ab['owner']);
}
public static function contactUpdated($parameters) {
//\OCP\Util::writeLog('contacts', __METHOD__.' parameters: '.print_r($parameters, true), \OCP\Util::DEBUG);
$app = new App();
$backend = $app->getBackend( (isset($parameters['backend'])) ? $parameters['backend'] :'local' );
$ab = $backend->getAddressBook( $parameters['addressBookId'] );
$contact = $parameters['contact'];
Utils\Properties::updateIndex($parameters['contactId'], $contact);
Utils\Properties::updateIndex($parameters['contactId'], $contact, $ab['owner']);
// If updated via CardDAV we don't know if PHOTO has changed
if(isset($parameters['carddav']) && $parameters['carddav']) {
if(isset($contact->PHOTO) || isset($contact->LOGO)) {

View File

@ -252,14 +252,19 @@ Class Properties {
*
* @param string $contactId
* @param VCard|null $vCard
* @param string|null $owner
*/
public static function updateIndex($contactId, $vCard = null) {
public static function updateIndex($contactId, $vCard = null, $owner = null) {
self::purgeIndexes(array($contactId));
if(is_null($vCard)) {
return;
}
if(is_null($owner) || empty($owner) ) {
$owner = \OC::$server->getUserSession()->getUser()->getUId();
}
if(!isset(self::$updateindexstmt)) {
self::$updateindexstmt = \OCP\DB::prepare( 'INSERT INTO `' . self::$indexTableName . '` '
. '(`userid`, `contactid`,`name`,`value`,`preferred`) VALUES(?,?,?,?,?)' );
@ -278,7 +283,7 @@ Class Properties {
try {
$result = self::$updateindexstmt->execute(
array(
\OC::$server->getUserSession()->getUser()->getUId(),
$owner,
$contactId,
$property->name,
substr($property->getValue(), 0, 254),