1
0
mirror of https://github.com/owncloudarchive/contacts.git synced 2025-01-18 07:52:21 +01:00

Check if querys succeeded

This commit is contained in:
LEDfan 2014-04-01 21:25:41 +02:00
parent 8362ef1c99
commit ab03ba5ff2

View File

@ -100,7 +100,7 @@ class OwnCloudUsers extends AbstractBackend {
} catch(\Exception $e) {
\OCP\Util::writeLog('contacts', __METHOD__.' exception: '
. $e->getMessage(), \OCP\Util::ERROR);
return $this->addressBooks;
return array();
}
return $this->getAddressBooksForUser();
@ -131,13 +131,13 @@ class OwnCloudUsers extends AbstractBackend {
// TODO create address book if it doesn't exists
$row['permissions'] = \OCP\PERMISSION_ALL;
$row['backend'] = $this->name;
return array($row);
}
} catch(\Exception $e) {
\OCP\Util::writeLog('contacts', __METHOD__.' exception: '
. $e->getMessage(), \OCP\Util::ERROR);
return $this->addressBooks;
return array();
}
return array($row);
}
/**
@ -191,7 +191,7 @@ class OwnCloudUsers extends AbstractBackend {
} catch(\Exception $e) {
\OCP\Util::writeLog('contacts', __METHOD__.' exception: '
. $e->getMessage(), \OCP\Util::ERROR);
return $this->addressBooks;
return array();
}
}
@ -221,7 +221,7 @@ class OwnCloudUsers extends AbstractBackend {
} catch(\Exception $e) {
\OCP\Util::writeLog('contacts', __METHOD__.' exception: '
. $e->getMessage(), \OCP\Util::ERROR);
return $this->addressBooks;
return array();
}
}
@ -239,6 +239,7 @@ class OwnCloudUsers extends AbstractBackend {
*/
private function addContacts($contacts, $addressbookid){
foreach($contacts as $user){
try{
$sql = 'INSERT INTO ' . $this->cardsTableName . ' ('
. 'id, '
. 'owner,'
@ -271,10 +272,21 @@ class OwnCloudUsers extends AbstractBackend {
);
$carddata = $this->generateCardData($contact);
$result = $query->execute(array($user, $this->userid, $addressbookid, \OCP\User::getDisplayName($user), $carddata->serialize(), 'test', time()));
// TODO Check if $result succeeded
}
}
if (\OCP\DB::isError($result)) {
\OCP\Util::writeLog('contacts', __METHOD__. 'DB error: '
. \OC_DB::getErrorMessage($result), \OCP\Util::ERROR);
return false;
} else {
return true;
}
} catch(\Exception $e) {
\OCP\Util::writeLog('contacts', __METHOD__.' exception: '
. $e->getMessage(), \OCP\Util::ERROR);
return false;
}
}
}
/**
* Help function to remove contacts from an addressbook.
* This only happens when an admin remove an ownCloud user
@ -284,11 +296,22 @@ class OwnCloudUsers extends AbstractBackend {
*/
private function removeContacts($contacts, $addressbookid){
foreach($contacts as $user){
try{
$sql = 'DELETE FROM ' . $this->cardsTableName . ' WHERE owner = ? AND id = ?';
$query = \OCP\DB::prepare($sql);
$result = $query->execute(array($this->userid, $user));
// TODO Check if $result succeeded
if (\OCP\DB::isError($result)) {
\OCP\Util::writeLog('contacts', __METHOD__. 'DB error: '
. \OC_DB::getErrorMessage($result), \OCP\Util::ERROR);
return false;
} else {
return true;
}
} catch(\Exception $e) {
\OCP\Util::writeLog('contacts', __METHOD__.' exception: '
. $e->getMessage(), \OCP\Util::ERROR);
return false;
}
}
}
@ -370,6 +393,7 @@ class OwnCloudUsers extends AbstractBackend {
$data = $contact->serialize();
try{
$sql = 'UPDATE ' . $this->cardsTableName
. ' SET '
. '`addressbookid` = ?, '
@ -381,6 +405,17 @@ class OwnCloudUsers extends AbstractBackend {
. 'AND `owner` = ? ';
$query = \OCP\DB::prepare($sql);
$result = $query->execute(array($addressBookId, $contact->FN, $data, time(), $id, $this->userid));
if (\OCP\DB::isError($result)) {
\OCP\Util::writeLog('contacts', __METHOD__. 'DB error: '
. \OC_DB::getErrorMessage($result), \OCP\Util::ERROR);
return false;
} else {
return true;
}
} catch(\Exception $e) {
\OCP\Util::writeLog('contacts', __METHOD__.' exception: '
. $e->getMessage(), \OCP\Util::ERROR);
return false;
}
}
}