2015-12-04 15:38:32 +03:00
|
|
|
<?php
|
|
|
|
|
|
|
|
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 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
|
|
|
*/
|
2016-01-22 16:58:49 +03:00
|
|
|
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-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
|
|
|
}
|
|
|
|
}
|