1
0
mirror of https://github.com/owncloudarchive/contacts.git synced 2024-12-10 21:24:33 +01:00
OwncloudContactsOfficial/lib/vcard.php

85 lines
2.6 KiB
PHP
Raw Normal View History

<?php
/**
* ownCloud - Addressbook
*
* @author Jakob Sack
* @copyright 2011 Jakob Sack mail@jakobsack.de
2013-02-22 23:54:21 +01:00
* @copyright 2012-2013 Thomas Tanghus <thomas@tanghus.net>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
/*
*
* The following SQL statement is just a help for developers and will not be
* executed!
*
* CREATE TABLE contacts_cards (
* id INT(11) UNSIGNED NOT NULL PRIMARY KEY AUTO_INCREMENT,
* addressbookid INT(11) UNSIGNED NOT NULL,
* fullname VARCHAR(255),
* carddata TEXT,
* uri VARCHAR(100),
* lastmodified INT(11) UNSIGNED
* );
*/
2012-10-25 03:34:12 +02:00
namespace OCA\Contacts;
2012-11-22 00:14:03 +01:00
use Sabre\VObject;
/**
* This class manages our vCards
*/
2012-10-25 03:34:12 +02:00
class VCard {
/**
* @brief Mass updates an array of cards
* @param array $objects An array of [id, carddata].
*/
2012-09-07 15:21:03 +02:00
public static function updateDataByID($objects) {
2012-10-25 03:34:12 +02:00
$stmt = \OCP\DB::prepare( 'UPDATE `*PREFIX*contacts_cards` SET `carddata` = ?, `lastmodified` = ? WHERE `id` = ?' );
$now = new \DateTime;
foreach($objects as $object) {
2012-11-22 00:14:03 +01:00
$vcard = null;
try {
$vcard = Sabre\VObject\Reader::read($contact['carddata']);
} catch(\Exception $e) {
\OC_Log::write('contacts', __METHOD__. $e->getMessage(), \OCP\Util::ERROR);
}
2012-07-20 00:17:59 +02:00
if(!is_null($vcard)) {
$oldcard = self::find($object[0]);
if (!$oldcard) {
return false;
}
2012-11-22 00:14:03 +01:00
$vcard->{'REV'} = $now->format(\DateTime::W3C);
$data = $vcard->serialize();
try {
$result = $stmt->execute(array($data,time(),$object[0]));
if (\OC_DB::isError($result)) {
2012-11-15 00:27:09 +01:00
\OC_Log::write('contacts', __METHOD__. 'DB error: ' . \OC_DB::getErrorMessage($result), \OCP\Util::ERROR);
}
2012-10-25 03:34:12 +02:00
//OCP\Util::writeLog('contacts','OCA\Contacts\VCard::updateDataByID, id: '.$object[0].': '.$object[1],OCP\Util::DEBUG);
} catch(\Exception $e) {
2012-10-25 03:34:12 +02:00
\OCP\Util::writeLog('contacts', __METHOD__.', exception: '.$e->getMessage(), \OCP\Util::ERROR);
\OCP\Util::writeLog('contacts', __METHOD__.', id: '.$object[0], \OCP\Util::DEBUG);
}
App::updateDBProperties($object[0], $vcard);
}
}
}
}