diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2015-12-04 13:38:32 +0100 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2016-01-12 14:24:47 +0100 |
commit | 90d9834c8c0d3ae10cc754595d729821584e76a9 (patch) | |
tree | 7a50a81c630c835e131e9da3aaf2ac50aad2c88b /apps/federation | |
parent | dbddbb634bcb6df346988b85cb2847e76e22e632 (diff) | |
download | nextcloud-server-90d9834c8c0d3ae10cc754595d729821584e76a9.tar.gz nextcloud-server-90d9834c8c0d3ae10cc754595d729821584e76a9.zip |
Decouple federation and dav app
Diffstat (limited to 'apps/federation')
-rw-r--r-- | apps/federation/appinfo/database.xml | 5 | ||||
-rw-r--r-- | apps/federation/appinfo/info.xml | 2 | ||||
-rw-r--r-- | apps/federation/appinfo/register_command.php | 9 | ||||
-rw-r--r-- | apps/federation/command/syncfederationaddressbooks.php | 75 | ||||
-rw-r--r-- | apps/federation/lib/dbhandler.php | 11 |
5 files changed, 93 insertions, 9 deletions
diff --git a/apps/federation/appinfo/database.xml b/apps/federation/appinfo/database.xml index e6728df1408..05b7fb12b49 100644 --- a/apps/federation/appinfo/database.xml +++ b/apps/federation/appinfo/database.xml @@ -52,9 +52,8 @@ </field> <field> <name>sync_token</name> - <type>integer</type> - <notnull>true</notnull> - <default>0</default> + <type>text</type> + <length>512</length> <comments>cardDav sync token</comments> </field> <index> diff --git a/apps/federation/appinfo/info.xml b/apps/federation/appinfo/info.xml index 92afc995366..bfb4ca8f8c9 100644 --- a/apps/federation/appinfo/info.xml +++ b/apps/federation/appinfo/info.xml @@ -5,7 +5,7 @@ <description>ownCloud Federation allows you to connect with other trusted ownClouds to exchange the user directory. For example this will be used to auto-complete external users for federated sharing.</description> <licence>AGPL</licence> <author>Bjoern Schiessle</author> - <version>0.0.1</version> + <version>0.0.2</version> <namespace>Federation</namespace> <category>other</category> <dependencies> diff --git a/apps/federation/appinfo/register_command.php b/apps/federation/appinfo/register_command.php new file mode 100644 index 00000000000..8509a9721ad --- /dev/null +++ b/apps/federation/appinfo/register_command.php @@ -0,0 +1,9 @@ +<?php + +$config = \OC::$server->getConfig(); +$dbConnection = \OC::$server->getDatabaseConnection(); +$userManager = OC::$server->getUserManager(); +$config = \OC::$server->getConfig(); + +/** @var Symfony\Component\Console\Application $application */ +$application->add(new \OCA\Federation\Command\SyncFederationAddressBooks($userManager, $dbConnection, $config)); diff --git a/apps/federation/command/syncfederationaddressbooks.php b/apps/federation/command/syncfederationaddressbooks.php new file mode 100644 index 00000000000..497eba66bec --- /dev/null +++ b/apps/federation/command/syncfederationaddressbooks.php @@ -0,0 +1,75 @@ +<?php + +namespace OCA\Federation\Command; + +use OCA\DAV\CardDAV\SyncService; +use OCA\Federation\DbHandler; +use OCA\Federation\TrustedServers; +use OCP\IConfig; +use OCP\IDBConnection; +use OCP\IUserManager; +use Symfony\Component\Console\Command\Command; +use Symfony\Component\Console\Helper\ProgressBar; +use Symfony\Component\Console\Input\InputArgument; +use Symfony\Component\Console\Input\InputInterface; +use Symfony\Component\Console\Output\OutputInterface; + +class SyncFederationAddressBooks extends Command { + + /** @var \OCP\IDBConnection */ + protected $dbConnection; + + /** @var SyncService */ + private $syncService; + + /** + * @param IUserManager $userManager + * @param IDBConnection $dbConnection + * @param IConfig $config + */ + function __construct(IDBConnection $dbConnection) { + parent::__construct(); + + $this->syncService = \OC::$server->query('CardDAVSyncService'); + $this->dbConnection = $dbConnection; + } + + protected function configure() { + $this + ->setName('federation:sync-addressbooks') + ->setDescription('Synchronizes addressbooks of all federated clouds'); + } + + /** + * @param InputInterface $input + * @param OutputInterface $output + */ + protected function execute(InputInterface $input, OutputInterface $output) { + + $progress = new ProgressBar($output); + $progress->start(); + $db = new DbHandler($this->dbConnection, null); + $trustedServers = $db->getAllServer(); + foreach ($trustedServers as $trustedServer) { + $progress->advance(); + $url = $trustedServer['url']; + $sharedSecret = $trustedServer['shared_secret']; + $syncToken = $trustedServer['sync_token']; + + if (is_null($sharedSecret)) { + continue; + } + $targetBookId = md5($url); + $targetPrincipal = "principals/system/system"; + $targetBookProperties = [ + '{DAV:}displayname' => $url + ]; + $newToken = $this->syncService->syncRemoteAddressBook($url, 'system', $sharedSecret, $syncToken, $targetPrincipal, $targetBookId, $targetBookProperties); + if ($newToken !== $syncToken) { + $db->setServerStatus($url, TrustedServers::STATUS_OK, $newToken); + } + } + $progress->finish(); + $output->writeln(''); + } +} diff --git a/apps/federation/lib/dbhandler.php b/apps/federation/lib/dbhandler.php index f86a8e15d80..0677430f799 100644 --- a/apps/federation/lib/dbhandler.php +++ b/apps/federation/lib/dbhandler.php @@ -207,14 +207,15 @@ class DbHandler { * @param string $url * @param int $status */ - public function setServerStatus($url, $status) { + public function setServerStatus($url, $status, $token = null) { $hash = $this->hash($url); $query = $this->connection->getQueryBuilder(); $query->update($this->dbTable) - ->set('status', $query->createParameter('status')) - ->where($query->expr()->eq('url_hash', $query->createParameter('url_hash'))) - ->setParameter('url_hash', $hash) - ->setParameter('status', $status); + ->set('status', $query->createNamedParameter($status)) + ->where($query->expr()->eq('url_hash', $query->createNamedParameter($hash))); + if (!is_null($token)) { + $query->set('sync_token', $query->createNamedParameter($token)); + } $query->execute(); } |