This CardDAV backend uses PDO to store addressbooks
Author: Evert Pot (http://evertpot.com/)
Inheritance: extends Sabre\CardDAV\Backend\AbstractBackend
 static function getSQLiteDB()
 {
     $pdo = Backend\PDOSqliteTest::getSQLite();
     // Inserting events through a backend class.
     $backend = new Backend\PDO($pdo);
     $addressbookId = $backend->createAddressBook('principals/user1', 'UUID-123467', array('{DAV:}displayname' => 'user1 addressbook', '{urn:ietf:params:xml:ns:carddav}addressbook-description' => 'AddressBook description'));
     $backend->createAddressBook('principals/user1', 'UUID-123468', array('{DAV:}displayname' => 'user1 addressbook2', '{urn:ietf:params:xml:ns:carddav}addressbook-description' => 'AddressBook description'));
     $backend->createCard($addressbookId, 'UUID-2345', self::getTestCardData());
     return $pdo;
 }
Exemple #2
0
 /**
  * Adds a change record to the addressbookchanges table.
  *
  * @param mixed $addressBookId
  * @param string $objectUri
  * @param int $operation 1 = add, 2 = modify, 3 = delete
  * @return void
  */
 protected function addChange($addressBookId, $objectUri, $operation)
 {
     $stmt = $this->pdo->prepare('INSERT INTO ' . $this->addressBookChangesTableName . ' (uri, synctoken, addressbookid, operation) SELECT ?, synctoken, ?, ? FROM ' . $this->addressBooksTableName . ' WHERE id = ?');
     $stmt->execute([$objectUri, $addressBookId, $operation, $addressBookId]);
     $stmt = $this->pdo->prepare('UPDATE ' . $this->addressBooksTableName . ' SET synctoken = synctoken + 1 WHERE id = ?');
     $stmt->execute([$addressBookId]);
 }
    public function __construct() {

		$oPdo = self::GetPDO();
		$sDbPrefix = '';

		parent::__construct($oPdo, $sDbPrefix.'oc_contacts_addressbooks', $sDbPrefix.'oc_contacts_cards');
    }
Exemple #4
0
 /**
  * Deletes a card
  *
  * @param mixed $addressBookId
  * @param string $cardUri
  * @return bool
  */
 public function deleteCard($addressBookId, $cardUri)
 {
     $stmt = $this->pdo->prepare('DELETE FROM ' . $this->cardsTableName . ' WHERE addressbookid = ? AND uri = ?');
     $stmt->execute(array($addressBookId, $cardUri));
     $stmt2 = $this->pdo->prepare('UPDATE ' . $this->addressBooksTableName . ' SET ctag = ctag + 1 WHERE id = ?');
     $stmt2->execute(array($addressBookId));
     return $stmt->rowCount() === 1;
 }
Exemple #5
0
 /**
  * Sets up the object
  */
 public function __construct()
 {
     parent::__construct(\CApi::GetPDO());
     $sDbPrefix = \CApi::GetSettings()->GetConf('Common/DBPrefix');
     $this->cardsTableName = $sDbPrefix . Constants::T_CARDS;
     $this->addressBooksTableName = $sDbPrefix . Constants::T_ADDRESSBOOKS;
     $this->addressBookChangesTableName = $sDbPrefix . Constants::T_ADDRESSBOOKCHANGES;
 }
Exemple #6
0
	/**
     * Sets up the object
     */
    public function __construct() {

		$oPdo = \CApi::GetPDO();
		$sDbPrefix = \CApi::GetSettings()->GetConf('Common/DBPrefix');

		parent::__construct($oPdo, $sDbPrefix.Constants::T_ADDRESSBOOKS, $sDbPrefix.Constants::T_CARDS);

    }
Exemple #7
0
 static function getSQLiteDB()
 {
     if (file_exists(SABRE_TEMPDIR . '/testdb.sqlite')) {
         unlink(SABRE_TEMPDIR . '/testdb.sqlite');
     }
     $pdo = new PDO('sqlite:' . SABRE_TEMPDIR . '/testdb.sqlite');
     $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
     // Yup this is definitely not 'fool proof', but good enough for now.
     $queries = explode(';', file_get_contents(__DIR__ . '/../../../examples/sql/sqlite.addressbooks.sql'));
     foreach ($queries as $query) {
         $pdo->exec($query);
     }
     // Inserting events through a backend class.
     $backend = new Backend\PDO($pdo);
     $addressbookId = $backend->createAddressBook('principals/user1', 'UUID-123467', array('{DAV:}displayname' => 'user1 addressbook', '{urn:ietf:params:xml:ns:carddav}addressbook-description' => 'AddressBook description'));
     $backend->createAddressBook('principals/user1', 'UUID-123468', array('{DAV:}displayname' => 'user1 addressbook2', '{urn:ietf:params:xml:ns:carddav}addressbook-description' => 'AddressBook description'));
     $backend->createCard($addressbookId, 'UUID-2345', self::getTestCardData());
     return $pdo;
 }
 /**
  * @depends testGetCard
  */
 function testDeleteCard()
 {
     $this->backend->deleteCard(1, 'card1');
     $result = $this->backend->getCard(1, 'card1');
     $this->assertFalse($result);
 }