server/apps/federation/lib/Command/SyncFederationAddressBooks.php

75 lines
2.1 KiB
PHP
Raw Normal View History

2015-12-04 12:38:32 +00:00
<?php
/**
2016-05-26 17:56:05 +00:00
* @author Björn Schießle <bjoern@schiessle.org>
* @author Lukas Reschke <lukas@statuscode.ch>
* @author Thomas Müller <thomas.mueller@tmit.eu>
*
* @copyright Copyright (c) 2016, ownCloud, Inc.
* @license AGPL-3.0
*
* This code is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License, version 3,
* as published by the Free Software Foundation.
*
* 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, version 3,
* along with this program. If not, see <http://www.gnu.org/licenses/>
*
*/
2015-12-04 12:38:32 +00:00
namespace OCA\Federation\Command;
use OCA\Federation\DbHandler;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
class SyncFederationAddressBooks extends Command {
2016-01-22 13:58:49 +00:00
/** @var \OCA\Federation\SyncFederationAddressBooks */
2015-12-04 12:38:32 +00:00
private $syncService;
/**
2016-01-26 16:27:58 +00:00
* @param \OCA\Federation\SyncFederationAddressBooks $syncService
2015-12-04 12:38:32 +00:00
*/
2016-01-22 13:58:49 +00:00
function __construct(\OCA\Federation\SyncFederationAddressBooks $syncService) {
2015-12-04 12:38:32 +00:00
parent::__construct();
2016-01-22 13:58:49 +00:00
$this->syncService = $syncService;
2015-12-04 12:38:32 +00:00
}
protected function configure() {
$this
->setName('federation:sync-addressbooks')
->setDescription('Synchronizes addressbooks of all federated clouds');
}
/**
* @param InputInterface $input
* @param OutputInterface $output
2016-01-26 16:27:58 +00:00
* @return int
2015-12-04 12:38:32 +00:00
*/
protected function execute(InputInterface $input, OutputInterface $output) {
$progress = new ProgressBar($output);
$progress->start();
2016-01-22 13:58:49 +00:00
$this->syncService->syncThemAll(function($url, $ex) use ($progress, $output) {
if ($ex instanceof \Exception) {
2015-12-21 16:32:39 +00:00
$output->writeln("Error while syncing $url : " . $ex->getMessage());
2016-01-22 13:58:49 +00:00
} else {
$progress->advance();
2015-12-04 12:38:32 +00:00
}
2016-01-22 13:58:49 +00:00
});
2015-12-04 12:38:32 +00:00
$progress->finish();
$output->writeln('');
2016-01-26 16:27:58 +00:00
return 0;
2015-12-04 12:38:32 +00:00
}
}