2011-09-17 00:26:57 +02:00
|
|
|
<?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>
|
2011-09-17 00:26:57 +02:00
|
|
|
*
|
|
|
|
* 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;
|
|
|
|
|
2011-09-17 00:26:57 +02:00
|
|
|
/**
|
|
|
|
* This class manages our vCards
|
|
|
|
*/
|
2012-10-25 03:34:12 +02:00
|
|
|
class VCard {
|
2011-09-17 00:26:57 +02:00
|
|
|
|
2012-03-07 16:39:56 +01:00
|
|
|
/**
|
|
|
|
* @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;
|
2012-03-07 16:39:56 +01:00
|
|
|
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)) {
|
2012-08-09 19:54:59 +02:00
|
|
|
$oldcard = self::find($object[0]);
|
|
|
|
if (!$oldcard) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-11-12 00:46:15 +01:00
|
|
|
|
2012-11-22 00:14:03 +01:00
|
|
|
$vcard->{'REV'} = $now->format(\DateTime::W3C);
|
2012-03-07 16:39:56 +01:00
|
|
|
$data = $vcard->serialize();
|
|
|
|
try {
|
|
|
|
$result = $stmt->execute(array($data,time(),$object[0]));
|
2012-10-31 21:37:49 +01:00
|
|
|
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-31 21:37:49 +01:00
|
|
|
}
|
2012-10-25 03:34:12 +02:00
|
|
|
//OCP\Util::writeLog('contacts','OCA\Contacts\VCard::updateDataByID, id: '.$object[0].': '.$object[1],OCP\Util::DEBUG);
|
2013-03-12 22:14:05 +01:00
|
|
|
} 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);
|
2012-03-07 16:39:56 +01:00
|
|
|
}
|
2012-11-12 02:11:19 +01:00
|
|
|
App::updateDBProperties($object[0], $vcard);
|
2012-03-07 16:39:56 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-17 00:26:57 +02:00
|
|
|
}
|