2015-12-04 15:38:32 +03:00
|
|
|
<?php
|
2016-03-01 19:25:15 +03:00
|
|
|
/**
|
2016-07-21 17:49:16 +03:00
|
|
|
* @copyright Copyright (c) 2016, ownCloud, Inc.
|
|
|
|
*
|
2016-05-26 20:56:05 +03:00
|
|
|
* @author Björn Schießle <bjoern@schiessle.org>
|
|
|
|
* @author Lukas Reschke <lukas@statuscode.ch>
|
2016-03-01 19:25:15 +03:00
|
|
|
* @author Thomas Müller <thomas.mueller@tmit.eu>
|
|
|
|
*
|
|
|
|
* @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 15:38:32 +03:00
|
|
|
namespace OCA\Federation\Command;
|
|
|
|
|
|
|
|
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 16:58:49 +03:00
|
|
|
/** @var \OCA\Federation\SyncFederationAddressBooks */
|
2015-12-04 15:38:32 +03:00
|
|
|
private $syncService;
|
|
|
|
|
|
|
|
/**
|
2016-01-26 19:27:58 +03:00
|
|
|
* @param \OCA\Federation\SyncFederationAddressBooks $syncService
|
2015-12-04 15:38:32 +03:00
|
|
|
*/
|
2017-08-02 15:34:51 +03:00
|
|
|
public function __construct(\OCA\Federation\SyncFederationAddressBooks $syncService) {
|
2015-12-04 15:38:32 +03:00
|
|
|
parent::__construct();
|
|
|
|
|
2016-01-22 16:58:49 +03:00
|
|
|
$this->syncService = $syncService;
|
2015-12-04 15:38:32 +03: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 19:27:58 +03:00
|
|
|
* @return int
|
2015-12-04 15:38:32 +03:00
|
|
|
*/
|
|
|
|
protected function execute(InputInterface $input, OutputInterface $output) {
|
|
|
|
|
|
|
|
$progress = new ProgressBar($output);
|
|
|
|
$progress->start();
|
2016-01-22 16:58:49 +03:00
|
|
|
$this->syncService->syncThemAll(function($url, $ex) use ($progress, $output) {
|
|
|
|
if ($ex instanceof \Exception) {
|
2015-12-21 19:32:39 +03:00
|
|
|
$output->writeln("Error while syncing $url : " . $ex->getMessage());
|
2016-02-26 19:51:20 +03:00
|
|
|
|
2016-01-22 16:58:49 +03:00
|
|
|
} else {
|
|
|
|
$progress->advance();
|
2015-12-04 15:38:32 +03:00
|
|
|
}
|
2016-01-22 16:58:49 +03:00
|
|
|
});
|
|
|
|
|
2015-12-04 15:38:32 +03:00
|
|
|
$progress->finish();
|
|
|
|
$output->writeln('');
|
2016-01-26 19:27:58 +03:00
|
|
|
|
|
|
|
return 0;
|
2015-12-04 15:38:32 +03:00
|
|
|
}
|
|
|
|
}
|