From f50f82b97423f458c93b63b96dd2b60764c8cfb0 Mon Sep 17 00:00:00 2001 From: "John Molakvoæ (skjnldsv)" Date: Wed, 26 Sep 2018 13:19:25 +0200 Subject: Migration step MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- core/Migrations/Version15000Date20180927120000.php | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 core/Migrations/Version15000Date20180927120000.php diff --git a/core/Migrations/Version15000Date20180927120000.php b/core/Migrations/Version15000Date20180927120000.php new file mode 100644 index 00000000000..d5c4b3364fc --- /dev/null +++ b/core/Migrations/Version15000Date20180927120000.php @@ -0,0 +1,47 @@ + + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program 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 program. If not, see . + * + */ + +namespace OC\Core\Migrations; + +use Doctrine\DBAL\Types\Type; +use OCP\DB\ISchemaWrapper; +use OCP\Migration\SimpleMigrationStep; + +/** + * add column for share notes + * + * Class Version15000Date20180927120000 + */ +class Version15000Date20180927120000 extends SimpleMigrationStep { + public function changeSchema(\OCP\Migration\IOutput $output, \Closure $schemaClosure, array $options) { + + /** @var ISchemaWrapper $schema */ + $schema = $schemaClosure(); + + $table = $schema->getTable('cards'); + $table->addColumn('uid', Type::STRING, [ + 'notnull' => true, + 'length' => 255] + ); + + return $schema; + } +} -- cgit v1.2.3 From 4dee1e06a3ecc0acafd369a1bb557c051cd4e7de Mon Sep 17 00:00:00 2001 From: "John Molakvoæ (skjnldsv)" Date: Fri, 26 Oct 2018 18:13:19 +0200 Subject: Repair Step MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- core/Migrations/Version15000Date20180927120000.php | 6 +- lib/private/Repair/NC15/SetVcardDatabaseUID.php | 127 +++++++++++++++++++++ 2 files changed, 130 insertions(+), 3 deletions(-) create mode 100644 lib/private/Repair/NC15/SetVcardDatabaseUID.php diff --git a/core/Migrations/Version15000Date20180927120000.php b/core/Migrations/Version15000Date20180927120000.php index d5c4b3364fc..5636811baa6 100644 --- a/core/Migrations/Version15000Date20180927120000.php +++ b/core/Migrations/Version15000Date20180927120000.php @@ -38,9 +38,9 @@ class Version15000Date20180927120000 extends SimpleMigrationStep { $table = $schema->getTable('cards'); $table->addColumn('uid', Type::STRING, [ - 'notnull' => true, - 'length' => 255] - ); + 'notnull' => false, + 'length' => 255 + ]); return $schema; } diff --git a/lib/private/Repair/NC15/SetVcardDatabaseUID.php b/lib/private/Repair/NC15/SetVcardDatabaseUID.php new file mode 100644 index 00000000000..2fe50c79471 --- /dev/null +++ b/lib/private/Repair/NC15/SetVcardDatabaseUID.php @@ -0,0 +1,127 @@ + + * + * @author John Molakvoæ + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program 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 program. If not, see . + * + */ + +namespace OC\Repair\NC13; + + +use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\IConfig; +use OCP\IDBConnection; +use OCP\Migration\IOutput; +use OCP\Migration\IRepairStep; + +class SetVcardDatabaseUID implements IRepairStep { + const MAX_ROWS = 1000; + + /** @var IDBConnection */ + private $connection; + private $updateQuery; + + public function __construct(IDBConnection $connection) { + $this->connection = $connection; + } + + + public function getName() { + return 'Extract the vcard uid and store it in the db'; + } + + /** + * @return \Generator + * @suppress SqlInjectionChecker + */ + private function getInvalidEntries() { + $builder = $this->connection->getQueryBuilder(); + + $builder->select('id', 'carddata') + ->from('cards') + ->where($builder->expr()->isNull('uid')) + ->setMaxResults(self::MAX_ROWS); + + do { + $result = $builder->execute(); + $rows = $result->fetchAll(); + foreach ($rows as $row) { + yield $row; + } + $result->closeCursor(); + } while (count($rows) > 0); + } + + private function getUid($carddata) { + preg_match('/^UID:(.*)$/m', $carddata, $matches); + if (count($matches > 1)) { + return $matches[1][0]; + } + return false; + } + + /** + * @param int $id + * @param string $uid + */ + private function update($id, $uid) { + if (!$this->updateQuery) { + $builder = $this->connection->getQueryBuilder(); + + $this->updateQuery = $builder->update('cards') + ->set('uid', $builder->createParameter('uid')) + ->where($builder->expr()->eq('id', $builder->createParameter('id'))); + } + + $this->updateQuery->setParameter('id', $id); + $this->updateQuery->setParameter('uid', $uid); + + $this->updateQuery->execute(); + } + + private function repair() { + $this->connection->beginTransaction(); + $entries = $this->getInvalidEntries(); + $count = 0; + foreach ($entries as $entry) { + $count++; + $uid = $this->getUid($entry['id']); + if ($uid !== false) { + $this->update($entry['id'], $uid); + } + } + $this->connection->commit(); + return $count; + } + + private function shouldRun() { + $versionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0'); + + // was added to 15.0.0.0 + return version_compare($versionFromBeforeUpdate, '15.0.0.0', '<='); + } + + public function run(IOutput $output) { + if ($this->shouldRun()) { + $count = $this->repair(); + + $output->info('Fixed ' . $count . ' vcards'); + } + } +} -- cgit v1.2.3 From 9fbe6774f7e337384f09f40aa90e9b0bc6602a13 Mon Sep 17 00:00:00 2001 From: "John Molakvoæ (skjnldsv)" Date: Fri, 26 Oct 2018 18:27:39 +0200 Subject: Repair registration and autoload bump MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- lib/composer/composer/autoload_classmap.php | 2 ++ lib/composer/composer/autoload_static.php | 2 ++ lib/private/Repair.php | 2 ++ lib/private/Repair/NC15/SetVcardDatabaseUID.php | 40 ++++++++++++++----------- version.php | 2 +- 5 files changed, 29 insertions(+), 19 deletions(-) diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index de149d3a136..e2eb6066342 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -652,6 +652,7 @@ return array( 'OC\\Core\\Migrations\\Version14000Date20180710092004' => $baseDir . '/core/Migrations/Version14000Date20180710092004.php', 'OC\\Core\\Migrations\\Version14000Date20180712153140' => $baseDir . '/core/Migrations/Version14000Date20180712153140.php', 'OC\\Core\\Migrations\\Version15000Date20180926101451' => $baseDir . '/core/Migrations/Version15000Date20180926101451.php', + 'OC\\Core\\Migrations\\Version15000Date20180927120000' => $baseDir . '/core/Migrations/Version15000Date20180927120000.php', 'OC\\DB\\Adapter' => $baseDir . '/lib/private/DB/Adapter.php', 'OC\\DB\\AdapterMySQL' => $baseDir . '/lib/private/DB/AdapterMySQL.php', 'OC\\DB\\AdapterOCI8' => $baseDir . '/lib/private/DB/AdapterOCI8.php', @@ -943,6 +944,7 @@ return array( 'OC\\Repair\\NC13\\RepairInvalidPaths' => $baseDir . '/lib/private/Repair/NC13/RepairInvalidPaths.php', 'OC\\Repair\\NC14\\AddPreviewBackgroundCleanupJob' => $baseDir . '/lib/private/Repair/NC14/AddPreviewBackgroundCleanupJob.php', 'OC\\Repair\\NC14\\RepairPendingCronJobs' => $baseDir . '/lib/private/Repair/NC14/RepairPendingCronJobs.php', + 'OC\\Repair\\NC15\\SetVcardDatabaseUID' => $baseDir . '/lib/private/Repair/NC15/SetVcardDatabaseUID.php', 'OC\\Repair\\OldGroupMembershipShares' => $baseDir . '/lib/private/Repair/OldGroupMembershipShares.php', 'OC\\Repair\\Owncloud\\DropAccountTermsTable' => $baseDir . '/lib/private/Repair/Owncloud/DropAccountTermsTable.php', 'OC\\Repair\\Owncloud\\SaveAccountsTableData' => $baseDir . '/lib/private/Repair/Owncloud/SaveAccountsTableData.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 7bd172c569d..ad282acf8b7 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -682,6 +682,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OC\\Core\\Migrations\\Version14000Date20180710092004' => __DIR__ . '/../../..' . '/core/Migrations/Version14000Date20180710092004.php', 'OC\\Core\\Migrations\\Version14000Date20180712153140' => __DIR__ . '/../../..' . '/core/Migrations/Version14000Date20180712153140.php', 'OC\\Core\\Migrations\\Version15000Date20180926101451' => __DIR__ . '/../../..' . '/core/Migrations/Version15000Date20180926101451.php', + 'OC\\Core\\Migrations\\Version15000Date20180927120000' => __DIR__ . '/../../..' . '/core/Migrations/Version15000Date20180927120000.php', 'OC\\DB\\Adapter' => __DIR__ . '/../../..' . '/lib/private/DB/Adapter.php', 'OC\\DB\\AdapterMySQL' => __DIR__ . '/../../..' . '/lib/private/DB/AdapterMySQL.php', 'OC\\DB\\AdapterOCI8' => __DIR__ . '/../../..' . '/lib/private/DB/AdapterOCI8.php', @@ -973,6 +974,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OC\\Repair\\NC13\\RepairInvalidPaths' => __DIR__ . '/../../..' . '/lib/private/Repair/NC13/RepairInvalidPaths.php', 'OC\\Repair\\NC14\\AddPreviewBackgroundCleanupJob' => __DIR__ . '/../../..' . '/lib/private/Repair/NC14/AddPreviewBackgroundCleanupJob.php', 'OC\\Repair\\NC14\\RepairPendingCronJobs' => __DIR__ . '/../../..' . '/lib/private/Repair/NC14/RepairPendingCronJobs.php', + 'OC\\Repair\\NC15\\SetVcardDatabaseUID' => __DIR__ . '/../../..' . '/lib/private/Repair/NC15/SetVcardDatabaseUID.php', 'OC\\Repair\\OldGroupMembershipShares' => __DIR__ . '/../../..' . '/lib/private/Repair/OldGroupMembershipShares.php', 'OC\\Repair\\Owncloud\\DropAccountTermsTable' => __DIR__ . '/../../..' . '/lib/private/Repair/Owncloud/DropAccountTermsTable.php', 'OC\\Repair\\Owncloud\\SaveAccountsTableData' => __DIR__ . '/../../..' . '/lib/private/Repair/Owncloud/SaveAccountsTableData.php', diff --git a/lib/private/Repair.php b/lib/private/Repair.php index ad9662ca1d7..01724fd6a38 100644 --- a/lib/private/Repair.php +++ b/lib/private/Repair.php @@ -39,6 +39,7 @@ use OC\Repair\NC11\FixMountStorages; use OC\Repair\NC13\AddLogRotateJob; use OC\Repair\NC14\AddPreviewBackgroundCleanupJob; use OC\Repair\NC14\RepairPendingCronJobs; +use OC\Repair\NC15\SetVcardDatabaseUID; use OC\Repair\OldGroupMembershipShares; use OC\Repair\Owncloud\DropAccountTermsTable; use OC\Repair\Owncloud\SaveAccountsTableData; @@ -139,6 +140,7 @@ class Repair implements IOutput{ new AddPreviewBackgroundCleanupJob(\OC::$server->getJobList()), new AddCleanupUpdaterBackupsJob(\OC::$server->getJobList()), new RepairPendingCronJobs(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig()), + new SetVcardDatabaseUID(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig()), ]; } diff --git a/lib/private/Repair/NC15/SetVcardDatabaseUID.php b/lib/private/Repair/NC15/SetVcardDatabaseUID.php index 2fe50c79471..e82a0aad18a 100644 --- a/lib/private/Repair/NC15/SetVcardDatabaseUID.php +++ b/lib/private/Repair/NC15/SetVcardDatabaseUID.php @@ -21,10 +21,8 @@ * */ -namespace OC\Repair\NC13; +namespace OC\Repair\NC15; - -use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IConfig; use OCP\IDBConnection; use OCP\Migration\IOutput; @@ -35,13 +33,17 @@ class SetVcardDatabaseUID implements IRepairStep { /** @var IDBConnection */ private $connection; + + /** @var IConfig */ + private $config; + private $updateQuery; - public function __construct(IDBConnection $connection) { + public function __construct(IDBConnection $connection, IConfig $config) { $this->connection = $connection; + $this->config = $config; } - public function getName() { return 'Extract the vcard uid and store it in the db'; } @@ -54,13 +56,13 @@ class SetVcardDatabaseUID implements IRepairStep { $builder = $this->connection->getQueryBuilder(); $builder->select('id', 'carddata') - ->from('cards') - ->where($builder->expr()->isNull('uid')) - ->setMaxResults(self::MAX_ROWS); + ->from('cards') + ->where($builder->expr()->isNull('uid')) + ->setMaxResults(self::MAX_ROWS); do { $result = $builder->execute(); - $rows = $result->fetchAll(); + $rows = $result->fetchAll(); foreach ($rows as $row) { yield $row; } @@ -70,9 +72,10 @@ class SetVcardDatabaseUID implements IRepairStep { private function getUid($carddata) { preg_match('/^UID:(.*)$/m', $carddata, $matches); - if (count($matches > 1)) { - return $matches[1][0]; + if (count($matches) > 1) { + return $matches[1]; } + return false; } @@ -85,8 +88,8 @@ class SetVcardDatabaseUID implements IRepairStep { $builder = $this->connection->getQueryBuilder(); $this->updateQuery = $builder->update('cards') - ->set('uid', $builder->createParameter('uid')) - ->where($builder->expr()->eq('id', $builder->createParameter('id'))); + ->set('uid', $builder->createParameter('uid')) + ->where($builder->expr()->eq('id', $builder->createParameter('id'))); } $this->updateQuery->setParameter('id', $id); @@ -98,23 +101,24 @@ class SetVcardDatabaseUID implements IRepairStep { private function repair() { $this->connection->beginTransaction(); $entries = $this->getInvalidEntries(); - $count = 0; + $count = 0; foreach ($entries as $entry) { $count++; - $uid = $this->getUid($entry['id']); + $uid = $this->getUid($entry['carddata']); if ($uid !== false) { $this->update($entry['id'], $uid); } } $this->connection->commit(); + return $count; } private function shouldRun() { - $versionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0'); + $versionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0.0'); - // was added to 15.0.0.0 - return version_compare($versionFromBeforeUpdate, '15.0.0.0', '<='); + // was added to 15.0.0.2 + return version_compare($versionFromBeforeUpdate, '15.0.0.2', '<='); } public function run(IOutput $output) { diff --git a/version.php b/version.php index c3740f01fa3..93a8b5fd53e 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ // between betas, final and RCs. This is _not_ the public version number. Reset minor/patchlevel // when updating major/minor version number. -$OC_Version = array(15, 0, 0, 1); +$OC_Version = array(15, 0, 0, 2); // The human readable string $OC_VersionString = '15.0.0 alpha'; -- cgit v1.2.3 From e2ec641c7b4d45c1b6153110af01c2c5a97e4db2 Mon Sep 17 00:00:00 2001 From: "John Molakvoæ (skjnldsv)" Date: Fri, 26 Oct 2018 19:01:38 +0200 Subject: Tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- lib/private/Repair/NC15/SetVcardDatabaseUID.php | 2 +- tests/lib/Repair/SetVcardDatabaseUIDTest.php | 121 ++++++++++++++++++++++++ 2 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 tests/lib/Repair/SetVcardDatabaseUIDTest.php diff --git a/lib/private/Repair/NC15/SetVcardDatabaseUID.php b/lib/private/Repair/NC15/SetVcardDatabaseUID.php index e82a0aad18a..4d2805247bf 100644 --- a/lib/private/Repair/NC15/SetVcardDatabaseUID.php +++ b/lib/private/Repair/NC15/SetVcardDatabaseUID.php @@ -71,7 +71,7 @@ class SetVcardDatabaseUID implements IRepairStep { } private function getUid($carddata) { - preg_match('/^UID:(.*)$/m', $carddata, $matches); + preg_match('/UID:(.*)$/m', $carddata, $matches); if (count($matches) > 1) { return $matches[1]; } diff --git a/tests/lib/Repair/SetVcardDatabaseUIDTest.php b/tests/lib/Repair/SetVcardDatabaseUIDTest.php new file mode 100644 index 00000000000..59a115ba755 --- /dev/null +++ b/tests/lib/Repair/SetVcardDatabaseUIDTest.php @@ -0,0 +1,121 @@ + + * + * @author John Molakvoæ + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program 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 program. If not, see . + * + */ + +namespace Test\Repair; + +use OCP\IConfig; +use OC\Repair\NC15\SetVcardDatabaseUID; +use Test\TestCase; + +/** + * @group DB + */ +class SetVcardDatabaseUIDTest extends TestCase { + + /** @var SetVcardDatabaseUID */ + private $repair; + + /** @var IConfig */ + private $config; + + protected function setUp() { + parent::setUp(); + + $this->config = $this->createMock(IConfig::class); + $this->repair = new SetVcardDatabaseUID(\OC::$server->getDatabaseConnection(), $this->config); + } + + protected function tearDown() { + return parent::tearDown(); + } + + public function dataTestVcards() { + return [ + // classic vcard + ['BEGIN:VCARD + VERSION:3.0 + PRODID:-//Sabre//Sabre VObject 4.1.2//EN + UID:Test + FN:Test + N:Test;;;; + END:VCARD', 'Test'], + + // UID as url + ['BEGIN:VCARD + VERSION:3.0 + PRODID:-//Sabre//Sabre VObject 4.1.2//EN + UID:https://User@old.domain.com/remote.php/carddav/addressbooks/User/contacts/2EAF6525-17ADC861-38D6BB1D.vcf + FN:Test + N:Test;;;; + END:VCARD', 'https://User@old.domain.com/remote.php/carddav/addressbooks/User/contacts/2EAF6525-17ADC861-38D6BB1D.vcf'], + + // No uid + ['BEGIN:VCARD + VERSION:3.0 + PRODID:-//Sabre//Sabre VObject 4.1.2//EN + FN:Test + N:Test;;;; + END:VCARD', false] + ]; + } + + /** + * @dataProvider dataTestVcards + * + * @param string $from + * @param string|boolean $expected + */ + public function testExtractUIDFromVcard($from, $expected) { + $uid = $this->invokePrivate($this->repair, 'getUid', ['carddata' => $from]); + $this->assertEquals($expected, $uid); + } + + public function shouldRunDataProvider() { + return [ + ['11.0.0.0', true], + ['15.0.0.3', false], + ['13.0.5.2', true], + ['12.0.0.0', true], + ['16.0.0.1', false], + ['15.0.0.2', true], + ['13.0.0.0', true], + ['13.0.0.1', true] + ]; + } + + /** + * @dataProvider shouldRunDataProvider + * + * @param string $from + * @param boolean $expected + */ + public function testShouldRun($from, $expected) { + $this->config->expects($this->any()) + ->method('getSystemValue') + ->with('version', '0.0.0.0') + ->willReturn($from); + + $this->assertEquals($expected, $this->invokePrivate($this->repair, 'shouldRun')); + } + +} \ No newline at end of file -- cgit v1.2.3 From 72cbc0c86bf11b1e9dc404c0357c58270717ec95 Mon Sep 17 00:00:00 2001 From: "John Molakvoæ (skjnldsv)" Date: Sat, 27 Oct 2018 11:54:57 +0200 Subject: Properly set uid and create and update MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- apps/dav/lib/CardDAV/CardDavBackend.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/apps/dav/lib/CardDAV/CardDavBackend.php b/apps/dav/lib/CardDAV/CardDavBackend.php index a2d3b03147b..a9d65f2f0f9 100644 --- a/apps/dav/lib/CardDAV/CardDavBackend.php +++ b/apps/dav/lib/CardDAV/CardDavBackend.php @@ -494,7 +494,7 @@ class CardDavBackend implements BackendInterface, SyncSupport { */ function getCards($addressBookId) { $query = $this->db->getQueryBuilder(); - $query->select(['id', 'uri', 'lastmodified', 'etag', 'size', 'carddata']) + $query->select(['id', 'uri', 'lastmodified', 'etag', 'size', 'carddata', 'uid']) ->from('cards') ->where($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId))); @@ -525,7 +525,7 @@ class CardDavBackend implements BackendInterface, SyncSupport { */ function getCard($addressBookId, $cardUri) { $query = $this->db->getQueryBuilder(); - $query->select(['id', 'uri', 'lastmodified', 'etag', 'size', 'carddata']) + $query->select(['id', 'uri', 'lastmodified', 'etag', 'size', 'carddata', 'uid']) ->from('cards') ->where($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId))) ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($cardUri))) @@ -563,7 +563,7 @@ class CardDavBackend implements BackendInterface, SyncSupport { $cards = []; $query = $this->db->getQueryBuilder(); - $query->select(['id', 'uri', 'lastmodified', 'etag', 'size', 'carddata']) + $query->select(['id', 'uri', 'lastmodified', 'etag', 'size', 'carddata', 'uid']) ->from('cards') ->where($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId))) ->andWhere($query->expr()->in('uri', $query->createParameter('uri'))); @@ -609,6 +609,7 @@ class CardDavBackend implements BackendInterface, SyncSupport { */ function createCard($addressBookId, $cardUri, $cardData) { $etag = md5($cardData); + $uid = $this->getUID($cardData); $query = $this->db->getQueryBuilder(); $query->insert('cards') @@ -619,6 +620,7 @@ class CardDavBackend implements BackendInterface, SyncSupport { 'addressbookid' => $query->createNamedParameter($addressBookId), 'size' => $query->createNamedParameter(strlen($cardData)), 'etag' => $query->createNamedParameter($etag), + 'uid' => $query->createNamedParameter($uid), ]) ->execute(); @@ -661,6 +663,7 @@ class CardDavBackend implements BackendInterface, SyncSupport { */ function updateCard($addressBookId, $cardUri, $cardData) { + $uid = $this->getUID($cardData); $etag = md5($cardData); $query = $this->db->getQueryBuilder(); $query->update('cards') @@ -668,6 +671,7 @@ class CardDavBackend implements BackendInterface, SyncSupport { ->set('lastmodified', $query->createNamedParameter(time())) ->set('size', $query->createNamedParameter(strlen($cardData))) ->set('etag', $query->createNamedParameter($etag)) + ->set('uid', $query->createNamedParameter($uid)) ->where($query->expr()->eq('uri', $query->createNamedParameter($cardUri))) ->andWhere($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId))) ->execute(); @@ -1125,4 +1129,10 @@ class CardDavBackend implements BackendInterface, SyncSupport { $addressbookInfo[$displaynameKey] = $principalInformation['{DAV:}displayname']; } } + + private function getUID($cardData) { + $vCard = Reader::read($cardData); + $uid = $vCard->UID->getValue(); + return $uid; + } } -- cgit v1.2.3 From eb5a20bc801e7ea2a6a50dfe33f319a71706d6dd Mon Sep 17 00:00:00 2001 From: "John Molakvoæ (skjnldsv)" Date: Sat, 27 Oct 2018 13:39:10 +0200 Subject: Create cards if none MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- core/Migrations/Version15000Date20180927120000.php | 51 +++++++++++++++++++--- 1 file changed, 46 insertions(+), 5 deletions(-) diff --git a/core/Migrations/Version15000Date20180927120000.php b/core/Migrations/Version15000Date20180927120000.php index 5636811baa6..7d58327475c 100644 --- a/core/Migrations/Version15000Date20180927120000.php +++ b/core/Migrations/Version15000Date20180927120000.php @@ -36,11 +36,52 @@ class Version15000Date20180927120000 extends SimpleMigrationStep { /** @var ISchemaWrapper $schema */ $schema = $schemaClosure(); - $table = $schema->getTable('cards'); - $table->addColumn('uid', Type::STRING, [ - 'notnull' => false, - 'length' => 255 - ]); + if ($schema->hasTable('cards')) { + $table = $schema->getTable('cards'); + $table->addColumn('uid', Type::STRING, [ + 'notnull' => false, + 'length' => 255 + ]); + } else { + $table = $schema->createTable('cards'); + $table->addColumn('id', 'bigint', [ + 'autoincrement' => true, + 'notnull' => true, + 'length' => 11, + 'unsigned' => true, + ]); + $table->addColumn('addressbookid', 'integer', [ + 'notnull' => true, + 'default' => 0, + ]); + $table->addColumn('carddata', 'blob', [ + 'notnull' => false, + ]); + $table->addColumn('uri', 'string', [ + 'notnull' => false, + 'length' => 255, + ]); + $table->addColumn('lastmodified', 'bigint', [ + 'notnull' => false, + 'length' => 11, + 'unsigned' => true, + ]); + $table->addColumn('etag', 'string', [ + 'notnull' => false, + 'length' => 32, + ]); + $table->addColumn('size', 'bigint', [ + 'notnull' => true, + 'length' => 11, + 'unsigned' => true, + ]); + $table->addColumn('uid', Type::STRING, [ + 'notnull' => false, + 'length' => 255 + ]); + $table->setPrimaryKey(['id']); + $table->addIndex(['addressbookid']); + } return $schema; } -- cgit v1.2.3 From 0a238983c64524b91c7cf700abdf948d764ed739 Mon Sep 17 00:00:00 2001 From: "John Molakvoæ (skjnldsv)" Date: Sat, 27 Oct 2018 13:41:00 +0200 Subject: fixup! Create cards if none MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- core/Migrations/Version15000Date20180927120000.php | 1 - 1 file changed, 1 deletion(-) diff --git a/core/Migrations/Version15000Date20180927120000.php b/core/Migrations/Version15000Date20180927120000.php index 7d58327475c..d38914314ff 100644 --- a/core/Migrations/Version15000Date20180927120000.php +++ b/core/Migrations/Version15000Date20180927120000.php @@ -80,7 +80,6 @@ class Version15000Date20180927120000 extends SimpleMigrationStep { 'length' => 255 ]); $table->setPrimaryKey(['id']); - $table->addIndex(['addressbookid']); } return $schema; -- cgit v1.2.3 From 161608b1f11f0b1c30b17bf81fa1fd205abd6ca6 Mon Sep 17 00:00:00 2001 From: "John Molakvoæ (skjnldsv)" Date: Tue, 30 Oct 2018 13:03:49 +0100 Subject: move migration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- apps/dav/composer/composer/autoload_classmap.php | 1 + apps/dav/composer/composer/autoload_static.php | 1 + .../Migration/Version1008Date20181030113700.php | 52 +++++++++++++ core/Migrations/Version15000Date20180927120000.php | 87 ---------------------- lib/composer/composer/autoload_classmap.php | 1 - lib/composer/composer/autoload_static.php | 1 - 6 files changed, 54 insertions(+), 89 deletions(-) create mode 100644 apps/dav/lib/Migration/Version1008Date20181030113700.php delete mode 100644 core/Migrations/Version15000Date20180927120000.php diff --git a/apps/dav/composer/composer/autoload_classmap.php b/apps/dav/composer/composer/autoload_classmap.php index fe7557f7e08..c9680651ff9 100644 --- a/apps/dav/composer/composer/autoload_classmap.php +++ b/apps/dav/composer/composer/autoload_classmap.php @@ -156,6 +156,7 @@ return array( 'OCA\\DAV\\Migration\\Version1005Date20180530124431' => $baseDir . '/../lib/Migration/Version1005Date20180530124431.php', 'OCA\\DAV\\Migration\\Version1006Date20180619154313' => $baseDir . '/../lib/Migration/Version1006Date20180619154313.php', 'OCA\\DAV\\Migration\\Version1007Date20181007225117' => $baseDir . '/../lib/Migration/Version1007Date20181007225117.php', + 'OCA\\DAV\\Migration\\Version1008Date20181030113700' => $baseDir . '/../lib/Migration/Version1008Date20181030113700.php', 'OCA\\DAV\\RootCollection' => $baseDir . '/../lib/RootCollection.php', 'OCA\\DAV\\Server' => $baseDir . '/../lib/Server.php', 'OCA\\DAV\\Settings\\CalDAVSettings' => $baseDir . '/../lib/Settings/CalDAVSettings.php', diff --git a/apps/dav/composer/composer/autoload_static.php b/apps/dav/composer/composer/autoload_static.php index 1668f1270f5..71879abc0a5 100644 --- a/apps/dav/composer/composer/autoload_static.php +++ b/apps/dav/composer/composer/autoload_static.php @@ -171,6 +171,7 @@ class ComposerStaticInitDAV 'OCA\\DAV\\Migration\\Version1005Date20180530124431' => __DIR__ . '/..' . '/../lib/Migration/Version1005Date20180530124431.php', 'OCA\\DAV\\Migration\\Version1006Date20180619154313' => __DIR__ . '/..' . '/../lib/Migration/Version1006Date20180619154313.php', 'OCA\\DAV\\Migration\\Version1007Date20181007225117' => __DIR__ . '/..' . '/../lib/Migration/Version1007Date20181007225117.php', + 'OCA\\DAV\\Migration\\Version1008Date20181030113700' => __DIR__ . '/..' . '/../lib/Migration/Version1008Date20181030113700.php', 'OCA\\DAV\\RootCollection' => __DIR__ . '/..' . '/../lib/RootCollection.php', 'OCA\\DAV\\Server' => __DIR__ . '/..' . '/../lib/Server.php', 'OCA\\DAV\\Settings\\CalDAVSettings' => __DIR__ . '/..' . '/../lib/Settings/CalDAVSettings.php', diff --git a/apps/dav/lib/Migration/Version1008Date20181030113700.php b/apps/dav/lib/Migration/Version1008Date20181030113700.php new file mode 100644 index 00000000000..1cc6223a9e9 --- /dev/null +++ b/apps/dav/lib/Migration/Version1008Date20181030113700.php @@ -0,0 +1,52 @@ + + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program 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 program. If not, see . + * + */ + +namespace OCA\DAV\Migration; + +use Closure; + +use Doctrine\DBAL\Types\Type; +use OCP\DB\ISchemaWrapper; +use OCP\Migration\SimpleMigrationStep; +use OCP\Migration\IOutput; + +/** + * add column for share notes + * + * Class Version15000Date20180927120000 + */ +class Version1008Date20181030113700 extends SimpleMigrationStep { + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { + + /** @var ISchemaWrapper $schema */ + $schema = $schemaClosure(); + + $table = $schema->getTable('cards'); + $table->addColumn('uid', Type::STRING, [ + 'notnull' => false, + 'length' => 255 + ]); + + return $schema; + } +} diff --git a/core/Migrations/Version15000Date20180927120000.php b/core/Migrations/Version15000Date20180927120000.php deleted file mode 100644 index d38914314ff..00000000000 --- a/core/Migrations/Version15000Date20180927120000.php +++ /dev/null @@ -1,87 +0,0 @@ - - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program 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 program. If not, see . - * - */ - -namespace OC\Core\Migrations; - -use Doctrine\DBAL\Types\Type; -use OCP\DB\ISchemaWrapper; -use OCP\Migration\SimpleMigrationStep; - -/** - * add column for share notes - * - * Class Version15000Date20180927120000 - */ -class Version15000Date20180927120000 extends SimpleMigrationStep { - public function changeSchema(\OCP\Migration\IOutput $output, \Closure $schemaClosure, array $options) { - - /** @var ISchemaWrapper $schema */ - $schema = $schemaClosure(); - - if ($schema->hasTable('cards')) { - $table = $schema->getTable('cards'); - $table->addColumn('uid', Type::STRING, [ - 'notnull' => false, - 'length' => 255 - ]); - } else { - $table = $schema->createTable('cards'); - $table->addColumn('id', 'bigint', [ - 'autoincrement' => true, - 'notnull' => true, - 'length' => 11, - 'unsigned' => true, - ]); - $table->addColumn('addressbookid', 'integer', [ - 'notnull' => true, - 'default' => 0, - ]); - $table->addColumn('carddata', 'blob', [ - 'notnull' => false, - ]); - $table->addColumn('uri', 'string', [ - 'notnull' => false, - 'length' => 255, - ]); - $table->addColumn('lastmodified', 'bigint', [ - 'notnull' => false, - 'length' => 11, - 'unsigned' => true, - ]); - $table->addColumn('etag', 'string', [ - 'notnull' => false, - 'length' => 32, - ]); - $table->addColumn('size', 'bigint', [ - 'notnull' => true, - 'length' => 11, - 'unsigned' => true, - ]); - $table->addColumn('uid', Type::STRING, [ - 'notnull' => false, - 'length' => 255 - ]); - $table->setPrimaryKey(['id']); - } - - return $schema; - } -} diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index e2eb6066342..e880d5ede49 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -652,7 +652,6 @@ return array( 'OC\\Core\\Migrations\\Version14000Date20180710092004' => $baseDir . '/core/Migrations/Version14000Date20180710092004.php', 'OC\\Core\\Migrations\\Version14000Date20180712153140' => $baseDir . '/core/Migrations/Version14000Date20180712153140.php', 'OC\\Core\\Migrations\\Version15000Date20180926101451' => $baseDir . '/core/Migrations/Version15000Date20180926101451.php', - 'OC\\Core\\Migrations\\Version15000Date20180927120000' => $baseDir . '/core/Migrations/Version15000Date20180927120000.php', 'OC\\DB\\Adapter' => $baseDir . '/lib/private/DB/Adapter.php', 'OC\\DB\\AdapterMySQL' => $baseDir . '/lib/private/DB/AdapterMySQL.php', 'OC\\DB\\AdapterOCI8' => $baseDir . '/lib/private/DB/AdapterOCI8.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index ad282acf8b7..c5f6211b69d 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -682,7 +682,6 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OC\\Core\\Migrations\\Version14000Date20180710092004' => __DIR__ . '/../../..' . '/core/Migrations/Version14000Date20180710092004.php', 'OC\\Core\\Migrations\\Version14000Date20180712153140' => __DIR__ . '/../../..' . '/core/Migrations/Version14000Date20180712153140.php', 'OC\\Core\\Migrations\\Version15000Date20180926101451' => __DIR__ . '/../../..' . '/core/Migrations/Version15000Date20180926101451.php', - 'OC\\Core\\Migrations\\Version15000Date20180927120000' => __DIR__ . '/../../..' . '/core/Migrations/Version15000Date20180927120000.php', 'OC\\DB\\Adapter' => __DIR__ . '/../../..' . '/lib/private/DB/Adapter.php', 'OC\\DB\\AdapterMySQL' => __DIR__ . '/../../..' . '/lib/private/DB/AdapterMySQL.php', 'OC\\DB\\AdapterOCI8' => __DIR__ . '/../../..' . '/lib/private/DB/AdapterOCI8.php', -- cgit v1.2.3 From 353f5bd46952d25abadc329092c353e64758fab5 Mon Sep 17 00:00:00 2001 From: "John Molakvoæ (skjnldsv)" Date: Tue, 30 Oct 2018 14:03:41 +0100 Subject: fixup! move migration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- apps/dav/lib/CardDAV/CardDavBackend.php | 15 +++++++++++-- lib/private/Repair/NC15/SetVcardDatabaseUID.php | 30 +++++++++++++++---------- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/apps/dav/lib/CardDAV/CardDavBackend.php b/apps/dav/lib/CardDAV/CardDavBackend.php index a9d65f2f0f9..8ef0e0baf56 100644 --- a/apps/dav/lib/CardDAV/CardDavBackend.php +++ b/apps/dav/lib/CardDAV/CardDavBackend.php @@ -1130,9 +1130,20 @@ class CardDavBackend implements BackendInterface, SyncSupport { } } + /** + * Extract UID from vcard + * + * @param string $cardData the vcard raw data + * @return string the uid or empty if none + * @throws BadRequest + */ private function getUID($cardData) { $vCard = Reader::read($cardData); - $uid = $vCard->UID->getValue(); - return $uid; + if ($vCard->UID) { + $uid = $vCard->UID->getValue(); + return $uid; + } + // should already be handled, but just in case + throw new BadRequest('vCards on CardDAV servers MUST have a UID property'); } } diff --git a/lib/private/Repair/NC15/SetVcardDatabaseUID.php b/lib/private/Repair/NC15/SetVcardDatabaseUID.php index 4d2805247bf..1b188e1d969 100644 --- a/lib/private/Repair/NC15/SetVcardDatabaseUID.php +++ b/lib/private/Repair/NC15/SetVcardDatabaseUID.php @@ -27,6 +27,7 @@ use OCP\IConfig; use OCP\IDBConnection; use OCP\Migration\IOutput; use OCP\Migration\IRepairStep; +use Sabre\VObject\Reader; class SetVcardDatabaseUID implements IRepairStep { const MAX_ROWS = 1000; @@ -70,20 +71,27 @@ class SetVcardDatabaseUID implements IRepairStep { } while (count($rows) > 0); } - private function getUid($carddata) { - preg_match('/UID:(.*)$/m', $carddata, $matches); - if (count($matches) > 1) { - return $matches[1]; + /** + * Extract UID from vcard + * + * @param string $cardData the vcard raw data + * @return string the uid or empty if none + */ + private function getUID(string $cardData): string { + $vCard = Reader::read($cardData); + if ($vCard->UID) { + $uid = $vCard->UID->getValue(); + return $uid; } - return false; + return ''; } /** * @param int $id * @param string $uid */ - private function update($id, $uid) { + private function update(int $id, string $uid) { if (!$this->updateQuery) { $builder = $this->connection->getQueryBuilder(); @@ -98,16 +106,14 @@ class SetVcardDatabaseUID implements IRepairStep { $this->updateQuery->execute(); } - private function repair() { + private function repair(): int { $this->connection->beginTransaction(); $entries = $this->getInvalidEntries(); $count = 0; foreach ($entries as $entry) { $count++; - $uid = $this->getUid($entry['carddata']); - if ($uid !== false) { - $this->update($entry['id'], $uid); - } + $uid = $this->getUID($entry['carddata']); + $this->update($entry['id'], $uid); } $this->connection->commit(); @@ -118,7 +124,7 @@ class SetVcardDatabaseUID implements IRepairStep { $versionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0.0'); // was added to 15.0.0.2 - return version_compare($versionFromBeforeUpdate, '15.0.0.2', '<='); + return version_compare($versionFromBeforeUpdate, '15.0.0.3', '<='); } public function run(IOutput $output) { -- cgit v1.2.3 From 29b72fd1f7031d6139ab340420d3fd9e29b5073c Mon Sep 17 00:00:00 2001 From: "John Molakvoæ (skjnldsv)" Date: Tue, 30 Oct 2018 14:05:34 +0100 Subject: fixup! move migration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- lib/private/Repair/NC15/SetVcardDatabaseUID.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/private/Repair/NC15/SetVcardDatabaseUID.php b/lib/private/Repair/NC15/SetVcardDatabaseUID.php index 1b188e1d969..ccf6c47cbc8 100644 --- a/lib/private/Repair/NC15/SetVcardDatabaseUID.php +++ b/lib/private/Repair/NC15/SetVcardDatabaseUID.php @@ -124,7 +124,7 @@ class SetVcardDatabaseUID implements IRepairStep { $versionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0.0'); // was added to 15.0.0.2 - return version_compare($versionFromBeforeUpdate, '15.0.0.3', '<='); + return version_compare($versionFromBeforeUpdate, '15.0.0.2', '<='); } public function run(IOutput $output) { -- cgit v1.2.3 From 5a1d3533721672e356ff9de47099171301fbb4b6 Mon Sep 17 00:00:00 2001 From: "John Molakvoæ (skjnldsv)" Date: Wed, 26 Sep 2018 13:19:25 +0200 Subject: Migration step MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- core/Migrations/Version15000Date20180927120000.php | 47 ++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 core/Migrations/Version15000Date20180927120000.php diff --git a/core/Migrations/Version15000Date20180927120000.php b/core/Migrations/Version15000Date20180927120000.php new file mode 100644 index 00000000000..d5c4b3364fc --- /dev/null +++ b/core/Migrations/Version15000Date20180927120000.php @@ -0,0 +1,47 @@ + + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program 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 program. If not, see . + * + */ + +namespace OC\Core\Migrations; + +use Doctrine\DBAL\Types\Type; +use OCP\DB\ISchemaWrapper; +use OCP\Migration\SimpleMigrationStep; + +/** + * add column for share notes + * + * Class Version15000Date20180927120000 + */ +class Version15000Date20180927120000 extends SimpleMigrationStep { + public function changeSchema(\OCP\Migration\IOutput $output, \Closure $schemaClosure, array $options) { + + /** @var ISchemaWrapper $schema */ + $schema = $schemaClosure(); + + $table = $schema->getTable('cards'); + $table->addColumn('uid', Type::STRING, [ + 'notnull' => true, + 'length' => 255] + ); + + return $schema; + } +} -- cgit v1.2.3 From 938c63e3a21d2d5cdbbd7ce08354407d8cf43902 Mon Sep 17 00:00:00 2001 From: "John Molakvoæ (skjnldsv)" Date: Fri, 26 Oct 2018 18:13:19 +0200 Subject: Repair Step MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- core/Migrations/Version15000Date20180927120000.php | 6 +- lib/private/Repair/NC15/SetVcardDatabaseUID.php | 127 +++++++++++++++++++++ 2 files changed, 130 insertions(+), 3 deletions(-) create mode 100644 lib/private/Repair/NC15/SetVcardDatabaseUID.php diff --git a/core/Migrations/Version15000Date20180927120000.php b/core/Migrations/Version15000Date20180927120000.php index d5c4b3364fc..5636811baa6 100644 --- a/core/Migrations/Version15000Date20180927120000.php +++ b/core/Migrations/Version15000Date20180927120000.php @@ -38,9 +38,9 @@ class Version15000Date20180927120000 extends SimpleMigrationStep { $table = $schema->getTable('cards'); $table->addColumn('uid', Type::STRING, [ - 'notnull' => true, - 'length' => 255] - ); + 'notnull' => false, + 'length' => 255 + ]); return $schema; } diff --git a/lib/private/Repair/NC15/SetVcardDatabaseUID.php b/lib/private/Repair/NC15/SetVcardDatabaseUID.php new file mode 100644 index 00000000000..2fe50c79471 --- /dev/null +++ b/lib/private/Repair/NC15/SetVcardDatabaseUID.php @@ -0,0 +1,127 @@ + + * + * @author John Molakvoæ + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program 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 program. If not, see . + * + */ + +namespace OC\Repair\NC13; + + +use OCP\DB\QueryBuilder\IQueryBuilder; +use OCP\IConfig; +use OCP\IDBConnection; +use OCP\Migration\IOutput; +use OCP\Migration\IRepairStep; + +class SetVcardDatabaseUID implements IRepairStep { + const MAX_ROWS = 1000; + + /** @var IDBConnection */ + private $connection; + private $updateQuery; + + public function __construct(IDBConnection $connection) { + $this->connection = $connection; + } + + + public function getName() { + return 'Extract the vcard uid and store it in the db'; + } + + /** + * @return \Generator + * @suppress SqlInjectionChecker + */ + private function getInvalidEntries() { + $builder = $this->connection->getQueryBuilder(); + + $builder->select('id', 'carddata') + ->from('cards') + ->where($builder->expr()->isNull('uid')) + ->setMaxResults(self::MAX_ROWS); + + do { + $result = $builder->execute(); + $rows = $result->fetchAll(); + foreach ($rows as $row) { + yield $row; + } + $result->closeCursor(); + } while (count($rows) > 0); + } + + private function getUid($carddata) { + preg_match('/^UID:(.*)$/m', $carddata, $matches); + if (count($matches > 1)) { + return $matches[1][0]; + } + return false; + } + + /** + * @param int $id + * @param string $uid + */ + private function update($id, $uid) { + if (!$this->updateQuery) { + $builder = $this->connection->getQueryBuilder(); + + $this->updateQuery = $builder->update('cards') + ->set('uid', $builder->createParameter('uid')) + ->where($builder->expr()->eq('id', $builder->createParameter('id'))); + } + + $this->updateQuery->setParameter('id', $id); + $this->updateQuery->setParameter('uid', $uid); + + $this->updateQuery->execute(); + } + + private function repair() { + $this->connection->beginTransaction(); + $entries = $this->getInvalidEntries(); + $count = 0; + foreach ($entries as $entry) { + $count++; + $uid = $this->getUid($entry['id']); + if ($uid !== false) { + $this->update($entry['id'], $uid); + } + } + $this->connection->commit(); + return $count; + } + + private function shouldRun() { + $versionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0'); + + // was added to 15.0.0.0 + return version_compare($versionFromBeforeUpdate, '15.0.0.0', '<='); + } + + public function run(IOutput $output) { + if ($this->shouldRun()) { + $count = $this->repair(); + + $output->info('Fixed ' . $count . ' vcards'); + } + } +} -- cgit v1.2.3 From 56ad1fccc0b63e478e9107b445ab43607f26f775 Mon Sep 17 00:00:00 2001 From: "John Molakvoæ (skjnldsv)" Date: Fri, 26 Oct 2018 18:27:39 +0200 Subject: Repair registration and autoload bump MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- lib/composer/composer/autoload_classmap.php | 2 ++ lib/composer/composer/autoload_static.php | 2 ++ lib/private/Repair.php | 2 ++ lib/private/Repair/NC15/SetVcardDatabaseUID.php | 40 ++++++++++++++----------- 4 files changed, 28 insertions(+), 18 deletions(-) diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 8c6dc502487..dc20789576b 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -670,6 +670,7 @@ return array( 'OC\\Core\\Migrations\\Version14000Date20180710092004' => $baseDir . '/core/Migrations/Version14000Date20180710092004.php', 'OC\\Core\\Migrations\\Version14000Date20180712153140' => $baseDir . '/core/Migrations/Version14000Date20180712153140.php', 'OC\\Core\\Migrations\\Version15000Date20180926101451' => $baseDir . '/core/Migrations/Version15000Date20180926101451.php', + 'OC\\Core\\Migrations\\Version15000Date20180927120000' => $baseDir . '/core/Migrations/Version15000Date20180927120000.php', 'OC\\Core\\Migrations\\Version15000Date20181015062942' => $baseDir . '/core/Migrations/Version15000Date20181015062942.php', 'OC\\DB\\Adapter' => $baseDir . '/lib/private/DB/Adapter.php', 'OC\\DB\\AdapterMySQL' => $baseDir . '/lib/private/DB/AdapterMySQL.php', @@ -964,6 +965,7 @@ return array( 'OC\\Repair\\NC13\\RepairInvalidPaths' => $baseDir . '/lib/private/Repair/NC13/RepairInvalidPaths.php', 'OC\\Repair\\NC14\\AddPreviewBackgroundCleanupJob' => $baseDir . '/lib/private/Repair/NC14/AddPreviewBackgroundCleanupJob.php', 'OC\\Repair\\NC14\\RepairPendingCronJobs' => $baseDir . '/lib/private/Repair/NC14/RepairPendingCronJobs.php', + 'OC\\Repair\\NC15\\SetVcardDatabaseUID' => $baseDir . '/lib/private/Repair/NC15/SetVcardDatabaseUID.php', 'OC\\Repair\\OldGroupMembershipShares' => $baseDir . '/lib/private/Repair/OldGroupMembershipShares.php', 'OC\\Repair\\Owncloud\\DropAccountTermsTable' => $baseDir . '/lib/private/Repair/Owncloud/DropAccountTermsTable.php', 'OC\\Repair\\Owncloud\\SaveAccountsTableData' => $baseDir . '/lib/private/Repair/Owncloud/SaveAccountsTableData.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index 2a46e99e020..fe2ff5d760e 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -700,6 +700,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OC\\Core\\Migrations\\Version14000Date20180710092004' => __DIR__ . '/../../..' . '/core/Migrations/Version14000Date20180710092004.php', 'OC\\Core\\Migrations\\Version14000Date20180712153140' => __DIR__ . '/../../..' . '/core/Migrations/Version14000Date20180712153140.php', 'OC\\Core\\Migrations\\Version15000Date20180926101451' => __DIR__ . '/../../..' . '/core/Migrations/Version15000Date20180926101451.php', + 'OC\\Core\\Migrations\\Version15000Date20180927120000' => __DIR__ . '/../../..' . '/core/Migrations/Version15000Date20180927120000.php', 'OC\\Core\\Migrations\\Version15000Date20181015062942' => __DIR__ . '/../../..' . '/core/Migrations/Version15000Date20181015062942.php', 'OC\\DB\\Adapter' => __DIR__ . '/../../..' . '/lib/private/DB/Adapter.php', 'OC\\DB\\AdapterMySQL' => __DIR__ . '/../../..' . '/lib/private/DB/AdapterMySQL.php', @@ -994,6 +995,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OC\\Repair\\NC13\\RepairInvalidPaths' => __DIR__ . '/../../..' . '/lib/private/Repair/NC13/RepairInvalidPaths.php', 'OC\\Repair\\NC14\\AddPreviewBackgroundCleanupJob' => __DIR__ . '/../../..' . '/lib/private/Repair/NC14/AddPreviewBackgroundCleanupJob.php', 'OC\\Repair\\NC14\\RepairPendingCronJobs' => __DIR__ . '/../../..' . '/lib/private/Repair/NC14/RepairPendingCronJobs.php', + 'OC\\Repair\\NC15\\SetVcardDatabaseUID' => __DIR__ . '/../../..' . '/lib/private/Repair/NC15/SetVcardDatabaseUID.php', 'OC\\Repair\\OldGroupMembershipShares' => __DIR__ . '/../../..' . '/lib/private/Repair/OldGroupMembershipShares.php', 'OC\\Repair\\Owncloud\\DropAccountTermsTable' => __DIR__ . '/../../..' . '/lib/private/Repair/Owncloud/DropAccountTermsTable.php', 'OC\\Repair\\Owncloud\\SaveAccountsTableData' => __DIR__ . '/../../..' . '/lib/private/Repair/Owncloud/SaveAccountsTableData.php', diff --git a/lib/private/Repair.php b/lib/private/Repair.php index ad9662ca1d7..01724fd6a38 100644 --- a/lib/private/Repair.php +++ b/lib/private/Repair.php @@ -39,6 +39,7 @@ use OC\Repair\NC11\FixMountStorages; use OC\Repair\NC13\AddLogRotateJob; use OC\Repair\NC14\AddPreviewBackgroundCleanupJob; use OC\Repair\NC14\RepairPendingCronJobs; +use OC\Repair\NC15\SetVcardDatabaseUID; use OC\Repair\OldGroupMembershipShares; use OC\Repair\Owncloud\DropAccountTermsTable; use OC\Repair\Owncloud\SaveAccountsTableData; @@ -139,6 +140,7 @@ class Repair implements IOutput{ new AddPreviewBackgroundCleanupJob(\OC::$server->getJobList()), new AddCleanupUpdaterBackupsJob(\OC::$server->getJobList()), new RepairPendingCronJobs(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig()), + new SetVcardDatabaseUID(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig()), ]; } diff --git a/lib/private/Repair/NC15/SetVcardDatabaseUID.php b/lib/private/Repair/NC15/SetVcardDatabaseUID.php index 2fe50c79471..e82a0aad18a 100644 --- a/lib/private/Repair/NC15/SetVcardDatabaseUID.php +++ b/lib/private/Repair/NC15/SetVcardDatabaseUID.php @@ -21,10 +21,8 @@ * */ -namespace OC\Repair\NC13; +namespace OC\Repair\NC15; - -use OCP\DB\QueryBuilder\IQueryBuilder; use OCP\IConfig; use OCP\IDBConnection; use OCP\Migration\IOutput; @@ -35,13 +33,17 @@ class SetVcardDatabaseUID implements IRepairStep { /** @var IDBConnection */ private $connection; + + /** @var IConfig */ + private $config; + private $updateQuery; - public function __construct(IDBConnection $connection) { + public function __construct(IDBConnection $connection, IConfig $config) { $this->connection = $connection; + $this->config = $config; } - public function getName() { return 'Extract the vcard uid and store it in the db'; } @@ -54,13 +56,13 @@ class SetVcardDatabaseUID implements IRepairStep { $builder = $this->connection->getQueryBuilder(); $builder->select('id', 'carddata') - ->from('cards') - ->where($builder->expr()->isNull('uid')) - ->setMaxResults(self::MAX_ROWS); + ->from('cards') + ->where($builder->expr()->isNull('uid')) + ->setMaxResults(self::MAX_ROWS); do { $result = $builder->execute(); - $rows = $result->fetchAll(); + $rows = $result->fetchAll(); foreach ($rows as $row) { yield $row; } @@ -70,9 +72,10 @@ class SetVcardDatabaseUID implements IRepairStep { private function getUid($carddata) { preg_match('/^UID:(.*)$/m', $carddata, $matches); - if (count($matches > 1)) { - return $matches[1][0]; + if (count($matches) > 1) { + return $matches[1]; } + return false; } @@ -85,8 +88,8 @@ class SetVcardDatabaseUID implements IRepairStep { $builder = $this->connection->getQueryBuilder(); $this->updateQuery = $builder->update('cards') - ->set('uid', $builder->createParameter('uid')) - ->where($builder->expr()->eq('id', $builder->createParameter('id'))); + ->set('uid', $builder->createParameter('uid')) + ->where($builder->expr()->eq('id', $builder->createParameter('id'))); } $this->updateQuery->setParameter('id', $id); @@ -98,23 +101,24 @@ class SetVcardDatabaseUID implements IRepairStep { private function repair() { $this->connection->beginTransaction(); $entries = $this->getInvalidEntries(); - $count = 0; + $count = 0; foreach ($entries as $entry) { $count++; - $uid = $this->getUid($entry['id']); + $uid = $this->getUid($entry['carddata']); if ($uid !== false) { $this->update($entry['id'], $uid); } } $this->connection->commit(); + return $count; } private function shouldRun() { - $versionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0'); + $versionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0.0'); - // was added to 15.0.0.0 - return version_compare($versionFromBeforeUpdate, '15.0.0.0', '<='); + // was added to 15.0.0.2 + return version_compare($versionFromBeforeUpdate, '15.0.0.2', '<='); } public function run(IOutput $output) { -- cgit v1.2.3 From 06b3ade9ee3ee1c384cc5061a63fcc5e3c405721 Mon Sep 17 00:00:00 2001 From: "John Molakvoæ (skjnldsv)" Date: Fri, 26 Oct 2018 19:01:38 +0200 Subject: Tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- lib/private/Repair/NC15/SetVcardDatabaseUID.php | 2 +- tests/lib/Repair/SetVcardDatabaseUIDTest.php | 121 ++++++++++++++++++++++++ 2 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 tests/lib/Repair/SetVcardDatabaseUIDTest.php diff --git a/lib/private/Repair/NC15/SetVcardDatabaseUID.php b/lib/private/Repair/NC15/SetVcardDatabaseUID.php index e82a0aad18a..4d2805247bf 100644 --- a/lib/private/Repair/NC15/SetVcardDatabaseUID.php +++ b/lib/private/Repair/NC15/SetVcardDatabaseUID.php @@ -71,7 +71,7 @@ class SetVcardDatabaseUID implements IRepairStep { } private function getUid($carddata) { - preg_match('/^UID:(.*)$/m', $carddata, $matches); + preg_match('/UID:(.*)$/m', $carddata, $matches); if (count($matches) > 1) { return $matches[1]; } diff --git a/tests/lib/Repair/SetVcardDatabaseUIDTest.php b/tests/lib/Repair/SetVcardDatabaseUIDTest.php new file mode 100644 index 00000000000..59a115ba755 --- /dev/null +++ b/tests/lib/Repair/SetVcardDatabaseUIDTest.php @@ -0,0 +1,121 @@ + + * + * @author John Molakvoæ + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program 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 program. If not, see . + * + */ + +namespace Test\Repair; + +use OCP\IConfig; +use OC\Repair\NC15\SetVcardDatabaseUID; +use Test\TestCase; + +/** + * @group DB + */ +class SetVcardDatabaseUIDTest extends TestCase { + + /** @var SetVcardDatabaseUID */ + private $repair; + + /** @var IConfig */ + private $config; + + protected function setUp() { + parent::setUp(); + + $this->config = $this->createMock(IConfig::class); + $this->repair = new SetVcardDatabaseUID(\OC::$server->getDatabaseConnection(), $this->config); + } + + protected function tearDown() { + return parent::tearDown(); + } + + public function dataTestVcards() { + return [ + // classic vcard + ['BEGIN:VCARD + VERSION:3.0 + PRODID:-//Sabre//Sabre VObject 4.1.2//EN + UID:Test + FN:Test + N:Test;;;; + END:VCARD', 'Test'], + + // UID as url + ['BEGIN:VCARD + VERSION:3.0 + PRODID:-//Sabre//Sabre VObject 4.1.2//EN + UID:https://User@old.domain.com/remote.php/carddav/addressbooks/User/contacts/2EAF6525-17ADC861-38D6BB1D.vcf + FN:Test + N:Test;;;; + END:VCARD', 'https://User@old.domain.com/remote.php/carddav/addressbooks/User/contacts/2EAF6525-17ADC861-38D6BB1D.vcf'], + + // No uid + ['BEGIN:VCARD + VERSION:3.0 + PRODID:-//Sabre//Sabre VObject 4.1.2//EN + FN:Test + N:Test;;;; + END:VCARD', false] + ]; + } + + /** + * @dataProvider dataTestVcards + * + * @param string $from + * @param string|boolean $expected + */ + public function testExtractUIDFromVcard($from, $expected) { + $uid = $this->invokePrivate($this->repair, 'getUid', ['carddata' => $from]); + $this->assertEquals($expected, $uid); + } + + public function shouldRunDataProvider() { + return [ + ['11.0.0.0', true], + ['15.0.0.3', false], + ['13.0.5.2', true], + ['12.0.0.0', true], + ['16.0.0.1', false], + ['15.0.0.2', true], + ['13.0.0.0', true], + ['13.0.0.1', true] + ]; + } + + /** + * @dataProvider shouldRunDataProvider + * + * @param string $from + * @param boolean $expected + */ + public function testShouldRun($from, $expected) { + $this->config->expects($this->any()) + ->method('getSystemValue') + ->with('version', '0.0.0.0') + ->willReturn($from); + + $this->assertEquals($expected, $this->invokePrivate($this->repair, 'shouldRun')); + } + +} \ No newline at end of file -- cgit v1.2.3 From 9afff2fb20ec2c00cc958639342add7b19a00e78 Mon Sep 17 00:00:00 2001 From: "John Molakvoæ (skjnldsv)" Date: Sat, 27 Oct 2018 11:54:57 +0200 Subject: Properly set uid and create and update MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- apps/dav/lib/CardDAV/CardDavBackend.php | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/apps/dav/lib/CardDAV/CardDavBackend.php b/apps/dav/lib/CardDAV/CardDavBackend.php index a2d3b03147b..a9d65f2f0f9 100644 --- a/apps/dav/lib/CardDAV/CardDavBackend.php +++ b/apps/dav/lib/CardDAV/CardDavBackend.php @@ -494,7 +494,7 @@ class CardDavBackend implements BackendInterface, SyncSupport { */ function getCards($addressBookId) { $query = $this->db->getQueryBuilder(); - $query->select(['id', 'uri', 'lastmodified', 'etag', 'size', 'carddata']) + $query->select(['id', 'uri', 'lastmodified', 'etag', 'size', 'carddata', 'uid']) ->from('cards') ->where($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId))); @@ -525,7 +525,7 @@ class CardDavBackend implements BackendInterface, SyncSupport { */ function getCard($addressBookId, $cardUri) { $query = $this->db->getQueryBuilder(); - $query->select(['id', 'uri', 'lastmodified', 'etag', 'size', 'carddata']) + $query->select(['id', 'uri', 'lastmodified', 'etag', 'size', 'carddata', 'uid']) ->from('cards') ->where($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId))) ->andWhere($query->expr()->eq('uri', $query->createNamedParameter($cardUri))) @@ -563,7 +563,7 @@ class CardDavBackend implements BackendInterface, SyncSupport { $cards = []; $query = $this->db->getQueryBuilder(); - $query->select(['id', 'uri', 'lastmodified', 'etag', 'size', 'carddata']) + $query->select(['id', 'uri', 'lastmodified', 'etag', 'size', 'carddata', 'uid']) ->from('cards') ->where($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId))) ->andWhere($query->expr()->in('uri', $query->createParameter('uri'))); @@ -609,6 +609,7 @@ class CardDavBackend implements BackendInterface, SyncSupport { */ function createCard($addressBookId, $cardUri, $cardData) { $etag = md5($cardData); + $uid = $this->getUID($cardData); $query = $this->db->getQueryBuilder(); $query->insert('cards') @@ -619,6 +620,7 @@ class CardDavBackend implements BackendInterface, SyncSupport { 'addressbookid' => $query->createNamedParameter($addressBookId), 'size' => $query->createNamedParameter(strlen($cardData)), 'etag' => $query->createNamedParameter($etag), + 'uid' => $query->createNamedParameter($uid), ]) ->execute(); @@ -661,6 +663,7 @@ class CardDavBackend implements BackendInterface, SyncSupport { */ function updateCard($addressBookId, $cardUri, $cardData) { + $uid = $this->getUID($cardData); $etag = md5($cardData); $query = $this->db->getQueryBuilder(); $query->update('cards') @@ -668,6 +671,7 @@ class CardDavBackend implements BackendInterface, SyncSupport { ->set('lastmodified', $query->createNamedParameter(time())) ->set('size', $query->createNamedParameter(strlen($cardData))) ->set('etag', $query->createNamedParameter($etag)) + ->set('uid', $query->createNamedParameter($uid)) ->where($query->expr()->eq('uri', $query->createNamedParameter($cardUri))) ->andWhere($query->expr()->eq('addressbookid', $query->createNamedParameter($addressBookId))) ->execute(); @@ -1125,4 +1129,10 @@ class CardDavBackend implements BackendInterface, SyncSupport { $addressbookInfo[$displaynameKey] = $principalInformation['{DAV:}displayname']; } } + + private function getUID($cardData) { + $vCard = Reader::read($cardData); + $uid = $vCard->UID->getValue(); + return $uid; + } } -- cgit v1.2.3 From 644686c0ec74f619a42c5274cd8422861df97127 Mon Sep 17 00:00:00 2001 From: "John Molakvoæ (skjnldsv)" Date: Sat, 27 Oct 2018 13:39:10 +0200 Subject: Create cards if none MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- core/Migrations/Version15000Date20180927120000.php | 50 +++++++++++++++++++--- 1 file changed, 45 insertions(+), 5 deletions(-) diff --git a/core/Migrations/Version15000Date20180927120000.php b/core/Migrations/Version15000Date20180927120000.php index 5636811baa6..d38914314ff 100644 --- a/core/Migrations/Version15000Date20180927120000.php +++ b/core/Migrations/Version15000Date20180927120000.php @@ -36,11 +36,51 @@ class Version15000Date20180927120000 extends SimpleMigrationStep { /** @var ISchemaWrapper $schema */ $schema = $schemaClosure(); - $table = $schema->getTable('cards'); - $table->addColumn('uid', Type::STRING, [ - 'notnull' => false, - 'length' => 255 - ]); + if ($schema->hasTable('cards')) { + $table = $schema->getTable('cards'); + $table->addColumn('uid', Type::STRING, [ + 'notnull' => false, + 'length' => 255 + ]); + } else { + $table = $schema->createTable('cards'); + $table->addColumn('id', 'bigint', [ + 'autoincrement' => true, + 'notnull' => true, + 'length' => 11, + 'unsigned' => true, + ]); + $table->addColumn('addressbookid', 'integer', [ + 'notnull' => true, + 'default' => 0, + ]); + $table->addColumn('carddata', 'blob', [ + 'notnull' => false, + ]); + $table->addColumn('uri', 'string', [ + 'notnull' => false, + 'length' => 255, + ]); + $table->addColumn('lastmodified', 'bigint', [ + 'notnull' => false, + 'length' => 11, + 'unsigned' => true, + ]); + $table->addColumn('etag', 'string', [ + 'notnull' => false, + 'length' => 32, + ]); + $table->addColumn('size', 'bigint', [ + 'notnull' => true, + 'length' => 11, + 'unsigned' => true, + ]); + $table->addColumn('uid', Type::STRING, [ + 'notnull' => false, + 'length' => 255 + ]); + $table->setPrimaryKey(['id']); + } return $schema; } -- cgit v1.2.3 From d89edb28c4218eeadc5c2c5bbea6253dfc599a5f Mon Sep 17 00:00:00 2001 From: "John Molakvoæ (skjnldsv)" Date: Tue, 30 Oct 2018 13:03:49 +0100 Subject: move migration MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- apps/dav/composer/composer/autoload_classmap.php | 1 + apps/dav/composer/composer/autoload_static.php | 1 + apps/dav/lib/CardDAV/CardDavBackend.php | 15 +++- .../Migration/Version1008Date20181030113700.php | 52 +++++++++++++ core/Migrations/Version15000Date20180927120000.php | 87 ---------------------- lib/composer/composer/autoload_classmap.php | 1 - lib/composer/composer/autoload_static.php | 1 - lib/private/Repair/NC15/SetVcardDatabaseUID.php | 28 ++++--- 8 files changed, 84 insertions(+), 102 deletions(-) create mode 100644 apps/dav/lib/Migration/Version1008Date20181030113700.php delete mode 100644 core/Migrations/Version15000Date20180927120000.php diff --git a/apps/dav/composer/composer/autoload_classmap.php b/apps/dav/composer/composer/autoload_classmap.php index fe7557f7e08..c9680651ff9 100644 --- a/apps/dav/composer/composer/autoload_classmap.php +++ b/apps/dav/composer/composer/autoload_classmap.php @@ -156,6 +156,7 @@ return array( 'OCA\\DAV\\Migration\\Version1005Date20180530124431' => $baseDir . '/../lib/Migration/Version1005Date20180530124431.php', 'OCA\\DAV\\Migration\\Version1006Date20180619154313' => $baseDir . '/../lib/Migration/Version1006Date20180619154313.php', 'OCA\\DAV\\Migration\\Version1007Date20181007225117' => $baseDir . '/../lib/Migration/Version1007Date20181007225117.php', + 'OCA\\DAV\\Migration\\Version1008Date20181030113700' => $baseDir . '/../lib/Migration/Version1008Date20181030113700.php', 'OCA\\DAV\\RootCollection' => $baseDir . '/../lib/RootCollection.php', 'OCA\\DAV\\Server' => $baseDir . '/../lib/Server.php', 'OCA\\DAV\\Settings\\CalDAVSettings' => $baseDir . '/../lib/Settings/CalDAVSettings.php', diff --git a/apps/dav/composer/composer/autoload_static.php b/apps/dav/composer/composer/autoload_static.php index 1668f1270f5..71879abc0a5 100644 --- a/apps/dav/composer/composer/autoload_static.php +++ b/apps/dav/composer/composer/autoload_static.php @@ -171,6 +171,7 @@ class ComposerStaticInitDAV 'OCA\\DAV\\Migration\\Version1005Date20180530124431' => __DIR__ . '/..' . '/../lib/Migration/Version1005Date20180530124431.php', 'OCA\\DAV\\Migration\\Version1006Date20180619154313' => __DIR__ . '/..' . '/../lib/Migration/Version1006Date20180619154313.php', 'OCA\\DAV\\Migration\\Version1007Date20181007225117' => __DIR__ . '/..' . '/../lib/Migration/Version1007Date20181007225117.php', + 'OCA\\DAV\\Migration\\Version1008Date20181030113700' => __DIR__ . '/..' . '/../lib/Migration/Version1008Date20181030113700.php', 'OCA\\DAV\\RootCollection' => __DIR__ . '/..' . '/../lib/RootCollection.php', 'OCA\\DAV\\Server' => __DIR__ . '/..' . '/../lib/Server.php', 'OCA\\DAV\\Settings\\CalDAVSettings' => __DIR__ . '/..' . '/../lib/Settings/CalDAVSettings.php', diff --git a/apps/dav/lib/CardDAV/CardDavBackend.php b/apps/dav/lib/CardDAV/CardDavBackend.php index a9d65f2f0f9..8ef0e0baf56 100644 --- a/apps/dav/lib/CardDAV/CardDavBackend.php +++ b/apps/dav/lib/CardDAV/CardDavBackend.php @@ -1130,9 +1130,20 @@ class CardDavBackend implements BackendInterface, SyncSupport { } } + /** + * Extract UID from vcard + * + * @param string $cardData the vcard raw data + * @return string the uid or empty if none + * @throws BadRequest + */ private function getUID($cardData) { $vCard = Reader::read($cardData); - $uid = $vCard->UID->getValue(); - return $uid; + if ($vCard->UID) { + $uid = $vCard->UID->getValue(); + return $uid; + } + // should already be handled, but just in case + throw new BadRequest('vCards on CardDAV servers MUST have a UID property'); } } diff --git a/apps/dav/lib/Migration/Version1008Date20181030113700.php b/apps/dav/lib/Migration/Version1008Date20181030113700.php new file mode 100644 index 00000000000..1cc6223a9e9 --- /dev/null +++ b/apps/dav/lib/Migration/Version1008Date20181030113700.php @@ -0,0 +1,52 @@ + + * + * @license GNU AGPL version 3 or any later version + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as + * published by the Free Software Foundation, either version 3 of the + * License, or (at your option) any later version. + * + * This program 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 program. If not, see . + * + */ + +namespace OCA\DAV\Migration; + +use Closure; + +use Doctrine\DBAL\Types\Type; +use OCP\DB\ISchemaWrapper; +use OCP\Migration\SimpleMigrationStep; +use OCP\Migration\IOutput; + +/** + * add column for share notes + * + * Class Version15000Date20180927120000 + */ +class Version1008Date20181030113700 extends SimpleMigrationStep { + public function changeSchema(IOutput $output, Closure $schemaClosure, array $options) { + + /** @var ISchemaWrapper $schema */ + $schema = $schemaClosure(); + + $table = $schema->getTable('cards'); + $table->addColumn('uid', Type::STRING, [ + 'notnull' => false, + 'length' => 255 + ]); + + return $schema; + } +} diff --git a/core/Migrations/Version15000Date20180927120000.php b/core/Migrations/Version15000Date20180927120000.php deleted file mode 100644 index d38914314ff..00000000000 --- a/core/Migrations/Version15000Date20180927120000.php +++ /dev/null @@ -1,87 +0,0 @@ - - * - * @license GNU AGPL version 3 or any later version - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as - * published by the Free Software Foundation, either version 3 of the - * License, or (at your option) any later version. - * - * This program 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 program. If not, see . - * - */ - -namespace OC\Core\Migrations; - -use Doctrine\DBAL\Types\Type; -use OCP\DB\ISchemaWrapper; -use OCP\Migration\SimpleMigrationStep; - -/** - * add column for share notes - * - * Class Version15000Date20180927120000 - */ -class Version15000Date20180927120000 extends SimpleMigrationStep { - public function changeSchema(\OCP\Migration\IOutput $output, \Closure $schemaClosure, array $options) { - - /** @var ISchemaWrapper $schema */ - $schema = $schemaClosure(); - - if ($schema->hasTable('cards')) { - $table = $schema->getTable('cards'); - $table->addColumn('uid', Type::STRING, [ - 'notnull' => false, - 'length' => 255 - ]); - } else { - $table = $schema->createTable('cards'); - $table->addColumn('id', 'bigint', [ - 'autoincrement' => true, - 'notnull' => true, - 'length' => 11, - 'unsigned' => true, - ]); - $table->addColumn('addressbookid', 'integer', [ - 'notnull' => true, - 'default' => 0, - ]); - $table->addColumn('carddata', 'blob', [ - 'notnull' => false, - ]); - $table->addColumn('uri', 'string', [ - 'notnull' => false, - 'length' => 255, - ]); - $table->addColumn('lastmodified', 'bigint', [ - 'notnull' => false, - 'length' => 11, - 'unsigned' => true, - ]); - $table->addColumn('etag', 'string', [ - 'notnull' => false, - 'length' => 32, - ]); - $table->addColumn('size', 'bigint', [ - 'notnull' => true, - 'length' => 11, - 'unsigned' => true, - ]); - $table->addColumn('uid', Type::STRING, [ - 'notnull' => false, - 'length' => 255 - ]); - $table->setPrimaryKey(['id']); - } - - return $schema; - } -} diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index dc20789576b..d7523d52caa 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -670,7 +670,6 @@ return array( 'OC\\Core\\Migrations\\Version14000Date20180710092004' => $baseDir . '/core/Migrations/Version14000Date20180710092004.php', 'OC\\Core\\Migrations\\Version14000Date20180712153140' => $baseDir . '/core/Migrations/Version14000Date20180712153140.php', 'OC\\Core\\Migrations\\Version15000Date20180926101451' => $baseDir . '/core/Migrations/Version15000Date20180926101451.php', - 'OC\\Core\\Migrations\\Version15000Date20180927120000' => $baseDir . '/core/Migrations/Version15000Date20180927120000.php', 'OC\\Core\\Migrations\\Version15000Date20181015062942' => $baseDir . '/core/Migrations/Version15000Date20181015062942.php', 'OC\\DB\\Adapter' => $baseDir . '/lib/private/DB/Adapter.php', 'OC\\DB\\AdapterMySQL' => $baseDir . '/lib/private/DB/AdapterMySQL.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index fe2ff5d760e..cf2fef4282d 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -700,7 +700,6 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OC\\Core\\Migrations\\Version14000Date20180710092004' => __DIR__ . '/../../..' . '/core/Migrations/Version14000Date20180710092004.php', 'OC\\Core\\Migrations\\Version14000Date20180712153140' => __DIR__ . '/../../..' . '/core/Migrations/Version14000Date20180712153140.php', 'OC\\Core\\Migrations\\Version15000Date20180926101451' => __DIR__ . '/../../..' . '/core/Migrations/Version15000Date20180926101451.php', - 'OC\\Core\\Migrations\\Version15000Date20180927120000' => __DIR__ . '/../../..' . '/core/Migrations/Version15000Date20180927120000.php', 'OC\\Core\\Migrations\\Version15000Date20181015062942' => __DIR__ . '/../../..' . '/core/Migrations/Version15000Date20181015062942.php', 'OC\\DB\\Adapter' => __DIR__ . '/../../..' . '/lib/private/DB/Adapter.php', 'OC\\DB\\AdapterMySQL' => __DIR__ . '/../../..' . '/lib/private/DB/AdapterMySQL.php', diff --git a/lib/private/Repair/NC15/SetVcardDatabaseUID.php b/lib/private/Repair/NC15/SetVcardDatabaseUID.php index 4d2805247bf..ccf6c47cbc8 100644 --- a/lib/private/Repair/NC15/SetVcardDatabaseUID.php +++ b/lib/private/Repair/NC15/SetVcardDatabaseUID.php @@ -27,6 +27,7 @@ use OCP\IConfig; use OCP\IDBConnection; use OCP\Migration\IOutput; use OCP\Migration\IRepairStep; +use Sabre\VObject\Reader; class SetVcardDatabaseUID implements IRepairStep { const MAX_ROWS = 1000; @@ -70,20 +71,27 @@ class SetVcardDatabaseUID implements IRepairStep { } while (count($rows) > 0); } - private function getUid($carddata) { - preg_match('/UID:(.*)$/m', $carddata, $matches); - if (count($matches) > 1) { - return $matches[1]; + /** + * Extract UID from vcard + * + * @param string $cardData the vcard raw data + * @return string the uid or empty if none + */ + private function getUID(string $cardData): string { + $vCard = Reader::read($cardData); + if ($vCard->UID) { + $uid = $vCard->UID->getValue(); + return $uid; } - return false; + return ''; } /** * @param int $id * @param string $uid */ - private function update($id, $uid) { + private function update(int $id, string $uid) { if (!$this->updateQuery) { $builder = $this->connection->getQueryBuilder(); @@ -98,16 +106,14 @@ class SetVcardDatabaseUID implements IRepairStep { $this->updateQuery->execute(); } - private function repair() { + private function repair(): int { $this->connection->beginTransaction(); $entries = $this->getInvalidEntries(); $count = 0; foreach ($entries as $entry) { $count++; - $uid = $this->getUid($entry['carddata']); - if ($uid !== false) { - $this->update($entry['id'], $uid); - } + $uid = $this->getUID($entry['carddata']); + $this->update($entry['id'], $uid); } $this->connection->commit(); -- cgit v1.2.3 From 7246f2ace50e41f68433cd89755413b512fa7909 Mon Sep 17 00:00:00 2001 From: Morris Jobke Date: Thu, 1 Nov 2018 14:44:35 +0100 Subject: Update PHPDoc to reflect the actual behaviour Signed-off-by: Morris Jobke --- apps/dav/lib/CardDAV/CardDavBackend.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/apps/dav/lib/CardDAV/CardDavBackend.php b/apps/dav/lib/CardDAV/CardDavBackend.php index 8ef0e0baf56..80a3fe2f11f 100644 --- a/apps/dav/lib/CardDAV/CardDavBackend.php +++ b/apps/dav/lib/CardDAV/CardDavBackend.php @@ -1134,8 +1134,8 @@ class CardDavBackend implements BackendInterface, SyncSupport { * Extract UID from vcard * * @param string $cardData the vcard raw data - * @return string the uid or empty if none - * @throws BadRequest + * @return string the uid + * @throws BadRequest if no UID is available */ private function getUID($cardData) { $vCard = Reader::read($cardData); -- cgit v1.2.3 From abed75e5cbd200169a236f3b586553e5d9ed0452 Mon Sep 17 00:00:00 2001 From: "John Molakvoæ (skjnldsv)" Date: Thu, 1 Nov 2018 17:32:21 +0100 Subject: Fix phpunit MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- tests/lib/Repair/SetVcardDatabaseUIDTest.php | 40 ++++++++++++++-------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/tests/lib/Repair/SetVcardDatabaseUIDTest.php b/tests/lib/Repair/SetVcardDatabaseUIDTest.php index 59a115ba755..fe1a7481d7b 100644 --- a/tests/lib/Repair/SetVcardDatabaseUIDTest.php +++ b/tests/lib/Repair/SetVcardDatabaseUIDTest.php @@ -52,30 +52,30 @@ class SetVcardDatabaseUIDTest extends TestCase { public function dataTestVcards() { return [ // classic vcard - ['BEGIN:VCARD - VERSION:3.0 - PRODID:-//Sabre//Sabre VObject 4.1.2//EN - UID:Test - FN:Test - N:Test;;;; - END:VCARD', 'Test'], + ['BEGIN:VCARD'.PHP_EOL. + 'VERSION:3.0'.PHP_EOL. + 'PRODID:-//Sabre//Sabre VObject 4.1.2//EN'.PHP_EOL. + 'UID:Test'.PHP_EOL. + 'FN:Test'.PHP_EOL. + 'N:Test;;;;'.PHP_EOL. + 'END:VCARD', 'Test'], // UID as url - ['BEGIN:VCARD - VERSION:3.0 - PRODID:-//Sabre//Sabre VObject 4.1.2//EN - UID:https://User@old.domain.com/remote.php/carddav/addressbooks/User/contacts/2EAF6525-17ADC861-38D6BB1D.vcf - FN:Test - N:Test;;;; - END:VCARD', 'https://User@old.domain.com/remote.php/carddav/addressbooks/User/contacts/2EAF6525-17ADC861-38D6BB1D.vcf'], + ['BEGIN:VCARD'.PHP_EOL. + 'VERSION:3.0'.PHP_EOL. + 'PRODID:-//Sabre//Sabre VObject 4.1.2//EN'.PHP_EOL. + 'UID:https://User@old.domain.com/remote.php/carddav/addressbooks/User/contacts/2EAF6525-17ADC861-38D6BB1D.vcf'.PHP_EOL. + 'FN:Test'.PHP_EOL. + 'N:Test;;;;'.PHP_EOL. + 'END:VCARD', 'https://User@old.domain.com/remote.php/carddav/addressbooks/User/contacts/2EAF6525-17ADC861-38D6BB1D.vcf'], // No uid - ['BEGIN:VCARD - VERSION:3.0 - PRODID:-//Sabre//Sabre VObject 4.1.2//EN - FN:Test - N:Test;;;; - END:VCARD', false] + ['BEGIN:VCARD'.PHP_EOL. + 'VERSION:3.0'.PHP_EOL. + 'PRODID:-//Sabre//Sabre VObject 4.1.2//EN'.PHP_EOL. + 'FN:Test'.PHP_EOL. + 'N:Test;;;;'.PHP_EOL. + 'END:VCARD', false] ]; } -- cgit v1.2.3 From 66624cfe0a56fb4ca14c4d15ce62ddf0a389078d Mon Sep 17 00:00:00 2001 From: "John Molakvoæ (skjnldsv)" Date: Fri, 2 Nov 2018 14:20:53 +0100 Subject: Phpunit fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: John Molakvoæ (skjnldsv) --- apps/dav/lib/CardDAV/CardDavBackend.php | 14 ++++--- apps/dav/tests/unit/CardDAV/CardDavBackendTest.php | 47 +++++++++++++--------- 2 files changed, 36 insertions(+), 25 deletions(-) diff --git a/apps/dav/lib/CardDAV/CardDavBackend.php b/apps/dav/lib/CardDAV/CardDavBackend.php index 80a3fe2f11f..a8907f631cd 100644 --- a/apps/dav/lib/CardDAV/CardDavBackend.php +++ b/apps/dav/lib/CardDAV/CardDavBackend.php @@ -1138,12 +1138,16 @@ class CardDavBackend implements BackendInterface, SyncSupport { * @throws BadRequest if no UID is available */ private function getUID($cardData) { - $vCard = Reader::read($cardData); - if ($vCard->UID) { - $uid = $vCard->UID->getValue(); - return $uid; + if ($cardData != '') { + $vCard = Reader::read($cardData); + if ($vCard->UID) { + $uid = $vCard->UID->getValue(); + return $uid; + } + // should already be handled, but just in case + throw new BadRequest('vCards on CardDAV servers MUST have a UID property'); } // should already be handled, but just in case - throw new BadRequest('vCards on CardDAV servers MUST have a UID property'); + throw new BadRequest('vCard can not be empty'); } } diff --git a/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php b/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php index 816ba670990..2f5287df82c 100644 --- a/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php +++ b/apps/dav/tests/unit/CardDAV/CardDavBackendTest.php @@ -87,6 +87,14 @@ class CardDavBackendTest extends TestCase { const UNIT_TEST_USER1 = 'principals/users/carddav-unit-test1'; const UNIT_TEST_GROUP = 'principals/groups/carddav-unit-test-group'; + private $vcardTest = 'BEGIN:VCARD'.PHP_EOL. + 'VERSION:3.0'.PHP_EOL. + 'PRODID:-//Sabre//Sabre VObject 4.1.2//EN'.PHP_EOL. + 'UID:Test'.PHP_EOL. + 'FN:Test'.PHP_EOL. + 'N:Test;;;;'.PHP_EOL. + 'END:VCARD'; + public function setUp() { parent::setUp(); @@ -121,7 +129,6 @@ class CardDavBackendTest extends TestCase { $query = $this->db->getQueryBuilder(); $query->delete('cards')->execute(); - $this->tearDown(); } @@ -217,8 +224,8 @@ class CardDavBackendTest extends TestCase { $uri = $this->getUniqueID('card'); // updateProperties is expected twice, once for createCard and once for updateCard - $backend->expects($this->at(0))->method('updateProperties')->with($bookId, $uri, ''); - $backend->expects($this->at(1))->method('updateProperties')->with($bookId, $uri, '***'); + $backend->expects($this->at(0))->method('updateProperties')->with($bookId, $uri, $this->vcardTest); + $backend->expects($this->at(1))->method('updateProperties')->with($bookId, $uri, $this->vcardTest); // Expect event $this->dispatcher->expects($this->at(0)) @@ -226,16 +233,16 @@ class CardDavBackendTest extends TestCase { ->with('\OCA\DAV\CardDAV\CardDavBackend::createCard', $this->callback(function(GenericEvent $e) use ($bookId, $uri) { return $e->getArgument('addressBookId') === $bookId && $e->getArgument('cardUri') === $uri && - $e->getArgument('cardData') === ''; + $e->getArgument('cardData') === $this->vcardTest; })); // create a card - $backend->createCard($bookId, $uri, ''); + $backend->createCard($bookId, $uri, $this->vcardTest); // get all the cards $cards = $backend->getCards($bookId); $this->assertEquals(1, count($cards)); - $this->assertEquals('', $cards[0]['carddata']); + $this->assertEquals($this->vcardTest, $cards[0]['carddata']); // get the cards $card = $backend->getCard($bookId, $uri); @@ -245,7 +252,7 @@ class CardDavBackendTest extends TestCase { $this->assertArrayHasKey('lastmodified', $card); $this->assertArrayHasKey('etag', $card); $this->assertArrayHasKey('size', $card); - $this->assertEquals('', $card['carddata']); + $this->assertEquals($this->vcardTest, $card['carddata']); // Expect event $this->dispatcher->expects($this->at(0)) @@ -253,13 +260,13 @@ class CardDavBackendTest extends TestCase { ->with('\OCA\DAV\CardDAV\CardDavBackend::updateCard', $this->callback(function(GenericEvent $e) use ($bookId, $uri) { return $e->getArgument('addressBookId') === $bookId && $e->getArgument('cardUri') === $uri && - $e->getArgument('cardData') === '***'; + $e->getArgument('cardData') === $this->vcardTest; })); // update the card - $backend->updateCard($bookId, $uri, '***'); + $backend->updateCard($bookId, $uri, $this->vcardTest); $card = $backend->getCard($bookId, $uri); - $this->assertEquals('***', $card['carddata']); + $this->assertEquals($this->vcardTest, $card['carddata']); // Expect event $this->dispatcher->expects($this->at(0)) @@ -290,18 +297,18 @@ class CardDavBackendTest extends TestCase { // create a card $uri0 = $this->getUniqueID('card'); - $this->backend->createCard($bookId, $uri0, ''); + $this->backend->createCard($bookId, $uri0, $this->vcardTest); $uri1 = $this->getUniqueID('card'); - $this->backend->createCard($bookId, $uri1, ''); + $this->backend->createCard($bookId, $uri1, $this->vcardTest); $uri2 = $this->getUniqueID('card'); - $this->backend->createCard($bookId, $uri2, ''); + $this->backend->createCard($bookId, $uri2, $this->vcardTest); // get all the cards $cards = $this->backend->getCards($bookId); $this->assertEquals(3, count($cards)); - $this->assertEquals('', $cards[0]['carddata']); - $this->assertEquals('', $cards[1]['carddata']); - $this->assertEquals('', $cards[2]['carddata']); + $this->assertEquals($this->vcardTest, $cards[0]['carddata']); + $this->assertEquals($this->vcardTest, $cards[1]['carddata']); + $this->assertEquals($this->vcardTest, $cards[2]['carddata']); // get the cards $cards = $this->backend->getMultipleCards($bookId, [$uri1, $uri2]); @@ -312,7 +319,7 @@ class CardDavBackendTest extends TestCase { $this->assertArrayHasKey('lastmodified', $card); $this->assertArrayHasKey('etag', $card); $this->assertArrayHasKey('size', $card); - $this->assertEquals('', $card['carddata']); + $this->assertEquals($this->vcardTest, $card['carddata']); } // delete the card @@ -357,7 +364,7 @@ class CardDavBackendTest extends TestCase { ->method('purgeProperties'); // create a card - $this->backend->createCard($bookId, $uri, ''); + $this->backend->createCard($bookId, $uri, $this->vcardTest); // delete the card $this->assertTrue($this->backend->deleteCard($bookId, $uri)); @@ -380,7 +387,7 @@ class CardDavBackendTest extends TestCase { // add a change $uri0 = $this->getUniqueID('card'); - $this->backend->createCard($bookId, $uri0, ''); + $this->backend->createCard($bookId, $uri0, $this->vcardTest); // look for changes $changes = $this->backend->getChangesForAddressBook($bookId, $syncToken, 1); @@ -683,7 +690,7 @@ class CardDavBackendTest extends TestCase { } $result = $this->backend->getContact(0, 'uri0'); - $this->assertSame(7, count($result)); + $this->assertSame(8, count($result)); $this->assertSame(0, (int)$result['addressbookid']); $this->assertSame('uri0', $result['uri']); $this->assertSame(5489543, (int)$result['lastmodified']); -- cgit v1.2.3