/** * @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, $isAddressbook = false) { OC_Contacts_App::getAddressbook($aid); // check for user ownership. $addressbook = OC_Contacts_Addressbook::find($aid); if ($addressbook['userid'] != OCP\User::getUser()) { $sharedAddressbook = OCP\Share::getItemSharedWithBySource('addressbook', $aid); if (!$sharedAddressbook || !($sharedAddressbook['permissions'] & OCP\Share::PERMISSION_CREATE)) { return false; } } if (is_array($id)) { foreach ($id as $index => $cardId) { $card = self::find($cardId); if (!$card) { unset($id[$index]); } $oldAddressbook = OC_Contacts_Addressbook::find($card['addressbookid']); if ($oldAddressbook['userid'] != OCP\User::getUser()) { $sharedContact = OCP\Share::getItemSharedWithBySource('contact', $cardId, OCP\Share::FORMAT_NONE, null, true); if (!$sharedContact || !($sharedContact['permissions'] & OCP\Share::PERMISSION_DELETE)) { unset($id[$index]); } } } $id_sql = join(',', array_fill(0, count($id), '?')); $prep = 'UPDATE `*PREFIX*contacts_cards` SET `addressbookid` = ? WHERE `id` IN (' . $id_sql . ')'; try { $stmt = OCP\DB::prepare($prep); //$aid = array($aid); $vals = array_merge((array) $aid, $id); $result = $stmt->execute($vals); } catch (Exception $e) { OCP\Util::writeLog('contacts', __METHOD__ . ', exception: ' . $e->getMessage(), OCP\Util::ERROR); OCP\Util::writeLog('contacts', __METHOD__ . ', ids: ' . join(',', $vals), OCP\Util::DEBUG); OCP\Util::writeLog('contacts', __METHOD__ . ', SQL:' . $prep, OCP\Util::DEBUG); return false; } } else { $stmt = null; if ($isAddressbook) { $stmt = OCP\DB::prepare('UPDATE `*PREFIX*contacts_cards` SET `addressbookid` = ? WHERE `addressbookid` = ?'); } else { $card = self::find($id); if (!$card) { return false; } $oldAddressbook = OC_Contacts_Addressbook::find($card['addressbookid']); if ($oldAddressbook['userid'] != OCP\User::getUser()) { $sharedContact = OCP\Share::getItemSharedWithBySource('contact', $id, OCP\Share::FORMAT_NONE, null, true); if (!$sharedContact || !($sharedContact['permissions'] & OCP\Share::PERMISSION_DELETE)) { return false; } } $stmt = OCP\DB::prepare('UPDATE `*PREFIX*contacts_cards` SET `addressbookid` = ? WHERE `id` = ?'); } try { $result = $stmt->execute(array($aid, $id)); } catch (Exception $e) { OCP\Util::writeLog('contacts', __METHOD__ . ', exception: ' . $e->getMessage(), OCP\Util::DEBUG); OCP\Util::writeLog('contacts', __METHOD__ . ' id: ' . $id, OCP\Util::DEBUG); return false; } } OC_Hook::emit('OC_Contacts_VCard', 'post_moveToAddressbook', array('aid' => $aid, 'id' => $id)); OC_Contacts_Addressbook::touch($aid); return true; }
/** * @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 = OCP\DB::prepare($prep); //$aid = array($aid); $vals = array_merge((array) $aid, $id); $result = $stmt->execute($vals); } catch (Exception $e) { OCP\Util::writeLog('contacts', 'OC_Contacts_VCard::moveToAddressBook:, exception: ' . $e->getMessage(), OCP\Util::DEBUG); OCP\Util::writeLog('contacts', 'OC_Contacts_VCard::moveToAddressBook, ids: ' . join(',', $vals), OCP\Util::DEBUG); OCP\Util::writeLog('contacts', 'SQL:' . $prep, OCP\Util::DEBUG); return false; } } else { try { $stmt = OCP\DB::prepare('UPDATE *PREFIX*contacts_cards SET addressbookid = ? WHERE id = ?'); $result = $stmt->execute(array($aid, $id)); } catch (Exception $e) { OCP\Util::writeLog('contacts', 'OC_Contacts_VCard::moveToAddressBook:, exception: ' . $e->getMessage(), OCP\Util::DEBUG); OCP\Util::writeLog('contacts', 'OC_Contacts_VCard::moveToAddressBook, id: ' . $id, OCP\Util::DEBUG); return false; } } OC_Contacts_Addressbook::touch($aid); return true; }
/** * @brief edits a card with the data provided by sabredav * @param integer $id Addressbook id * @param string $uri the uri of the card * @param string $data vCard file * @return boolean */ public static function editFromDAVData($aid, $uri, $data) { $oldcard = self::findWhereDAVDataIs($aid, $uri); $fn = null; $card = self::parse($data); if (!is_null($card)) { foreach ($card->children as $property) { if ($property->name == 'FN') { $fn = $property->value; } } } $stmt = OC_DB::prepare('UPDATE *PREFIX*contacts_cards SET fullname = ?,carddata = ?, lastmodified = ? WHERE id = ?'); $result = $stmt->execute(array($fn, $data, time(), $oldcard['id'])); OC_Contacts_Addressbook::touch($oldcard['addressbookid']); return true; }