From 159a8cdfe97d912d453cc45d926ce6eac2cf55dc Mon Sep 17 00:00:00 2001 From: Gerald Vogt Date: Wed, 22 Jul 2015 11:03:34 +0200 Subject: [PATCH] insert correct userid (aka id of owner) into index properties. --- lib/hooks.php | 12 ++++++++++-- lib/utils/properties.php | 9 +++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/lib/hooks.php b/lib/hooks.php index adf1f168..7ca9b20c 100644 --- a/lib/hooks.php +++ b/lib/hooks.php @@ -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)) { diff --git a/lib/utils/properties.php b/lib/utils/properties.php index d4aa03e2..1c26f031 100644 --- a/lib/utils/properties.php +++ b/lib/utils/properties.php @@ -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),