From: Thomas Tanghus Date: Mon, 13 Feb 2012 23:56:50 +0000 (+0100) Subject: Added OC_Contacts_VCard::moveToAddressBook X-Git-Tag: v4.0.0beta~71^2~5^2~4^2~2^2~5 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=3adaacc0ce8cbbcb070cd06fb52d98e4f590751a;p=nextcloud-server.git Added OC_Contacts_VCard::moveToAddressBook --- diff --git a/apps/contacts/lib/vcard.php b/apps/contacts/lib/vcard.php index f9ca427354e..a0eacd0e63b 100644 --- a/apps/contacts/lib/vcard.php +++ b/apps/contacts/lib/vcard.php @@ -384,4 +384,44 @@ class OC_Contacts_VCard{ } return $temp; } + + /** + * @brief Move card(s) to an address book + * @param integer $aid Address book id + * @param $id Array or integer of cards to be moved. + * @return boolean + * + */ + public static function moveToAddressBook($aid, $id){ + OC_Contacts_App::getAddressbook($aid); // check for user ownership. + if(is_array($id)) { + $id_sql = join(',', array_fill(0, count($id), '?')); + $prep = 'UPDATE *PREFIX*contacts_cards SET addressbookid = ? WHERE id IN ('.$id_sql.')'; + try { + $stmt = OC_DB::prepare( $prep ); + //$aid = array($aid); + $vals = array_merge((array)$aid, $id); + $result = $stmt->execute($vals); + } catch(Exception $e) { + OC_Log::write('contacts','OC_Contacts_VCard::moveToAddressBook:, exception: '.$e->getMessage(),OC_Log::DEBUG); + OC_Log::write('contacts','OC_Contacts_VCard::moveToAddressBook, ids: '.join(',', $vals),OC_Log::DEBUG); + OC_Log::write('contacts','SQL:'.$prep,OC_Log::DEBUG); + return false; + } + } else { + try { + $stmt = OC_DB::prepare( 'UPDATE *PREFIX*contacts_cards SET addressbookid = ? WHERE id = ?' ); + $result = $stmt->execute(array($aid, $id)); + } catch(Exception $e) { + OC_Log::write('contacts','OC_Contacts_VCard::moveToAddressBook:, exception: '.$e->getMessage(),OC_Log::DEBUG); + OC_Log::write('contacts','OC_Contacts_VCard::moveToAddressBook, id: '.$id,OC_Log::DEBUG); + OC_Log::write('contacts','SQL:'.$prep,OC_Log::DEBUG); + return false; + } + } + + OC_Contacts_Addressbook::touch($aid); + return true; + } + }