Sabre\CardDAV\Backend\PDO::updateCard PHP Method

updateCard() public method

The addressbook id will be passed as the first argument. This is the same id as it is returned from the getAddressBooksForUser method. The cardUri is a base uri, and doesn't include the full path. The cardData argument is the vcard body, and is passed as a string. It is possible to return an ETag from this method. This ETag should match that of the updated resource, and must be enclosed with double quotes (that is: the string itself must contain the actual quotes). You should only return the ETag if you store the carddata as-is. If a subsequent GET request on the same card does not have the same body, byte-by-byte and you did return an ETag here, clients tend to get confused. If you don't return an ETag, you can just return null.
public updateCard ( mixed $addressBookId, string $cardUri, string $cardData ) : string | null
$addressBookId mixed
$cardUri string
$cardData string
return string | null
    function updateCard($addressBookId, $cardUri, $cardData)
    {
        $stmt = $this->pdo->prepare('UPDATE ' . $this->cardsTableName . ' SET carddata = ?, lastmodified = ?, size = ?, etag = ? WHERE uri = ? AND addressbookid =?');
        $etag = md5($cardData);
        $stmt->execute([$cardData, time(), strlen($cardData), $etag, $cardUri, $addressBookId]);
        $this->addChange($addressBookId, $cardUri, 2);
        return '"' . $etag . '"';
    }

Usage Example

Example #1
0
 /**
  * @depends testGetCard
  */
 public function testUpdateCard()
 {
     $result = $this->backend->updateCard(1, 'card1', 'newdata');
     $this->assertEquals('"' . md5('newdata') . '"', $result);
     $result = $this->backend->getCard(1, 'card1');
     $this->assertEquals(1, $result['id']);
     $this->assertEquals('newdata', $result['carddata']);
 }
All Usage Examples Of Sabre\CardDAV\Backend\PDO::updateCard