summaryrefslogtreecommitdiffstats
path: root/apps/federation/command
diff options
context:
space:
mode:
authorThomas Müller <thomas.mueller@tmit.eu>2016-01-22 14:58:49 +0100
committerThomas Müller <thomas.mueller@tmit.eu>2016-01-22 14:58:49 +0100
commit7909c47b7c595acf2cd9e6ed2da4906339541311 (patch)
tree6d2a4a7ee46db6ebeb07a8b3095a5206edaf670c /apps/federation/command
parent9b4c9a0357ba9a10f4e0c7c1cafb3923ba5929db (diff)
downloadnextcloud-server-7909c47b7c595acf2cd9e6ed2da4906339541311.tar.gz
nextcloud-server-7909c47b7c595acf2cd9e6ed2da4906339541311.zip
Sync federated clouds using a cron job
Diffstat (limited to 'apps/federation/command')
-rw-r--r--apps/federation/command/syncfederationaddressbooks.php40
1 files changed, 9 insertions, 31 deletions
diff --git a/apps/federation/command/syncfederationaddressbooks.php b/apps/federation/command/syncfederationaddressbooks.php
index 516029d25ab..aff54fa0901 100644
--- a/apps/federation/command/syncfederationaddressbooks.php
+++ b/apps/federation/command/syncfederationaddressbooks.php
@@ -2,9 +2,7 @@
namespace OCA\Federation\Command;
-use OCA\DAV\CardDAV\SyncService;
use OCA\Federation\DbHandler;
-use OCA\Federation\TrustedServers;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputInterface;
@@ -12,20 +10,16 @@ use Symfony\Component\Console\Output\OutputInterface;
class SyncFederationAddressBooks extends Command {
- /** @var DbHandler */
- protected $dbHandler;
-
- /** @var SyncService */
+ /** @var \OCA\Federation\SyncFederationAddressBooks */
private $syncService;
/**
* @param DbHandler $dbHandler
*/
- function __construct(DbHandler $dbHandler) {
+ function __construct(\OCA\Federation\SyncFederationAddressBooks $syncService) {
parent::__construct();
- $this->syncService = \OC::$server->query('CardDAVSyncService');
- $this->dbHandler = $dbHandler;
+ $this->syncService = $syncService;
}
protected function configure() {
@@ -42,30 +36,14 @@ class SyncFederationAddressBooks extends Command {
$progress = new ProgressBar($output);
$progress->start();
- $trustedServers = $this->dbHandler->getAllServer();
- foreach ($trustedServers as $trustedServer) {
- $progress->advance();
- $url = $trustedServer['url'];
- $sharedSecret = $trustedServer['shared_secret'];
- $syncToken = $trustedServer['sync_token'];
-
- if (is_null($sharedSecret)) {
- continue;
- }
- $targetBookId = sha1($url);
- $targetPrincipal = "principals/system/system";
- $targetBookProperties = [
- '{DAV:}displayname' => $url
- ];
- try {
- $newToken = $this->syncService->syncRemoteAddressBook($url, 'system', $sharedSecret, $syncToken, $targetPrincipal, $targetBookId, $targetBookProperties);
- if ($newToken !== $syncToken) {
- $this->dbHandler->setServerStatus($url, TrustedServers::STATUS_OK, $newToken);
- }
- } catch (\Exception $ex) {
+ $this->syncService->syncThemAll(function($url, $ex) use ($progress, $output) {
+ if ($ex instanceof \Exception) {
$output->writeln("Error while syncing $url : " . $ex->getMessage());
+ } else {
+ $progress->advance();
}
- }
+ });
+
$progress->finish();
$output->writeln('');
}